Skip to content

Commit

Permalink
feat(supergraph): operationHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jan 16, 2024
1 parent 2655d5f commit ac26793
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/spotty-ads-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@graphql-mesh/supergraph": patch
"@graphql-mesh/types": patch
---

`operationHeaders` in Supergraph Handler
22 changes: 18 additions & 4 deletions packages/handlers/supergraph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,12 +86,26 @@ export default class SupergraphHandler implements MeshHandler {
async getMeshSource({ fetchFn }: GetMeshSourcePayload): Promise<MeshSource> {
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,
Expand Down
4 changes: 4 additions & 0 deletions packages/handlers/supergraph/yaml-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ type SupergraphHandler @md {
source: String!

schemaHeaders: Any

operationHeaders: Any

batch: Boolean
}
18 changes: 18 additions & 0 deletions packages/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3069,6 +3069,24 @@
"additionalItems": true
}
]
},
"operationHeaders": {
"anyOf": [
{
"type": "object",
"additionalProperties": true
},
{
"type": "string"
},
{
"type": "array",
"additionalItems": true
}
]
},
"batch": {
"type": "boolean"
}
},
"required": ["source"]
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,8 @@ export interface SupergraphHandler {
*/
source: string;
schemaHeaders?: any;
operationHeaders?: any;
batch?: boolean;
}
/**
* Handler for OData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
* `schemaHeaders` (type: `Any`)
* `operationHeaders` (type: `Any`)
* `batch` (type: `Boolean`)

0 comments on commit ac26793

Please sign in to comment.