Topics In Demand
Notification
New

No notification found.

How to deploy custom Subgraph with The Graph Protocol?
How to deploy custom Subgraph with The Graph Protocol?

October 27, 2023

22

0

 

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 decentralized networks. 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 data indexing infrastructure and Subgraph. 

This guide provides you step-by-step process of how to deploy custom Subgraph with the Graph protocol’s hosted service. 

deploy custom Subgraph

Why do businesses need custom Subgraph?

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 Ethereum standards like ERC-721 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. Custom Subgraphs are frequently used across DeFi, NFTs, gaming, DAOs, and other web3 projects that need  very specific blockchain data to streamline their operations.

How can you deploy your own custom Subgraphs?

This guide explains how you can deploy custom Subgraphs 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 decentralized network currently supports limited networks, while the hosted service is supported for a range of networks. Let’s see the entire process. 

Your Subgraph will contain three main files– 

subgraph.yaml: A file defining Subgraph manifest, 

schema.graphql: 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 

AssemblyScript Mappings: code for translating event data to all the entities you define in the schema. 


Assuming that you have completed the above process, let’s start deploying your custom Subgraph.

Step-1: Creating your custom Subgraph on the Graph Hosted service 

Create your Subgraph first. Visit the dashboard 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.  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 here.

Step:2  Deploying the Subgraph to the Hosted Service

To initiate the deployment of your subgraph, 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.

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. 

Step:3 Redeploy your Subgraph

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 subgraph necessitates the Graph Node to reindex the entire subgraph once more, starting from the genesis block.

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  and in the meantime a new version is syncing. 

Step:4  Querying data from your Subgraph 

With you deployed Subgraph, visit the Hosted Service, that will  open a GraphQL interface. From here, you can explore  the deployed GraphQL API of your Subgraph through issuing the queries and viewing its schema.  

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 Zeeve-managed Subgraph hosted service comes in. Let’s learn more about it. 

Zeeve-hosted Subgraph service— the hassle-free way to deploy and manage your custom Subgraphs 

The Subgraph hosted service at Zeeve allows you to deploy your custom Subgraph on all the leading blockchain networks, 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. 

 Now, let’s learn about the Subgraph deployment process on Zeeve. To build your custom Subgraph with Zeeve platform, you first need to login or sign up on the Zeeve dashboard. 

  1. 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.
deploy custom Subgraph

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.

  1. Provide all the necessary information about the Subgraph such as Subgraph name, workspace, blockchain network, and plan type. Zeeve supports different networks such as Avalanche and Ethereum. 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. 
deploy custom Subgraph
  1. Now, click on ‘Add Subgraph’ to complete the deployment. It will open a details page where the status of your Subgraph 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. 
deploy custom Subgraph

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. 

Monitoring and maintenance of Subgraph 

Zeeve provides completely monitored and managed nodes. Zeeve proactively monitor your deployed Subgraph, check the logs, and check errors if any.  The monitoring is done on critical parameters such as Info, Debug, Warning, and Error. Plus, the upgrades are released automatically. 

deploy custom subgraph

 

About The Author 

Author

Dr. Ravi Chamria is co-founder CEO of Zeeve Inc, an Enterprise Blockchain company. He has an experience of 18+ years in IT consulting spanning across Fintech, InsureTech, Supply Chain and eCommerce. He is an executive MBA from IIM, Lucknow and a prolific speaker on emerging technologies like Blockchain, IoT and AI/ML.

Passionate About: Blockchain, Supply Chain Management, Digital Lending, Digital Payments, AI/ML, IoT

Specialities: Strategic Management, Technology Innovation, Product Management


That the contents of third-party articles/blogs published here on the website, and the interpretation of all information in the article/blogs such as data, maps, numbers, opinions etc. displayed in the article/blogs and views or the opinions expressed within the content are solely of the author's; and do not reflect the opinions and beliefs of NASSCOM or its affiliates in any manner. NASSCOM does not take any liability w.r.t. content in any manner and will not be liable in any manner whatsoever for any kind of liability arising out of any act, error or omission. The contents of third-party article/blogs published, are provided solely as convenience; and the presence of these articles/blogs should not, under any circumstances, be considered as an endorsement of the contents by NASSCOM in any manner; and if you chose to access these articles/blogs , you do so at your own risk.


Zeeve is an enterprise-grade Blockchain Infrastructure Automation Platform. Join the growing list of clients that trust us with their Blockchain initiatives

© Copyright nasscom. All Rights Reserved.