Optional field. Used to set the Headers for schema introspection. Expects JSON object representing
the Headers.
Dynamic Header Values (e.g., for Authorization)
Mesh can take dynamic values from the GraphQL Context or the environmental variables.
The expression inside dynamic values should be as in JS.
From Context
mesh-config.ts
import { defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli'export const composeConfig = defineConfig({ subgraphs: [ { sourceHandler: loadGraphQLHTTPSubgraph('Users', { endpoint: 'http://localhost:4001/users', operationHeaders: { // Please do not use capital letters while getting the headers // Use "{context.headers['x-my-api-token']}" if you want just the value of the header Authorization: 'Bearer {context.headers["x-my-api-token"]}' // You can also access to the cookies like below; // Authorization: Bearer {context.cookies.myApiToken} } }) } ]})
From Environment Variables
Set up the variable on your environment, e.g VERY_SECRET_TOKEN=12345. Then you can use it using
{env.VERY_SECRET_TOKEN}.
The config wil look something like:
mesh-config.ts
import { defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli'export const composeConfig = defineConfig({ subgraphs: [ { sourceHandler: loadGraphQLHTTPSubgraph('Users', { // You can also use the environment variables in the endpoint endpoint: 'http://{env.MY_HOST_NAME}:4001/users', operationHeaders: { Authorization: 'Bearer {env.VERY_SECRET_TOKEN}' } }) } ]})
This site uses cookies for analytics and improving your experience.