From 996ae9869dcce101c6278f52db7216140ca813c2 Mon Sep 17 00:00:00 2001 From: Idalith <126833353+idalithb@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:20:12 -0700 Subject: [PATCH] Querying Best Practices (#796) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update website/pages/en/querying/querying-best-practices.mdx --------- Co-authored-by: BenoƮt Rouleau --- .../pages/en/querying/querying-best-practices.mdx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/website/pages/en/querying/querying-best-practices.mdx b/website/pages/en/querying/querying-best-practices.mdx index 5654cf9e23a5..6e085cfe7bf1 100644 --- a/website/pages/en/querying/querying-best-practices.mdx +++ b/website/pages/en/querying/querying-best-practices.mdx @@ -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. @@ -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`) @@ -59,9 +59,9 @@ 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 @@ -69,7 +69,7 @@ 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)