GraphQL handlers
This handler allows you to load remote GraphQL schemas as part of your mesh. The GraphQL handler uses the following format:
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://your-service/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
Consider a scenario where 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://your-service/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 a local schema by using the additionalTypeDefs
and additionalResolvers
configuration options.
Config API reference
endpoint
(type:String
, required) - URL or file path for your remote GraphQL endpoint- Local file types must be
.js
or.ts
.
- Local file types must be
schemaHeaders
(type:Any
) - JSON object for adding headers to API calls for runtime schema introspectionoperationHeaders
(type:JSON
) - JSON object for adding headers to API calls for runtime operation executionuseGETForQueries
(type:Boolean
) - An HTTP GET method for query operationsmethod
(type:String (GET | POST)
) - An HTTP method for GraphQL operations