Skip to content

Commit

Permalink
Optimizing queries (graphprotocol#720)
Browse files Browse the repository at this point in the history
* 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 <benoit.rouleau@icloud.com>

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

Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>

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

Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>

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

Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>

---------

Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>
  • Loading branch information
idalithb and benface authored Jul 17, 2024
1 parent ea02af2 commit 91d960f
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions website/pages/en/querying/querying-best-practices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit 91d960f

Please sign in to comment.