Somebody else has published the subgraph. You want to read it from your application and not think about the protocol again.
That is a reasonable goal and mostly achievable. This lesson is about the parts that are not automatic.
The shape of it.
Get an API key from Subgraph Studio, find the subgraph you need in Graph Explorer, and query its gateway endpoint over GraphQL with your key attached.
That is genuinely the whole integration. The rest of this path is about the assumptions that integration quietly makes.
Choosing a subgraph you can depend on.
Anyone can publish a subgraph. Some are maintained, some were a weekend project in 2023 that still indexes. Before building on one:
- Is it the one the protocol team actually uses? Many protocols publish an official subgraph and it is usually the right choice.
- Is it being served? Check that indexers are allocated to it. A published subgraph with no allocation returns nothing useful.
- Is it healthy? Check indexing status. A subgraph that failed at some block has stopped, and it will keep answering with data up to that block.
- Is it maintained? Contract upgrades break subgraphs. An unmaintained one breaks eventually and stays broken.
- Does it carry signal? Signal is other people’s money betting it will keep being queried, which is a reasonable second opinion.
The three failure modes.
Stale. The subgraph is behind the chain head, or stopped entirely. Data is correct and old.
Empty. No matching entities. Indistinguishable in the response from stale or broken, which is what makes it dangerous.
Slow. Your query went to an indexer having a difficult afternoon, or your query is expensive. Set timeouts.
None of these throws an error. All of them are handled by checking indexing status alongside the data, which is the single highest-value thing you can add to the integration.
The key.
Never in a client. An API key in a web or mobile bundle is extractable and spendable by anyone who looks.
Query through your own backend, keep the key in server configuration, and rate limit per user there. This is ordinary practice for a paid API and it gets skipped here because the per-query amounts feel small.
A subgraph stopped indexing three months ago. What happens to your queries?
It answers perfectly with stale data and raises nothing. Checking indexing progress against chain head is the highest-value addition to any integration for exactly this reason.
Where should your API key live?
Anything in a bundle is readable and spendable. Proxying through your own backend also lets you rate limit per user, which a client-side key cannot.
0 of 2 answered