How to deploy custom Subgraph with The Graph Protocol?
Tags: subgraph
Published: 2023-11-22 09:27:33

<p>Whether you are building a dApp or you want to enhance the functionality of your existing web3 applications– you must need indexed on-chain data from a range of blockchains and <a href="https://www.zeeve.io/blockchain-protocols/">decentralized networks</a>. However, querying data out of the blockchain’s distributed ledger is a complex task. To provide a solution, The Graph protocol simplifies data querying and indexing with its powerful <a href="https://www.zeeve.io/subgraphs/">data indexing infrastructure</a> and Subgraph.&nbsp;</p>
<p>Want to know more about how data indexing and querying work on the Graph network and <a href="https://www.zeeve.io/subgraphs/">Subgraph</a>? Read our comprehensive guide on this below:</p>
<p><a href="https://www.zeeve.io/blog/how-to-query-web3-data-using-the-graph-protocol-and-subgraphs/"><strong>How to query Web3 data using The Graph Protocol and Subgraphs</strong></a></p>
<p>This guide provides you step-by-step process of how to <a href="https://www.zeeve.io/subgraphs/">deploy custom Subgraph</a> with the Graph protocol’s hosted service.&nbsp;</p>
<figure class="wp-block-image size-large"><a href="https://www.zeeve.io/talk-to-an-expert/"><img src="https://www.zeeve.io/wp-content/uploads/2023/10/LAYNCHsUBGRAPH_BANNER-1024x131.png" alt="deploy custom Subgraph" class="wp-image-47878"/></a></figure>
<h2 id="h-why-do-businesses-need-custom-subgraph">Why do businesses need custom Subgraph?</h2>
<p>A lot of web3 projects want to perform customized data queries because general-purpose queries do not cater to their specific data needs. For example, some dApps many not just want to leverage <a href="https://www.zeeve.io/blockchain-protocols/deploy-ethereum-blockchain/">Ethereum</a> standards like <a href="https://www.zeeve.io/blog/introduction-to-token-standards-erc-20-erc-721-erc-777-and-erc-1155/">ERC-721</a> or ERC. Instead, they want to pull only the data which is highly relevant. These specific types of data requirements can be fulfilled by deploying custom Subgraphs that are designed to run customized GraphQL queries. <a href="https://www.zeeve.io/subgraphs/">Custom Subgraphs</a> are frequently used across <a href="https://www.zeeve.io/blog/blockchain-bridges-helping-the-growth-of-defi">DeFi</a>, <a href="https://www.zeeve.io/blog/a-simple-and-comprehensive-guide-on-non-fungible-tokens/">NFTs</a>, gaming, <a href="https://www.zeeve.io/blog/a-complete-guide-to-different-kinds-of-daos/">DAOs</a>, and other web3 projects that need&nbsp; very specific blockchain data to streamline their operations.</p>
<h2 id="h-how-can-you-deploy-your-own-custom-subgraphs">How can you deploy your own custom Subgraphs?</h2>
<p>This guide explains how you can <a href="https://www.zeeve.io/subgraphs/">deploy custom Subgraphs</a> on the hosted service. Leveraging this service, you don't need Graph node, GRT tokens for staking, or infrastructure to maintain your Subgraph. Also, The Graph <a href="https://www.zeeve.io/blockchain-protocols/">decentralized network</a> currently supports <a href="https://thegraph.com/docs/en/developing/supported-networks/" rel="nofollow">limited networks</a>, while the hosted service is supported for a range of networks. Let’s see the entire process.&nbsp;</p>
<p>Your Subgraph will contain three main files–&nbsp;</p>
<p><strong>subgraph.yaml</strong>: A file defining Subgraph manifest,&nbsp;</p>
<p><strong>schema.graphql</strong>: GraphQL schema for defining what type of data needs to be stored in your Subgraph, and how it can be queries via GraphQL, and finally the&nbsp;</p>
<p><strong>AssemblyScript Mappings</strong>: code for translating event data to all the entities you define in the schema.&nbsp;</p>
<p><br>Assuming that you have completed the above process, let’s start deploying your custom Subgraph.</p>
<h3>Step-1: Creating your custom Subgraph on the Graph Hosted service&nbsp;</h3>
<p>Create your <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> first. Visit the <a href="https://thegraph.com/docs/en/developing/supported-networks/" rel="nofollow">dashboard </a>and proceed to ‘Add Subgraph’ option. Further, you need to provide some information for initialization such as image, Subgraph name, account, subtitle, description, Github url, and hide. Once you provide all the details, save your Subgraph.&nbsp; Upon this, a screen will appear that will explains you the process of installing the Graph CLI and generating scaffolding of your new Subgraph. You can learn about both these processes <a href="https://thegraph.com/docs/en/developing/defining-a-subgraph/" rel="nofollow">here</a>.</p>
<h3>Step:2&nbsp; Deploying the Subgraph to the Hosted Service</h3>
<p>To initiate the <a href="https://www.zeeve.io/subgraphs/">deployment of your subgraph</a>, you'll be using the 'yarn deploy' command. This action involves the uploading of the subgraph files created through 'yarn build' to IPFS. Simultaneously, it notifies the Graph Explorer to commence the indexing process on your subgraph using these uploaded files.</p>
<p>Once the subgraph deployment is complete, the Graph Explorer will transition to displaying the synchronization status of your subgraph. The time taken for synchronization varies based on factors like the volume of data and the quantity of events to be extracted from historical blocks, commencing with the genesis block. This synchronization process can range from a few minutes to several hours.The subgraph status will switch to 'Synced' once the Graph Node has successfully extracted all data from historical blocks.&nbsp;</p>
<h3>Step:3 Redeploy your Subgraph</h3>
<p>If you make modifications to your subgraph definition, such as correcting the entity mapping issues, you should re-run the 'yarn deploy' command to deploy the updated version of your subgraph. Any update to a <a href="https://www.zeeve.io/subgraphs/">subgraph</a> necessitates the Graph Node to reindex the entire subgraph once more, starting from the genesis block.</p>
<p>Incase you have previously deployed a subgraph that is still in the 'Syncing' status, it will be promptly replaced by the newly deployed version. However, if the prior version has already achieved full synchronization, the Graph Node will designate the newly deployed version as the 'Pending Version.' It will initiate background syncing and will only replace the presently deployed version with the new one once the synchronization of the new version has been completed. This approach ensures that you have a functional subgraph to work&nbsp; and in the meantime a new version is syncing.&nbsp;</p>
<h3>Step:4&nbsp; Querying data from your Subgraph&nbsp;</h3>
<p>With you deployed Subgraph, visit the <a href="https://thegraph.com/hosted-service/" rel="nofollow">Hosted Service</a>, that will&nbsp; open a GraphQL interface. From here, you can explore&nbsp; the deployed GraphQL API of your Subgraph through issuing the queries and viewing its schema.&nbsp;&nbsp;</p>
<p>Note that the Graph hosted service has begun sunsetting, and it will become unavailable to users soon. However, as we know, there are a lot of benefits to using a hosted service. For example, you don’t need to manage nodes, stake GRT tokens, manage infrastructure, and so on. That’s where the <a href="https://www.zeeve.io/subgraphs/">Zeeve-managed Subgraph</a> hosted service comes in. Let’s learn more about it.&nbsp;</p>
<h3>Zeeve-hosted Subgraph service— the hassle-free way to deploy and manage your custom Subgraphs&nbsp;</h3>
<p>The Subgraph hosted service at <a href="https://www.zeeve.io/">Zeeve</a> allows you to <a href="https://www.zeeve.io/subgraphs/">deploy your custom Subgraph</a> on all the leading <a href="https://www.zeeve.io/platform/">blockchain networks</a>, including ones that are not yet supported on the Graph hosted service. For that, again you do not need to run nodes or stake tokens which you are suppped to do while deploying on The Graph. With this approach, Zeeve-managed services will cut down your Subgraph and deployment and maintenance cost significantly.&nbsp;</p>
<p>&nbsp;Now, let’s learn about the Subgraph deployment process on <a href="https://www.zeeve.io/">Zeeve</a>. To build your <a href="https://www.zeeve.io/subgraphs/">custom Subgraph</a> with <a href="https://www.zeeve.io/platform/">Zeeve platform</a>, you first need to login or sign up on the Zeeve dashboard.&nbsp;</p>
<li>Go to ‘Hosted Subgraphs’ under ‘Buy Services’ and select the quantity of Subgraph units you need. If you want, you can add-on API units and queries as required. Click on Buy Now and complete payment to get subscription for your Subgraph/Subgraphs.</li>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dc5disdchbbxlu1x6drg.png)
<p>You can either ‘go to dashboard’ or directly ‘setup subgraph’. Alternatively, go to the ‘Manage Services’ and click on ‘Hosted Subgraph’. Create new subgraph from here.</p>
<li>Provide all the necessary information about the Subgraph such as Subgraph name, workspace, <a href="https://www.zeeve.io/blockchain-protocols/">blockchain network</a>, and plan type. Zeeve supports different networks such as <a href="https://www.zeeve.io/blockchain-protocols/deploy-avalanche-node/">Avalanche</a> and <a href="https://www.zeeve.io/blockchain-protocols/deploy-ethereum-blockchain/">Ethereum</a>. Also, there’s a option of custom netwo</li>
<li>Provide all the necessary information about the Subgraph such as Subgraph name, workspace, <a href="https://www.zeeve.io/blockchain-protocols/">blockchain network</a>, and plan type. Zeeve supports different networks such as <a href="https://www.zeeve.io/blockchain-protocols/deploy-avalanche-node/">Avalanche</a> and <a href="https://www.zeeve.io/blockchain-protocols/deploy-ethereum-blockchain/">Ethereum</a>. Also, there’s a option of custom network where you can add the RPC endpoint of your desired blockchain network and add it to the platform.&nbsp;</li>
<li>rk where you can add the RPC endpoint of your desired blockchain network and add it to the platform.&nbsp;</li>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2521vxvxi9zd1j83sq80.png)
<li>Now, click on ‘Add Subgraph’ to complete the deployment. It will open a details page where the status of your <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> will by default visible as ‘Not Deployed’. On this same page, you will get Deployment command URL and Query URL. With this, again go to the Graph CLI and deploy your Subgraph. Once deployed, the status will change to ‘Deployed’ and your Subgraph will be ready to query the web3 data.&nbsp;</li>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5nzf3t0w0ottf9a0ocm.png)
<p>Regarding the Query URL, you can use it on PostSQL to check the entire query requests made in the past 24 hours and the total API consumption units.&nbsp;</p>
<h3>Monitoring and maintenance of Subgraph&nbsp;</h3>
<p><a href="https://www.zeeve.io/">Zeeve</a> provides completely monitored and managed nodes. Zeeve proactively monitor your deployed Subgraph, check the logs, and check errors if any.&nbsp; The monitoring is done on critical parameters such as Info, Debug, Warning, and Error. Plus, the upgrades are released automatically.&nbsp;</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ku9pmgokm4ou02zgj66h.png)
<h2 id="h-conclusion">Conclusion</h2>
<p>As discussed, the Graph protocol offers a fully a powerful, and highly efficient infrastructure to <a href="https://www.zeeve.io/subgraphs/">deploy custom Subgraphs</a> for retrieving data from a range of blockchains. However, you can discuss all your concerns with Subgraph development and the Graph network with the blockchain experts at Zeeve. We are happy to assist you. Drop your queries via email on this page or you can also <a href="https://www.zeeve.io/talk-to-an-expert/">schedule one-to-one call with our consultants</a>.&nbsp;</p>