2 minutes
How to Query a Subgraph Using The Graph
Querying a Subgraph with The Graph lets you access onchain data in a fast, reliable, and structured way, without running your own indexing infrastructure. You send GraphQL queries to a gateway, which routes them to Indexers on The Graph Network and bills you for them. This guide shows you how to find a published Subgraph, choose a gateway, get credentials, and send your first query.
Step 1: Find a Subgraph
Every Subgraph published to The Graph Network has a details page in Graph Explorer, operated by The Graph Foundation. Search by name, protocol, network, or contract address. The details page shows the Subgraph’s ID, its schema, and a playground where you can try queries. See Using Graph Explorer.
Note that you can choose a Subgraph ID or the Deployment ID if you want to stay on one exact version. See Subgraph ID vs Deployment ID for an overview of the differences between them.
Step 2: Choose a Gateway
Multiple Gateway Operators serve every published Subgraph. They differ in API keys, pricing, payment methods, and support, but they all serve the same Subgraphs with the same GraphQL API. This guide uses The Graph Foundation’s Gateway (gateway.thegraph.com) as the default throughout these docs, but you can choose another Gateway Provider if you’d like.
Step 3: Get API Key Credentials
For The Graph Foundation’s Gateway, create an API key on the API Keys page in Subgraph Studio. See Managing API Keys. Studio includes a free monthly query allowance, and you can pay for more with GRT or credit card. See Pricing.
If you use another Gateway Operator, get your API key and billing from that operator.
Step 4: Send a Query
On the Subgraph’s details page in Graph Explorer, click Query to copy its query URL for The Graph Foundation’s Gateway:


The URL has this format:
1https://gateway.thegraph.com/api/<API_KEY>/subgraphs/id/<SUBGRAPH_ID>Send a GraphQL query to it with a POST request:
1curl -X POST "https://gateway.thegraph.com/api/<API_KEY>/subgraphs/id/<SUBGRAPH_ID>" \2 -H "Content-Type: application/json" \3 --data '{"query": "{ _meta { block { number } } }"}'See the Query API for a complete reference on how to query the Subgraph’s entities.
Handling Errors
- If you get 405 errors with a GET request to the query URL, switch to a POST request.
- GraphQL reports query problems in an
errorsarray, often with HTTP status200, so check forerrorsas well as the status code.
Additional Resources
- Use GraphQL querying best practices.
- To query from an application, see Querying from an Application.
- View querying examples.