diff --git a/.changeset/spotty-ads-wonder.md b/.changeset/spotty-ads-wonder.md new file mode 100644 index 0000000000000..28ca55f8c4ef7 --- /dev/null +++ b/.changeset/spotty-ads-wonder.md @@ -0,0 +1,6 @@ +--- +"@graphql-mesh/supergraph": patch +"@graphql-mesh/types": patch +--- + +`operationHeaders` in Supergraph Handler diff --git a/packages/handlers/supergraph/src/index.ts b/packages/handlers/supergraph/src/index.ts index 0cf1fac372208..2f2ef59152090 100644 --- a/packages/handlers/supergraph/src/index.ts +++ b/packages/handlers/supergraph/src/index.ts @@ -16,7 +16,7 @@ import { YamlConfig, } from '@graphql-mesh/types'; import { isUrl, readFile, readUrl } from '@graphql-mesh/utils'; -import { buildHTTPExecutor } from '@graphql-tools/executor-http'; +import { buildHTTPExecutor, HTTPExecutorOptions } from '@graphql-tools/executor-http'; import { getStitchedSchemaFromSupergraphSdl } from '@graphql-tools/federation'; export default class SupergraphHandler implements MeshHandler { @@ -86,12 +86,26 @@ export default class SupergraphHandler implements MeshHandler { async getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise { this.fetchFn = fetchFn; const supergraphSdl = await this.getSupergraphSdl(); + const operationHeadersFactory = + this.config.operationHeaders != null + ? getInterpolatedHeadersFactory(this.config.operationHeaders) + : undefined; const schema = getStitchedSchemaFromSupergraphSdl({ supergraphSdl, - onExecutor({ endpoint }) { - return buildHTTPExecutor({ endpoint, fetch: fetchFn }); + onExecutor: ({ endpoint }) => { + return buildHTTPExecutor({ + endpoint, + fetch: fetchFn, + headers: + operationHeadersFactory && + (execReq => + operationHeadersFactory({ + env: process.env, + context: execReq.context, + })), + } as HTTPExecutorOptions); }, - batch: true, + batch: this.config.batch == null ? true : this.config.batch, }); return { schema, diff --git a/packages/handlers/supergraph/yaml-config.graphql b/packages/handlers/supergraph/yaml-config.graphql index 972ab72e6c720..5f5dadf0b53bb 100644 --- a/packages/handlers/supergraph/yaml-config.graphql +++ b/packages/handlers/supergraph/yaml-config.graphql @@ -11,4 +11,8 @@ type SupergraphHandler @md { source: String! schemaHeaders: Any + + operationHeaders: Any + + batch: Boolean } diff --git a/packages/types/src/config-schema.json b/packages/types/src/config-schema.json index 90e9e46bacb2e..44d9dfe1a98b2 100644 --- a/packages/types/src/config-schema.json +++ b/packages/types/src/config-schema.json @@ -3069,6 +3069,24 @@ "additionalItems": true } ] + }, + "operationHeaders": { + "anyOf": [ + { + "type": "object", + "additionalProperties": true + }, + { + "type": "string" + }, + { + "type": "array", + "additionalItems": true + } + ] + }, + "batch": { + "type": "boolean" } }, "required": ["source"] diff --git a/packages/types/src/config.ts b/packages/types/src/config.ts index 4ed1ac6f9bb75..52403c740caa0 100644 --- a/packages/types/src/config.ts +++ b/packages/types/src/config.ts @@ -1009,6 +1009,8 @@ export interface SupergraphHandler { */ source: string; schemaHeaders?: any; + operationHeaders?: any; + batch?: boolean; } /** * Handler for OData diff --git a/website/src/generated-markdown/SupergraphHandler.generated.md b/website/src/generated-markdown/SupergraphHandler.generated.md index 02cb454b9d579..90b0ce11e6f39 100644 --- a/website/src/generated-markdown/SupergraphHandler.generated.md +++ b/website/src/generated-markdown/SupergraphHandler.generated.md @@ -2,4 +2,6 @@ * `source` (type: `String`, required) - A file path to your Supergraph Schema 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`) \ No newline at end of file +* `schemaHeaders` (type: `Any`) +* `operationHeaders` (type: `Any`) +* `batch` (type: `Boolean`) \ No newline at end of file