You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/pages/en/querying/graphql-api.mdx
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,13 @@ Learn about the GraphQL Query API used in The Graph.
6
6
7
7
## What is GraphQL?
8
8
9
-
[GraphQL](https://graphql.org/learn/) is the query language for APIs and a runtime for executing those queries with your existing data. The Graph uses GraphQL to query subgraphs.
9
+
[GraphQL](https://graphql.org/learn/) is a query language for APIs and a runtime for executing those queries with your existing data. The Graph uses GraphQL to query subgraphs.
10
10
11
-
-To understand the larger role that GraphQL plays, review [developing](/network/developing/) and [creating a subgraph](/developing/creating-a-subgraph/).
11
+
To understand the larger role that GraphQL plays, review [developing](/network/developing/) and [creating a subgraph](/developing/creating-a-subgraph/).
12
12
13
13
## Queries with GraphQL
14
14
15
-
In your subgraph schema you define types called `Entities`. For each `Entity` type, an `entity` and `entities`field will be generated on the top-level `Query` type.
15
+
In your subgraph schema you define types called `Entities`. For each `Entity` type, an `entity` and `entities`fields will be generated on the top-level `Query` type.
16
16
17
17
> Note: `query` does not need to be included at the top of the `graphql` query when using The Graph.
18
18
@@ -85,7 +85,7 @@ When querying a collection, it's best to:
85
85
86
86
- Use the `first` parameter to paginate from the beginning of the collection.
87
87
- The default sort order is by `ID` in ascending alphanumeric order, **not** by creation time.
88
-
- Use The`skip` parameter to skip entities and paginate. e.g.`first:100` shows the first 100 entities and `first:100, skip:100` shows the next 100 entities.
88
+
- Use the`skip` parameter to skip entities and paginate. For instance,`first:100` shows the first 100 entities and `first:100, skip:100` shows the next 100 entities.
89
89
- Avoid using `skip` values in queries because they generally perform poorly. To retrieve a large number of items, it's best to page through entities based on an attribute as shown in the previous example above.
90
90
91
91
#### Example using `first`
@@ -118,7 +118,7 @@ Query 10 `Token` entities, offset by 10 places from the beginning of the collect
118
118
119
119
#### Example using `first` and `id_ge`
120
120
121
-
If a client needs to retrieve a large number of entities, it's best to base queries on an attribute and filter by that attribute. For example, a client could retrieve a large number of tokens using this query:
121
+
If a client needs to retrieve a large number of entities, it's more performant to base queries on an attribute and filter by that attribute. For example, a client could retrieve a large number of tokens using this query:
122
122
123
123
```graphql
124
124
querymanyTokens($lastID: String) {
@@ -168,7 +168,7 @@ You can use suffixes like `_gt`, `_lte` for value comparison:
168
168
169
169
#### Example for block filtering
170
170
171
-
You can also filter entities by the `_change_block(number_gte: Int)`, which filters entities that were updated in or after the specified block.
171
+
You can also filter entities that were updated in or after a specified block with `_change_block(number_gte: Int)`.
172
172
173
173
This can be useful if you are looking to fetch only entities which have changed, for example since the last time you polled. Or alternatively it can be useful to investigate or debug how entities are changing in your subgraph (if combined with a block filter, you can isolate only entities that changed in a specific block).
You can query the state of your entities not just for the latest block, which is the default, but also for an arbitrary block in the past. The block at which a query should happen can be specified either by its block number or its block hash by including a `block` argument in the toplevel fields of queries.
293
293
294
-
-The result of such a query will not change over time, i.e., querying at a certain past block will return the same result no matter when it is executed, with the exception that if you query at a block very close to the head of the chain, the result might change if that block turns out to **not** be on the main chain and the chain gets reorganized. Once a block can be considered final, the result of the query will not change.
294
+
The result of such a query will not change over time, i.e., querying at a certain past block will return the same result no matter when it is executed, with the exception that if you query at a block very close to the head of the chain, the result might change if that block turns out to **not** be on the main chain and the chain gets reorganized. Once a block can be considered final, the result of the query will not change.
295
295
296
296
> Note: The current implementation is still subject to certain limitations that might violate these guarantees. The implementation can not always tell that a given block hash is not on the main chain at all, or if a query result by a block hash for a block that is not yet considered final could be influenced by a block reorganization running concurrently with the query. They do not affect the results of queries by block hash when the block is final and known to be on the main chain. [This issue](https://github.com/graphprotocol/graph-node/issues/1405) explains what these limitations are in detail.
The schema of your `data source`, which is the entity types, values, and relationships that are available to query, are defined through the [GraphQL Interface Definition Langauge (IDL)](https://facebook.github.io/graphql/draft/#sec-Type-System).
392
+
The schema of your `data source`, i.e. the entity types, values, and relationships that are available to query, are defined through the [GraphQL Interface Definition Langauge (IDL)](https://facebook.github.io/graphql/draft/#sec-Type-System).
393
393
394
394
GraphQL schemas generally define root types for `queries`, `subscriptions` and `mutations`. The Graph only supports `queries`. The root `Query` type for your subgraph is automatically generated from the GraphQL schema that's included in your [subgraph manifest](/developing/creating-a-subgraph/#components-of-a-subgraph).
395
395
396
-
> **Note:** Our API does not expose mutations because developers are expected to issue transactions directly against the underlying blockchain from their applications.
396
+
> Note: Our API does not expose mutations because developers are expected to issue transactions directly against the underlying blockchain from their applications.
0 commit comments