If you want to load a remote GraphQL subgraph from a URL, you can provide source in the
configuration like below;
In this case, Mesh will take the schema from source, but execute the operations against the
endpoint.
In this case, Mesh won’t introspect the endpoint, and use source as a source schema before
applying any transformations etc.
mesh-config.ts
import { defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli'export const composeConfig = defineConfig({ subgraphs: [ { sourceHandler: loadGraphQLHTTPSubgraph('GitHub', { endpoint: 'https://api.github.com/graphql', // You can provide your SDL or introspection seperately source: 'https://docs.github.com/public/schema.docs.graphql', operationHeaders: { // This forwards the header from the incoming request to the remote server authorization: 'Bearer {context.headers["x-my-api-token"]}' } }) } ]})
Fetch Strategies and Multiple HTTP endpoints for the same source
If you want to have an advanced fetch strategy for the GraphQL source such as retrying twice or
timeout in 30 seconds etc. Also, you can have different HTTP endpoints for a single source, and you
can configure Mesh to get a better execution flow.
For example, you can make a request to both endpoints and return the fastest response with race
strategy.
All fetch strategies can be combined to create the ultimate execution flow:
retry
The retry mechanism allow you to specify the retry attempts for a single GraphQL endpoint/source.
The retry flow will execute in both conditions: a network error, or due to a runtime error.
mesh-config.ts
import { defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli'export const composeConfig = defineConfig({ subgraphs: [ { sourceHandler: loadGraphQLHTTPSubgraph('Uniswap', { endpoint: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2', // Specify here, if you have an unstable/error prone indexer retry: 2 }) } ]})
timeout
The timeout mechanism allow you to specify the timeout for a given GraphQL endpoint.