### Install Dependencies and Run Example Source: https://github.com/graphprotocol/graph-client/blob/main/examples/urql/README.md Steps to install dependencies, build the client, and start the Urql example project. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/urql/ $ yarn build-client $ yarn start ``` -------------------------------- ### Install Dependencies and Run Example Source: https://github.com/graphprotocol/graph-client/blob/main/examples/composition/README.md Installs dependencies, builds the client, and starts the composition example. Ensure you are in the root directory first. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/composition $ yarn build-client $ yarn start ``` -------------------------------- ### Install Dependencies and Build Source: https://github.com/graphprotocol/graph-client/blob/main/examples/execute/README.md Commands to install dependencies, build the client, and start the example in the root and example directories. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/execute $ yarn build-client $ yarn start ``` -------------------------------- ### Install and Run Example Source: https://github.com/graphprotocol/graph-client/blob/main/examples/node/README.md Steps to install dependencies, build the client, and run the NodeJS example. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/node $ yarn build-client $ yarn start ``` -------------------------------- ### Install Dependencies and Build Source: https://github.com/graphprotocol/graph-client/blob/main/examples/apollo/README.md Commands to install dependencies, build the client locally, and start the Apollo example. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/apollo/ $ yarn build-client $ yarn start ``` -------------------------------- ### Install Dependencies and Run Next.js Example Source: https://github.com/graphprotocol/graph-client/blob/main/examples/nextjs/README.md Commands to install dependencies, build the client, and start the Next.js development server. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/nextjs/ $ yarn build-client $ yarn dev ``` -------------------------------- ### Install and Build Dependencies Source: https://github.com/graphprotocol/graph-client/blob/main/examples/cross-chain-sdk/README.md Commands to install dependencies, build the client, and run the example in a monorepo setup. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/cross-chain-sdk $ yarn build-client $ yarn start ``` -------------------------------- ### Install and Build Project Dependencies Source: https://github.com/graphprotocol/graph-client/blob/main/examples/urql-live-query/README.md Follow these commands to set up the project, build the client, and run the Urql live query example. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/urql-live-query/ $ yarn build-client $ yarn start ``` -------------------------------- ### Install Dependencies and Build Client Source: https://github.com/graphprotocol/graph-client/blob/main/examples/react-query/README.md Commands to install dependencies, build the monorepo, build the client for the React Query example, and start the development server. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/react-query/ $ yarn build-client $ yarn start ``` -------------------------------- ### Install and Build The Graph Client Source: https://github.com/graphprotocol/graph-client/blob/main/examples/cross-chain-extension/README.md Commands to install dependencies, build the client, and run the cross-chain extension example. ```bash # In the root directory $ yarn install $ yarn build $ cd examples/cross-chain-extension $ yarn build-client $ yarn start ``` -------------------------------- ### Typed SDK Setup and Usage Source: https://github.com/graphprotocol/graph-client/blob/main/packages/x402/README.md Install necessary packages and configure `.graphclientrc.yml` for type-safe SDK generation. Define queries in `.graphql` files and use `graphclient build`. ```bash npm install @graphprotocol/client-cli @graphprotocol/client-x402 ``` ```yaml customFetch: '@graphprotocol/client-x402' sources: - name: uniswap handler: graphql: endpoint: https://gateway.thegraph.com/api/x402/subgraphs/id/ documents: - "./src/queries/*.graphql" ``` ```graphql query GetPairs($first: Int!) { pairs(first: $first) { id token0 { symbol } token1 { symbol } } } ``` ```bash export X402_PRIVATE_KEY=0xabc123... export X402_CHAIN=base graphclient build rm .graphclient/package.json # Required: mesh generates broken ESM exports ``` ```typescript import { execute, GetPairsDocument } from './.graphclient' const result = await execute(GetPairsDocument, { first: 5 }) // ^ fully typed based on your schema and query ``` -------------------------------- ### Example Build Output Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md This is an example of the output you can expect when running the 'graphclient build' command. ```text GraphClient: Cleaning existing artifacts GraphClient: Reading the configuration 🕸️: Generating the unified schema 🕸️: Generating artifacts 🕸️: Generating index file in TypeScript 🕸️: Writing index.ts for ESM to the disk. 🕸️: Cleanup 🕸️: Done! => .graphclient ``` -------------------------------- ### Start Graph Client DevTools Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Run the 'graphclient serve-dev' command to start the built-in GraphiQL development server for experimenting with queries. ```bash graphclient serve-dev ``` -------------------------------- ### Install Prefix Transform with npm Source: https://github.com/graphprotocol/graph-client/blob/main/examples/transforms/README.md Install the `@graphql-mesh/transform-prefix` dependency using npm. ```bash npm i -D @graphql-mesh/transform-prefix ``` -------------------------------- ### Install Prefix Transform with pnpm Source: https://github.com/graphprotocol/graph-client/blob/main/examples/transforms/README.md Install the `@graphql-mesh/transform-prefix` dependency using pnpm. ```bash pnpm add -D @graphql-mesh/transform-prefix ``` -------------------------------- ### Install Prefix Transform with yarn Source: https://github.com/graphprotocol/graph-client/blob/main/examples/transforms/README.md Install the `@graphql-mesh/transform-prefix` dependency using yarn. ```bash yarn add -D @graphql-mesh/transform-prefix ``` -------------------------------- ### Install Graph Client CLI Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Install The Graph Client CLI as a development dependency in your project. ```sh yarn add -D @graphprotocol/client-cli ``` -------------------------------- ### Run The Graph Client DevTools Source: https://github.com/graphprotocol/graph-client/blob/main/examples/composition/README.md Launches The Graph Client DevTools for interactive querying. This command can be run from the example's directory. ```bash yarn graphiql ``` -------------------------------- ### Install Graph Client CLI Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Install the Graph Client CLI as a dev dependency using npm. ```bash npm install --save-dev @graphprotocol/client-cli ``` -------------------------------- ### Programmatic Query with x402 Source: https://github.com/graphprotocol/graph-client/blob/main/packages/x402/README.md Install the package and use `createGraphQuery` for programmatic access in scripts or bots. No build step or types are required. ```bash npm install @graphprotocol/client-x402 ``` ```typescript import { createGraphQuery } from '@graphprotocol/client-x402' const query = createGraphQuery({ endpoint: 'https://gateway.thegraph.com/api/x402/subgraphs/id/', chain: 'base', }) const result = await query('{ pairs(first: 5) { id } }') console.log(result.data) ``` -------------------------------- ### Environment Variables for Configuration Source: https://github.com/graphprotocol/graph-client/blob/main/packages/x402/README.md Configure the x402 client using environment variables for private key and payment chain. ```bash export X402_PRIVATE_KEY=0x... export X402_CHAIN=base # Optional: "base" (default) or "base-sepolia" ``` -------------------------------- ### CLI Query with x402 Source: https://github.com/graphprotocol/graph-client/blob/main/packages/x402/README.md Use the CLI for quick queries or shell scripts. Ensure the X402_PRIVATE_KEY environment variable is set. ```bash export X402_PRIVATE_KEY=0xabc123... npx @graphprotocol/client-x402 "{ pairs(first: 5) { id } }" \ --endpoint https://gateway.thegraph.com/api/x402/subgraphs/id/ \ --chain base ``` -------------------------------- ### Graph Client Configuration File Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Create a .graphclientrc.yml file to configure GraphQL endpoints for The Graph. ```yaml # .graphclientrc.yml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 ``` -------------------------------- ### Build Graph Client Artifacts Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Run the Graph Client CLI to build runtime artifacts. This command should be prefixed with 'yarn'. ```bash graphclient build ``` -------------------------------- ### Graph-Client Integration with Any GraphQL Client Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Shows how the Graph-Client can be integrated with any existing GraphQL client through a compatibility layer, allowing it to execute queries. ```mermaid graph LR; c[Any GraphQL Client]-->|fetch/Urql Exchange/Apollo Link|l[Compatibility Layer]; l-->|executes|g[Graph-Client]; g-->op[Orchestrator/Query Planner] op-->sA[Subgraph A]; op-->sB[Subgraph B]; ``` -------------------------------- ### Typed SDK Mode: Build and Execute Source: https://github.com/graphprotocol/graph-client/blob/main/examples/client-x402/README.md Utilize the Typed SDK for full type safety with a generated SDK. This involves building the client and then executing a TypeScript file. ```bash export X402_PRIVATE_KEY=0x... export X402_CHAIN=base-sepolia npx graphclient build npx tsx index.ts ``` -------------------------------- ### Subscription-as-Query Mechanism Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Explains a mechanism that enables GraphQL subscriptions by executing underlying GraphQL queries and using hooks to monitor smart contract changes for real-time updates. ```mermaid graph LR; app[App]-->|subscription somedata|c; c[Any GraphQL Client]-->l[Compatibility Layer]; l-->|executes|g[GraphQL Schema/Executor]; g-->op[Orchestrator] op-->|query somedata|sA[Subgraph]; sc[Smart Contract]-->|change event|op; ``` -------------------------------- ### Subgraph Composition using graphql-tools Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Demonstrates the process of composing multiple subgraph schemas into a single schema or executor using a Composer, facilitated by tools like graphql-tools. ```mermaid graph LR; g[GraphQL Schema/Executor]-->m{Composer}; m-->s1[Subgraph A GraphQL schema]; m-->s2[Subgraph B GraphQL schema]; m-->s3[Subgraph C GraphQL schema]; ``` -------------------------------- ### Configure Polling Live Plugin Source: https://github.com/graphprotocol/graph-client/blob/main/docs/live.md Add this configuration to your .graphclientrc.yml file to enable the pollingLive plugin with a default interval. ```yaml plugins: - pollingLive: defaultInterval: 1000 ``` -------------------------------- ### Standalone Graph-Client Execution Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Illustrates the basic execution flow where the Graph-Client runs in a browser or Node.js environment and interacts with the Orchestrator/Query Planner. ```mermaid graph LR; c[Browser/Node]-->|executes|g[Graph-Client]; g-->op[Orchestrator/Query Planner] op-->sA[Subgraph A]; op-->sB[Subgraph B]; ``` -------------------------------- ### Using Generated TypedDocumentNode in TypeScript Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Import and use the generated `ExampleQueryDocument` for GraphQL calls in TypeScript to achieve a fully typed experience. Ensure GraphQL operations are named. ```typescript import { ExampleQueryDocument, execute } from '../.graphclient' async function main() { // "result" variable is fully typed, and represents the exact structure of the fields you selected in your query. const result = await execute(ExampleQueryDocument, {}) console.log(result) } ``` -------------------------------- ### CLI Mode: Direct Terminal Query Source: https://github.com/graphprotocol/graph-client/blob/main/examples/client-x402/README.md Execute queries directly from the terminal using the CLI script. Ensure X402_PRIVATE_KEY and X402_CHAIN environment variables are set. ```bash export X402_PRIVATE_KEY=0x... export X402_CHAIN=base-sepolia ./cli.sh http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }' ``` -------------------------------- ### Configure File Type for Artifacts Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Use the '--fileType' flag to configure the CLI to generate JavaScript or JSON files instead of TypeScript. ```bash graphclient --fileType js ``` -------------------------------- ### Configure Client-side Composition with Multiple Sources Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Define multiple GraphQL sources in your .graphclient.yml file to enable client-side composition, allowing queries across different subgraphs. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 - name: compoundv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/graphprotocol/compound-v2 ``` -------------------------------- ### GraphQL Query with Paginated Fetch (First Page) Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md The first part of a manual pagination strategy, fetching the initial set of records within the subgraph's limit. ```graphql query { # Will throw an error if the limit is 1000 users(first: 1000) { id name } } ``` -------------------------------- ### Programmatic Mode: Scripted Query Source: https://github.com/graphprotocol/graph-client/blob/main/examples/client-x402/README.md Use the programmatic approach in scripts without a build step. Set environment variables and run the script using tsx. ```bash export X402_PRIVATE_KEY=0x... export X402_CHAIN=base-sepolia npx tsx programmatic.ts http://localhost:7700/api/x402/deployments/id/Qm... '{ indexers { id } }' ``` -------------------------------- ### Configure Additional Resolvers in .graphclientrc.yml Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Point to a file containing custom GraphQL resolvers using the `additionalResolvers` configuration. This enables implementing custom mutation logic. ```yaml additionalResolvers: - './resolvers' ``` -------------------------------- ### Subgraph Execution Strategies: Retry Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Shows the 'Retry' strategy, where a query is sent to a source, and if it fails, the source retries the query. ```mermaid graph LR; subgraph retry req3(Outgoing Query)-->sA3[Subgraph A]; sA3-->d3{RetryStrategy}; d3-->s5[Source 1]; s5-->|error|s5; s5-->|ok|d3; end ``` -------------------------------- ### Implement Custom Mutation Resolver in JavaScript Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Implement the custom mutation logic in a JavaScript file. The `doSomething` mutation can execute arbitrary code, such as using web3 libraries or connecting wallets. ```javascript module.exports = { Mutation: { async doSomething(root, args, context, info) { // Here, you can run anything you wish. // For example, use `web3` lib, connect a wallet and so on. return true }, }, } ``` -------------------------------- ### Interpolate Environment Variables at Runtime Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Use the `env` helper to interpolate environment variables for runtime configuration. Ensure the environment variable is defined when `process.env` is called. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 operationHeaders: Authorization: Bearer {env.MY_API_TOKEN} # runtime ``` -------------------------------- ### GraphQL Query with Default Live Interval Source: https://github.com/graphprotocol/graph-client/blob/main/docs/live.md Apply the @live directive to a GraphQL query to enable real-time updates using the default interval configured in .graphclientrc.yml. ```graphql query ExampleQuery @live { transactions(first: 2, orderBy: timestamp, orderDirection: desc) { id blockNumber timestamp } } ``` -------------------------------- ### Subgraph Execution Strategies: Race Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Illustrates the 'Race' strategy for subgraph execution, where an outgoing query is sent to multiple sources, and the first successful response is used. ```mermaid graph LR; subgraph race req(Outgoing Query)-->sA[Subgraph A]; sA-->d{RaceStrategy}; d-->s1[Source 1]; d-->s2[Source 2]; s1-->d; s2-->d; end ``` -------------------------------- ### Configure Automatic Block Tracking Source: https://github.com/graphprotocol/graph-client/blob/main/packages/block-tracking/README.md Configure automatic block tracking in your `.graphclientrc.yml` file. The `blockTracking` transform automatically fetches and uses block information for future queries. Ensure your schema source contains `_meta` and input block filters by setting `validateSchema` to true. ```yaml # .graphclientrc.yml sources: - name: uniswap handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 transforms: # The following section will make sure to automatically fetch the block information, and then use it for tracking in future queries. - blockTracking: validateSchema: true # Validates that the schema source actually contains _meta and input block filters. ``` -------------------------------- ### Subgraph Execution Strategies: Fallback Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Depicts the 'Fallback' strategy, where a query is sent to a primary source, and if it fails, it falls back to a secondary source. ```mermaid graph LR; subgraph fallback req2(Outgoing Query)-->sA2[Subgraph A]; sA2-->d2{FallbackStrategy}; d2-->s3[Source 1]; s3-->|error|s4[Source 2]; s4-->|ok|d2; s3-->|ok|d2; end ``` -------------------------------- ### Interpolate Environment Variables at Build Time Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Specify environment variables directly to be filled during the `graphclient build` process. This is useful for build-time configuration. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 operationHeaders: Authorization: Bearer ${MY_API_TOKEN} # build time ``` -------------------------------- ### Configure Documents in .graphclientrc.yml Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Specify GraphQL operation files or directories for The Graph Client CLI to find and generate TypedDocumentNode objects. Supports glob expressions. ```yaml sources: - # ... your Subgraphs/GQL sources here documents: - ./src/example-query.graphql ``` ```yaml documents: - './src/**/*.graphql' - './src/**/*.{ts,tsx,js,jsx}' ``` -------------------------------- ### Configure Auto Pagination in .graphclientrc.yml Source: https://github.com/graphprotocol/graph-client/blob/main/packages/auto-pagination/README.md Configure automatic pagination by specifying the 'autoPagination' transform in your .graphclientrc.yml file. You can set 'validateSchema' to true to ensure the schema supports the required input filters and 'limitOfRecords' to adjust the maximum number of records per query based on your indexer's configuration. ```yaml # .graphclientrc.yml sources: - name: uniswap handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 transforms: - autoPagination: validateSchema: true # Validates that the schema source actually contains the required input filters. limitOfRecords: 1000 # Default is 1000, you can change if you indexer has different configuration in GRAPH_GRAPHQL_MAX_FIRST var. ``` -------------------------------- ### Use Runtime Variables in Operation Headers Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Use runtime variables within operation headers by referencing context configuration. This allows for dynamic token injection. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 operationHeaders: Authorization: Bearer {context.config.apiToken} ``` -------------------------------- ### GraphQL Query with Paginated Fetch (Second Page) Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md The second part of a manual pagination strategy, fetching the next set of records by using the 'skip' argument. ```graphql query { # Will throw an error if the limit is 1000 users(first: 1000, skip: 1000) { id name } } ``` -------------------------------- ### Configure Automatic Pagination Transform Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Enable the autoPagination transform in your .graphclient.yml to automatically handle paginated results from subgraphs. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 transforms: - autoPagination: # You might want to disable schema validation for faster startup validateSchema: true ``` -------------------------------- ### Customize Network Calls with Operation Headers Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Configure operation headers in the .graphclientrc.yml file to add custom headers like authentication tokens to network requests. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 operationHeaders: Authorization: Bearer MY_TOKEN ``` -------------------------------- ### Configure Block Tracking Transform Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Configure the blockTracking transform in your .graphclient.yml file to monitor block numbers and ignore specific fields or operations. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 transforms: - blockTracking: # You might want to disable schema validation for faster startup validateSchema: true # Ignore the fields that you don't want to be tracked ignoreFieldNames: [users, prices] # Exclude the operation with the following names ignoreOperationNames: [NotFollowed] ``` -------------------------------- ### Configure Race Strategy with Multiple Endpoints Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Employ the race strategy to query multiple GraphQL endpoints concurrently for the same source. The fastest response from any of the specified indexers will be returned. ```yaml sources: - name: uniswapv2 handler: graphql: strategy: race sources: - endpoint: https://bad-uniswap-v2-api.com - endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 ``` -------------------------------- ### Subgraph Execution Strategies: HighestValue Source: https://github.com/graphprotocol/graph-client/blob/main/docs/architecture.md Details the 'HighestValue' strategy, which selects the source with the maximum block number among available sources for query execution. ```mermaid graph LR; subgraph highestValue req4(Outgoing Query)-->sA4[Subgraph A]; sA4-->d4{HighestValueStrategy}; d4-->s14[Source 1]; d4-->s24[Source 2]; s14-->synced4["process"] s24-->synced4 synced4-->|"max(_meta.block_number)"|d4 end ``` -------------------------------- ### Configure Highest Value Strategy for Most Synced Data Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Utilize the highestValue strategy to query multiple endpoints in parallel and select the data from the most up-to-date indexer. This strategy is useful for ensuring you retrieve the latest synchronized data. ```yaml sources: - name: uniswapv2 handler: graphql: strategy: highestValue strategyConfig: selectionSet: | { _meta { block { number } } } value: '_meta.block.number' sources: - endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2-1 - endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2-2 ``` -------------------------------- ### Configure Fallback Strategy with Multiple Endpoints Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Use the fallback strategy to specify multiple GraphQL endpoints for a single source. If an error or timeout occurs with the primary endpoint, it will fall back to the next one in the list. ```yaml sources: - name: uniswapv2 handler: graphql: strategy: fallback sources: - endpoint: https://bad-uniswap-v2-api.com retry: 2 timeout: 5000 - endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 ``` -------------------------------- ### Query Composed Schemas Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Execute a single GraphQL query that fetches data from multiple subgraphs defined in the client configuration, demonstrating client-side composition. ```graphql query myQuery { # this one is coming from compound-v2 markets(first: 7) { borrowRate } # this one is coming from uniswap-v2 pair(id: "0x00004ee988665cdda9a1080d5792cecd16dc1220") { id token0 { id } token1 { id } } } ``` -------------------------------- ### GraphQL Query with Per-Query Live Interval Source: https://github.com/graphprotocol/graph-client/blob/main/docs/live.md Specify a custom interval directly within the @live directive for a specific GraphQL query. ```graphql query ExampleQuery @live(interval: 5000) { transactions(first: 2, orderBy: timestamp, orderDirection: desc) { id } } ``` -------------------------------- ### Execute GraphQL Query with Generated Client Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Import and use the generated 'execute' function to run GraphQL operations in your TypeScript code. ```typescript import { execute } from '../.graphclient' const myQuery = gql` query pairs { pair(id: "0x00004ee988665cdda9a1080d5792cecd16dc1220") { id token0 { id symbol name } token1 { id symbol name } } } ` async function main() { const result = await execute(myQuery, {}) console.log(result) } main() ``` -------------------------------- ### Define AdditionalTypeDefs in .graphclientrc.yml Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Extend the schema with custom types and mutations by defining `additionalTypeDefs` in the configuration file. This allows for custom logic within the GraphQL schema. ```yaml additionalTypeDefs: | # We should define the missing `Mutation` type extend schema { mutation: Mutation } type Mutation { doSomething(input: SomeCustomInput!): Boolean! } input SomeCustomInput { field: String! } ``` -------------------------------- ### Configure Timeout for GraphQL Endpoint Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Set a timeout for a specific GraphQL endpoint to prevent requests from hanging indefinitely. The timeout is specified in milliseconds. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 timeout: 5000 # 5 seconds ``` -------------------------------- ### Configure Retry Strategy for GraphQL Endpoint Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Implement a retry mechanism for a GraphQL endpoint to handle network errors or runtime indexing issues. Specify the number of retry attempts. ```yaml sources: - name: uniswapv2 handler: graphql: endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2 retry: 2 # specify here, if you have an unstable/error prone indexer ``` -------------------------------- ### Implement Custom Mutation Resolver in TypeScript Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Implement the custom mutation logic in a TypeScript file, leveraging the `Resolvers` type generated by The Graph Client for full type safety. This ensures correct argument and return types. ```typescript import { Resolvers } from './.graphclient' // Now it's fully typed! const resolvers: Resolvers = { Mutation: { async doSomething(root, args, context, info) { // Here, you can run anything you wish. // For example, use `web3` lib, connect a wallet and so on. return true }, }, } export default resolvers ``` -------------------------------- ### Inject Runtime Variables into GraphQL Context Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Inject runtime variables into the GraphQL execution context using the `execute` function. These variables become available in mutation resolvers as properties of the `context` object. ```typescript execute( MY_QUERY, {}, { myHelper: {}, // this will be available in your Mutation resolver as `context.myHelper` }, ) ``` -------------------------------- ### Execute Operation with Runtime Variables Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md Pass runtime variables to the execute function during operation execution to supply values for dynamic configurations like API tokens. ```typescript execute(myQuery, myVariables, { config: { apiToken: 'MY_TOKEN', }, }) ``` -------------------------------- ### GraphQL Query with High Limit Source: https://github.com/graphprotocol/graph-client/blob/main/docs/README.md This GraphQL query attempts to fetch more users than a typical subgraph limit (e.g., 1000), which would normally result in an error. ```graphql query { # Will throw an error if the limit is 1000 users(first: 2000) { id name } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.