@graphql-mesh/runtime 0.96.8 → 0.96.9-alpha-20231009133300-312e08898

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/get-mesh.js CHANGED
@@ -8,6 +8,7 @@ const graphql_jit_1 = require("@envelop/graphql-jit");
8
8
  const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
9
9
  const utils_1 = require("@graphql-mesh/utils");
10
10
  const delegate_1 = require("@graphql-tools/delegate");
11
+ const executor_1 = require("@graphql-tools/executor");
11
12
  const utils_2 = require("@graphql-tools/utils");
12
13
  const fetch_1 = require("@whatwg-node/fetch");
13
14
  const constants_js_1 = require("./constants.js");
@@ -19,13 +20,6 @@ const memoizedGetEnvelopedFactory = (0, utils_2.memoize1)(function getEnvelopedF
19
20
  plugins,
20
21
  });
21
22
  });
22
- const memoizedGetOperationType = (0, utils_2.memoize1)((document) => {
23
- const operationAST = (0, graphql_1.getOperationAST)(document, undefined);
24
- if (!operationAST) {
25
- throw new Error('Must provide document with a valid operation');
26
- }
27
- return operationAST.operation;
28
- });
29
23
  function wrapFetchWithPlugins(plugins) {
30
24
  const onFetchHooks = [];
31
25
  for (const plugin of plugins) {
@@ -34,18 +28,6 @@ function wrapFetchWithPlugins(plugins) {
34
28
  }
35
29
  }
36
30
  return function wrappedFetchFn(url, options, context, info) {
37
- if (url != null && typeof url !== 'string') {
38
- throw new TypeError(`First parameter(url) of 'fetch' must be a string, got ${(0, utils_2.inspect)(url)}`);
39
- }
40
- if (options != null && typeof options !== 'object') {
41
- throw new TypeError(`Second parameter(options) of 'fetch' must be an object, got ${(0, utils_2.inspect)(options)}`);
42
- }
43
- if (context != null && typeof context !== 'object') {
44
- throw new TypeError(`Third parameter(context) of 'fetch' must be an object, got ${(0, utils_2.inspect)(context)}`);
45
- }
46
- if (info != null && typeof info !== 'object') {
47
- throw new TypeError(`Fourth parameter(info) of 'fetch' must be an object, got ${(0, utils_2.inspect)(info)}`);
48
- }
49
31
  let fetchFn;
50
32
  const doneHooks = [];
51
33
  function setFetchFn(newFetchFn) {
@@ -195,7 +177,7 @@ async function getMesh(options) {
195
177
  }
196
178
  const plugins = [
197
179
  (0, core_1.useEngine)({
198
- execute: graphql_1.execute,
180
+ execute: executor_1.normalizedExecutor,
199
181
  validate: graphql_1.validate,
200
182
  parse: utils_1.parseWithCache,
201
183
  specifiedRules: graphql_1.specifiedRules,
@@ -235,13 +217,12 @@ async function getMesh(options) {
235
217
  const EMPTY_VARIABLES_VALUE = {};
236
218
  function createExecutor(globalContext = EMPTY_CONTEXT_VALUE) {
237
219
  const getEnveloped = memoizedGetEnvelopedFactory(plugins);
238
- const { schema, parse, execute, subscribe, contextFactory } = getEnveloped(globalContext);
220
+ const { schema, parse, execute, contextFactory } = getEnveloped(globalContext);
239
221
  return function meshExecutor(documentOrSDL, variableValues = EMPTY_VARIABLES_VALUE, contextValue = EMPTY_CONTEXT_VALUE, rootValue = EMPTY_ROOT_VALUE, operationName) {
240
222
  const document = typeof documentOrSDL === 'string' ? parse(documentOrSDL) : documentOrSDL;
241
- const executeFn = memoizedGetOperationType(document) === 'subscription' ? subscribe : execute;
242
223
  const contextValue$ = contextFactory(contextValue);
243
224
  if ((0, utils_2.isPromise)(contextValue$)) {
244
- return contextValue$.then(contextValue => executeFn({
225
+ return contextValue$.then(contextValue => execute({
245
226
  schema,
246
227
  document,
247
228
  contextValue,
@@ -250,7 +231,7 @@ async function getMesh(options) {
250
231
  operationName,
251
232
  }));
252
233
  }
253
- return executeFn({
234
+ return execute({
254
235
  schema,
255
236
  document,
256
237
  contextValue: contextValue$,
@@ -37,7 +37,7 @@ const getIntrospectionOperationType = (0, utils_2.memoize1)(function getIntrospe
37
37
  });
38
38
  function getExecuteFn(subschema) {
39
39
  const compiledQueryCache = new WeakMap();
40
- const transformedRequestCache = new WeakMap();
40
+ const transformedDocumentNodeCache = new WeakMap();
41
41
  return function subschemaExecute(args) {
42
42
  const originalRequest = {
43
43
  document: args.document,
@@ -78,7 +78,7 @@ function getExecuteFn(subschema) {
78
78
  };
79
79
  let executor = subschema.executor;
80
80
  if (executor == null) {
81
- if (isStream) {
81
+ if (isStream || operationAST.operation === 'subscription') {
82
82
  executor = (0, delegate_1.createDefaultExecutor)(subschema.schema);
83
83
  }
84
84
  else {
@@ -123,24 +123,23 @@ function getExecuteFn(subschema) {
123
123
  executor = createBatchingExecutor(executor);
124
124
  }
125
125
  */
126
- let transformedRequestAndContext = transformedRequestCache.get(originalRequest.document);
127
- if (!transformedRequestAndContext) {
128
- const transformationContext = {};
129
- const transformedRequest = (0, utils_1.applyRequestTransforms)(originalRequest, delegationContext, transformationContext, subschema.transforms);
130
- transformedRequestAndContext = {
131
- transformedRequest,
132
- transformationContext,
133
- };
134
- transformedRequestCache.set(originalRequest.document, transformedRequestAndContext);
126
+ const transformationContext = {};
127
+ const transformedRequest = (0, utils_1.applyRequestTransforms)(originalRequest, delegationContext, transformationContext, subschema.transforms);
128
+ const cachedTransfomedDocumentNode = transformedDocumentNodeCache.get(originalRequest.document);
129
+ if (cachedTransfomedDocumentNode) {
130
+ transformedRequest.document = cachedTransfomedDocumentNode;
131
+ }
132
+ else {
133
+ transformedDocumentNodeCache.set(originalRequest.document, transformedRequest.document);
135
134
  }
136
135
  function handleResult(originalResult) {
137
136
  if ((0, utils_2.isAsyncIterable)(originalResult)) {
138
- return (0, core_1.mapAsyncIterator)(originalResult, singleResult => (0, utils_1.applyResultTransforms)(singleResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms));
137
+ return (0, core_1.mapAsyncIterator)(originalResult, singleResult => (0, utils_1.applyResultTransforms)(singleResult, delegationContext, transformationContext, subschema.transforms));
139
138
  }
140
- const transformedResult = (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms);
139
+ const transformedResult = (0, utils_1.applyResultTransforms)(originalResult, delegationContext, transformationContext, subschema.transforms);
141
140
  return transformedResult;
142
141
  }
143
- const originalResult$ = executor(transformedRequestAndContext.transformedRequest);
142
+ const originalResult$ = executor(transformedRequest);
144
143
  if ((0, utils_2.isPromise)(originalResult$)) {
145
144
  return originalResult$.then(handleResult);
146
145
  }
package/esm/get-mesh.js CHANGED
@@ -1,11 +1,12 @@
1
- import { execute, getOperationAST, specifiedRules, validate, } from 'graphql';
1
+ import { specifiedRules, validate, } from 'graphql';
2
2
  import { envelop, useEngine, useExtendContext, useSchema } from '@envelop/core';
3
3
  import { OneOfInputObjectsRule, useExtendedValidation } from '@envelop/extended-validation';
4
4
  import { useGraphQlJit } from '@envelop/graphql-jit';
5
5
  import { process } from '@graphql-mesh/cross-helpers';
6
6
  import { applySchemaTransforms, DefaultLogger, getHeadersObj, groupTransforms, parseWithCache, PubSub, } from '@graphql-mesh/utils';
7
7
  import { Subschema } from '@graphql-tools/delegate';
8
- import { getRootTypeMap, inspect, isAsyncIterable, isPromise, mapAsyncIterator, memoize1, } from '@graphql-tools/utils';
8
+ import { normalizedExecutor } from '@graphql-tools/executor';
9
+ import { getRootTypeMap, isAsyncIterable, isPromise, mapAsyncIterator, memoize1, } from '@graphql-tools/utils';
9
10
  import { fetch as defaultFetchFn } from '@whatwg-node/fetch';
10
11
  import { MESH_CONTEXT_SYMBOL } from './constants.js';
11
12
  import { getInContextSDK } from './in-context-sdk.js';
@@ -16,13 +17,6 @@ const memoizedGetEnvelopedFactory = memoize1(function getEnvelopedFactory(plugin
16
17
  plugins,
17
18
  });
18
19
  });
19
- const memoizedGetOperationType = memoize1((document) => {
20
- const operationAST = getOperationAST(document, undefined);
21
- if (!operationAST) {
22
- throw new Error('Must provide document with a valid operation');
23
- }
24
- return operationAST.operation;
25
- });
26
20
  export function wrapFetchWithPlugins(plugins) {
27
21
  const onFetchHooks = [];
28
22
  for (const plugin of plugins) {
@@ -31,18 +25,6 @@ export function wrapFetchWithPlugins(plugins) {
31
25
  }
32
26
  }
33
27
  return function wrappedFetchFn(url, options, context, info) {
34
- if (url != null && typeof url !== 'string') {
35
- throw new TypeError(`First parameter(url) of 'fetch' must be a string, got ${inspect(url)}`);
36
- }
37
- if (options != null && typeof options !== 'object') {
38
- throw new TypeError(`Second parameter(options) of 'fetch' must be an object, got ${inspect(options)}`);
39
- }
40
- if (context != null && typeof context !== 'object') {
41
- throw new TypeError(`Third parameter(context) of 'fetch' must be an object, got ${inspect(context)}`);
42
- }
43
- if (info != null && typeof info !== 'object') {
44
- throw new TypeError(`Fourth parameter(info) of 'fetch' must be an object, got ${inspect(info)}`);
45
- }
46
28
  let fetchFn;
47
29
  const doneHooks = [];
48
30
  function setFetchFn(newFetchFn) {
@@ -191,7 +173,7 @@ export async function getMesh(options) {
191
173
  }
192
174
  const plugins = [
193
175
  useEngine({
194
- execute,
176
+ execute: normalizedExecutor,
195
177
  validate,
196
178
  parse: parseWithCache,
197
179
  specifiedRules,
@@ -231,13 +213,12 @@ export async function getMesh(options) {
231
213
  const EMPTY_VARIABLES_VALUE = {};
232
214
  function createExecutor(globalContext = EMPTY_CONTEXT_VALUE) {
233
215
  const getEnveloped = memoizedGetEnvelopedFactory(plugins);
234
- const { schema, parse, execute, subscribe, contextFactory } = getEnveloped(globalContext);
216
+ const { schema, parse, execute, contextFactory } = getEnveloped(globalContext);
235
217
  return function meshExecutor(documentOrSDL, variableValues = EMPTY_VARIABLES_VALUE, contextValue = EMPTY_CONTEXT_VALUE, rootValue = EMPTY_ROOT_VALUE, operationName) {
236
218
  const document = typeof documentOrSDL === 'string' ? parse(documentOrSDL) : documentOrSDL;
237
- const executeFn = memoizedGetOperationType(document) === 'subscription' ? subscribe : execute;
238
219
  const contextValue$ = contextFactory(contextValue);
239
220
  if (isPromise(contextValue$)) {
240
- return contextValue$.then(contextValue => executeFn({
221
+ return contextValue$.then(contextValue => execute({
241
222
  schema,
242
223
  document,
243
224
  contextValue,
@@ -246,7 +227,7 @@ export async function getMesh(options) {
246
227
  operationName,
247
228
  }));
248
229
  }
249
- return executeFn({
230
+ return execute({
250
231
  schema,
251
232
  document,
252
233
  contextValue: contextValue$,
@@ -34,7 +34,7 @@ const getIntrospectionOperationType = memoize1(function getIntrospectionOperatio
34
34
  });
35
35
  function getExecuteFn(subschema) {
36
36
  const compiledQueryCache = new WeakMap();
37
- const transformedRequestCache = new WeakMap();
37
+ const transformedDocumentNodeCache = new WeakMap();
38
38
  return function subschemaExecute(args) {
39
39
  const originalRequest = {
40
40
  document: args.document,
@@ -75,7 +75,7 @@ function getExecuteFn(subschema) {
75
75
  };
76
76
  let executor = subschema.executor;
77
77
  if (executor == null) {
78
- if (isStream) {
78
+ if (isStream || operationAST.operation === 'subscription') {
79
79
  executor = createDefaultExecutor(subschema.schema);
80
80
  }
81
81
  else {
@@ -120,24 +120,23 @@ function getExecuteFn(subschema) {
120
120
  executor = createBatchingExecutor(executor);
121
121
  }
122
122
  */
123
- let transformedRequestAndContext = transformedRequestCache.get(originalRequest.document);
124
- if (!transformedRequestAndContext) {
125
- const transformationContext = {};
126
- const transformedRequest = applyRequestTransforms(originalRequest, delegationContext, transformationContext, subschema.transforms);
127
- transformedRequestAndContext = {
128
- transformedRequest,
129
- transformationContext,
130
- };
131
- transformedRequestCache.set(originalRequest.document, transformedRequestAndContext);
123
+ const transformationContext = {};
124
+ const transformedRequest = applyRequestTransforms(originalRequest, delegationContext, transformationContext, subschema.transforms);
125
+ const cachedTransfomedDocumentNode = transformedDocumentNodeCache.get(originalRequest.document);
126
+ if (cachedTransfomedDocumentNode) {
127
+ transformedRequest.document = cachedTransfomedDocumentNode;
128
+ }
129
+ else {
130
+ transformedDocumentNodeCache.set(originalRequest.document, transformedRequest.document);
132
131
  }
133
132
  function handleResult(originalResult) {
134
133
  if (isAsyncIterable(originalResult)) {
135
- return mapAsyncIterator(originalResult, singleResult => applyResultTransforms(singleResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms));
134
+ return mapAsyncIterator(originalResult, singleResult => applyResultTransforms(singleResult, delegationContext, transformationContext, subschema.transforms));
136
135
  }
137
- const transformedResult = applyResultTransforms(originalResult, delegationContext, transformedRequestAndContext.transformationContext, subschema.transforms);
136
+ const transformedResult = applyResultTransforms(originalResult, delegationContext, transformationContext, subschema.transforms);
138
137
  return transformedResult;
139
138
  }
140
- const originalResult$ = executor(transformedRequestAndContext.transformedRequest);
139
+ const originalResult$ = executor(transformedRequest);
141
140
  if (isPromise(originalResult$)) {
142
141
  return originalResult$.then(handleResult);
143
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/runtime",
3
- "version": "0.96.8",
3
+ "version": "0.96.9-alpha-20231009133300-312e08898",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@graphql-mesh/cross-helpers": "^0.4.1",
@@ -17,6 +17,7 @@
17
17
  "@graphql-mesh/string-interpolation": "^0.5.2",
18
18
  "@graphql-tools/batch-delegate": "^9.0.0",
19
19
  "@graphql-tools/delegate": "^10.0.0",
20
+ "@graphql-tools/executor": "^1.2.0",
20
21
  "@graphql-tools/wrap": "^10.0.0",
21
22
  "@whatwg-node/fetch": "^0.9.0",
22
23
  "graphql-jit": "0.8.2"