GraphQL handlers
This handler allows you to load remote GraphQL schemas and use them with schema-stitching, based on graphql-tools
. To get started, use the handler in your Mesh config file:
Copied to your clipboard{"sources": [{"name": "MyGraphQLApi","handler": {"graphql": {"endpoint": "https://my-service-url/graphql"}}}]}
GraphQL handlers can also use local sources, see Reference local file handlers for more information.
Headers from context
Copied to your clipboard{"sources": [{"name": "MyGraphQLApi","handler": {"graphql": {"endpoint": "https://my-service-url/graphql","operationHeaders": {"Authorization": "Bearer {context.headers['x-my-api-token']}"// Do not use capital letters in header names.}}}}]}
Header names are automatically converted to lowercase.
Fetching SDL or introspection from CDN or somewhere
Imagine that introspection is disabled in the production environment of your GraphQL source, and you want to provide your SDL or introspection separately:
Copied to your clipboard{"sources": [{"name": "MyGraphQLApi","handler": {"graphql": {"endpoint": "https://api.github.com/graphql","operationHeaders": {"Authorization": "Bearer {context.headers['GITHUB_TOKEN']}"}}}}]}
In this case, CLI's build
command won't save the introspection in the artifacts, so your Mesh won't start if the source
URL is down.
Local Schemas
We recommend providing local schema by using the additionalTypeDefs
and additionalResolvers
configuration options.
Config API reference
endpoint
(type:String
, required) - A URL or file path to your remote GraphQL endpoint. If you provide a path to a code file(js or ts), other options will be ignored and the schema exported from the file will be used directly.schemaHeaders
(type:Any
) - JSON object representing the Headers to add to the runtime of the API calls only for schema introspectionoperationHeaders
(type:JSON
) - JSON object representing the Headers to add to the runtime of the API calls only for operation during runtimeuseGETForQueries
(type:Boolean
) - Use HTTP GET for Query operationsmethod
(type:String (GET | POST)
) - HTTP method used for GraphQL operations