diff --git a/website/pages/en/querying/querying-best-practices.mdx b/website/pages/en/querying/querying-best-practices.mdx index 18a51701045d..32d1415b20fa 100644 --- a/website/pages/en/querying/querying-best-practices.mdx +++ b/website/pages/en/querying/querying-best-practices.mdx @@ -108,7 +108,7 @@ Now that we covered the basic rules of GraphQL queries syntax, let's now look at --- -## Writing GraphQL queries +## Best Practices ### Always write static queries @@ -193,9 +193,7 @@ const result = await execute(query, { Note: The opposite directive is `@skip(if: ...)`. -### Performance tips - -**"Ask for what you want"** +### Ask for what you want GraphQL became famous for its "Ask for what you want" tagline. @@ -224,7 +222,39 @@ The response could contain 100 transactions for each of the 100 tokens. If the application only needs 10 transactions, the query should explicitly set `first: 10` on the transactions field. -**Combining multiple queries** +### Use a single query to request multiple records + +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}` + +Example of inefficient querying: + +```graphql +query SingleRecord { + entity(id: X) { + id + name + } +} +query SingleRecord { + entity(id: Y) { + id + name + } +} +``` + +Example of optimized querying: + +```graphql +query ManyRecords { + entities(where: { id_in: [X, Y] }) { + id + name + } +} +``` + +### Combine multiple queries in a single request Your application might require querying multiple types of data as follows: