@graphql-mesh/supergraph 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -51,6 +51,7 @@ class SupergraphHandler {
51
51
  });
52
52
  }
53
53
  async getMeshSource({ fetchFn }) {
54
+ const subgraphConfigs = this.config.subgraphs || [];
54
55
  this.fetchFn = fetchFn;
55
56
  const supergraphSdl = await this.getSupergraphSdl();
56
57
  const operationHeadersFactory = this.config.operationHeaders != null
@@ -58,15 +59,32 @@ class SupergraphHandler {
58
59
  : undefined;
59
60
  const schema = (0, federation_1.getStitchedSchemaFromSupergraphSdl)({
60
61
  supergraphSdl,
61
- onExecutor: ({ endpoint }) => {
62
+ onExecutor: ({ subgraphName, endpoint }) => {
63
+ const subgraphConfiguration = subgraphConfigs.find(subgraphConfig => subgraphConfig.name === subgraphName) || {
64
+ name: subgraphName,
65
+ };
62
66
  return (0, executor_http_1.buildHTTPExecutor)({
63
67
  endpoint,
68
+ ...subgraphConfiguration,
64
69
  fetch: fetchFn,
65
- headers: operationHeadersFactory &&
66
- (execReq => operationHeadersFactory({
70
+ headers(executorRequest) {
71
+ const subgraphConfiguration = subgraphConfigs.find(subgraphConfig => subgraphConfig.name === subgraphName);
72
+ const headers = {};
73
+ const resolverData = {
74
+ root: executorRequest.rootValue,
67
75
  env: cross_helpers_1.process.env,
68
- context: execReq.context,
69
- })),
76
+ context: executorRequest.context,
77
+ info: executorRequest.info,
78
+ args: executorRequest.variables,
79
+ };
80
+ if (subgraphConfiguration?.operationHeaders) {
81
+ const headersFactory = (0, string_interpolation_1.getInterpolatedHeadersFactory)(subgraphConfiguration.operationHeaders);
82
+ Object.assign(headers, headersFactory(resolverData));
83
+ }
84
+ if (operationHeadersFactory) {
85
+ Object.assign(headers, operationHeadersFactory(resolverData));
86
+ }
87
+ },
70
88
  });
71
89
  },
72
90
  batch: this.config.batch == null ? true : this.config.batch,
package/esm/index.js CHANGED
@@ -49,6 +49,7 @@ export default class SupergraphHandler {
49
49
  });
50
50
  }
51
51
  async getMeshSource({ fetchFn }) {
52
+ const subgraphConfigs = this.config.subgraphs || [];
52
53
  this.fetchFn = fetchFn;
53
54
  const supergraphSdl = await this.getSupergraphSdl();
54
55
  const operationHeadersFactory = this.config.operationHeaders != null
@@ -56,15 +57,32 @@ export default class SupergraphHandler {
56
57
  : undefined;
57
58
  const schema = getStitchedSchemaFromSupergraphSdl({
58
59
  supergraphSdl,
59
- onExecutor: ({ endpoint }) => {
60
+ onExecutor: ({ subgraphName, endpoint }) => {
61
+ const subgraphConfiguration = subgraphConfigs.find(subgraphConfig => subgraphConfig.name === subgraphName) || {
62
+ name: subgraphName,
63
+ };
60
64
  return buildHTTPExecutor({
61
65
  endpoint,
66
+ ...subgraphConfiguration,
62
67
  fetch: fetchFn,
63
- headers: operationHeadersFactory &&
64
- (execReq => operationHeadersFactory({
68
+ headers(executorRequest) {
69
+ const subgraphConfiguration = subgraphConfigs.find(subgraphConfig => subgraphConfig.name === subgraphName);
70
+ const headers = {};
71
+ const resolverData = {
72
+ root: executorRequest.rootValue,
65
73
  env: process.env,
66
- context: execReq.context,
67
- })),
74
+ context: executorRequest.context,
75
+ info: executorRequest.info,
76
+ args: executorRequest.variables,
77
+ };
78
+ if (subgraphConfiguration?.operationHeaders) {
79
+ const headersFactory = getInterpolatedHeadersFactory(subgraphConfiguration.operationHeaders);
80
+ Object.assign(headers, headersFactory(resolverData));
81
+ }
82
+ if (operationHeadersFactory) {
83
+ Object.assign(headers, operationHeadersFactory(resolverData));
84
+ }
85
+ },
68
86
  });
69
87
  },
70
88
  batch: this.config.batch == null ? true : this.config.batch,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-mesh/supergraph",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@graphql-mesh/cross-helpers": "^0.4.1",
7
- "@graphql-mesh/store": "^0.97.4",
8
- "@graphql-mesh/types": "^0.97.4",
9
- "@graphql-mesh/utils": "^0.97.4",
7
+ "@graphql-mesh/store": "^0.97.5",
8
+ "@graphql-mesh/types": "^0.97.5",
9
+ "@graphql-mesh/utils": "^0.97.5",
10
10
  "graphql": "*",
11
11
  "tslib": "^2.4.0"
12
12
  },