Skip to content

Commit 91d960f

Browse files
idalithbbenface
andauthored
Optimizing queries (#720)
* Adding documentation to reflect @Data-Nexus educational updates * updated section * heading edit * Update website/pages/en/querying/querying-best-practices.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/querying/querying-best-practices.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/querying/querying-best-practices.mdx Co-authored-by: Benoît Rouleau <[email protected]> * Update website/pages/en/querying/querying-best-practices.mdx Co-authored-by: Benoît Rouleau <[email protected]> --------- Co-authored-by: Benoît Rouleau <[email protected]>
1 parent ea02af2 commit 91d960f

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

website/pages/en/querying/querying-best-practices.mdx

+35-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Now that we covered the basic rules of GraphQL queries syntax, let's now look at
108108

109109
---
110110

111-
## Writing GraphQL queries
111+
## Best Practices
112112

113113
### Always write static queries
114114

@@ -193,9 +193,7 @@ const result = await execute(query, {
193193

194194
Note: The opposite directive is `@skip(if: ...)`.
195195

196-
### Performance tips
197-
198-
**"Ask for what you want"**
196+
### Ask for what you want
199197

200198
GraphQL became famous for its "Ask for what you want" tagline.
201199

@@ -224,7 +222,39 @@ The response could contain 100 transactions for each of the 100 tokens.
224222

225223
If the application only needs 10 transactions, the query should explicitly set `first: 10` on the transactions field.
226224

227-
**Combining multiple queries**
225+
### Use a single query to request multiple records
226+
227+
By default, subgraphs have a singular entity for one record. For multiple records, use the plural entities and filter: `where: {id_in:[X,Y,Z]}` or `where: {volume_gt:100000}`
228+
229+
Example of inefficient querying:
230+
231+
```graphql
232+
query SingleRecord {
233+
entity(id: X) {
234+
id
235+
name
236+
}
237+
}
238+
query SingleRecord {
239+
entity(id: Y) {
240+
id
241+
name
242+
}
243+
}
244+
```
245+
246+
Example of optimized querying:
247+
248+
```graphql
249+
query ManyRecords {
250+
entities(where: { id_in: [X, Y] }) {
251+
id
252+
name
253+
}
254+
}
255+
```
256+
257+
### Combine multiple queries in a single request
228258

229259
Your application might require querying multiple types of data as follows:
230260

0 commit comments

Comments
 (0)