Skip to content

Commit

Permalink
Querying Best Practices (#796)
Browse files Browse the repository at this point in the history
* Update website/pages/en/querying/querying-best-practices.mdx

---------

Co-authored-by: Benoît Rouleau <benoit.rouleau@icloud.com>
  • Loading branch information
idalithb and benface authored Oct 17, 2024
1 parent b22ab57 commit 996ae98
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions website/pages/en/querying/querying-best-practices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
title: Querying Best Practices
---

The Graph provides a decentralized way to query data from blockchains via GraphQL APIs, making it easier to query data with the GraphQL language.
The Graph provides a decentralized way to query data from blockchains. Its data is exposed through a GraphQL API, making it easier to query with the GraphQL language.

Learn the essential GraphQL language rules and GraphQL querying best practices.
Learn the essential GraphQL language rules and best practices to optimize your subgraph.

---

## Querying a GraphQL API

### The anatomy of a GraphQL query
### The Anatomy of a GraphQL Query

Unlike REST API, a GraphQL API is built upon a Schema that defines which queries can be performed.

Expand Down Expand Up @@ -50,7 +50,7 @@ query [operationName]([variableName]: [variableType]) {
}
```

While the list of syntactic do's and don'ts is long, here are the essential rules to keep in mind when it comes to writing GraphQL queries:
## Rules for Writing GraphQL Queries

- Each `queryName` must only be used once per operation.
- Each `field` must be used only once in a selection (we cannot query `id` twice under `token`)
Expand All @@ -59,17 +59,17 @@ While the list of syntactic do's and don'ts is long, here are the essential rule
- In a given list of variables, each of them must be unique.
- All defined variables must be used.

Failing to follow the above rules will end with an error from the Graph API.
> Note: Failing to follow these rules will result in an error from The Graph API.
For a complete list of rules with code examples, please look at our [GraphQL Validations guide](/release-notes/graphql-validations-migration-guide/).
For a complete list of rules with code examples, check out [GraphQL Validations guide](/release-notes/graphql-validations-migration-guide/).

### Sending a query to a GraphQL API

GraphQL is a language and set of conventions that transport over HTTP.

It means that you can query a GraphQL API using standard `fetch` (natively or via `@whatwg-node/fetch` or `isomorphic-fetch`).

However, as stated in ["Querying from an Application"](/querying/querying-from-an-application), it's recommend to use `graph-client` which supports unique features such as:
However, as mentioned in ["Querying from an Application"](/querying/querying-from-an-application), it's recommended to use `graph-client`, which supports the following unique features:

- Cross-chain Subgraph Handling: Querying from multiple subgraphs in a single query
- [Automatic Block Tracking](https://github.com/graphprotocol/graph-client/blob/main/packages/block-tracking/README.md)
Expand Down

0 comments on commit 996ae98

Please sign in to comment.