@graphql-tools/executor 0.0.10-alpha-20221114133606-dae9ff99 → 0.0.10
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/execution/execute.js +9 -3
- package/esm/execution/execute.js +9 -3
- package/package.json +2 -2
- package/typings/execution/execute.d.cts +4 -5
- package/typings/execution/execute.d.ts +4 -5
- package/typings/execution/flattenAsyncIterable.d.cts +1 -1
- package/typings/execution/flattenAsyncIterable.d.ts +1 -1
- package/typings/execution/normalizedExecutor.d.cts +1 -1
- package/typings/execution/normalizedExecutor.d.ts +1 -1
- package/typings/execution/promiseForObject.d.cts +1 -1
- package/typings/execution/promiseForObject.d.ts +1 -1
- package/typings/execution/values.d.cts +1 -1
- package/typings/execution/values.d.ts +1 -1
package/cjs/execution/execute.js
CHANGED
|
@@ -8,6 +8,12 @@ const promiseForObject_js_1 = require("./promiseForObject.js");
|
|
|
8
8
|
const flattenAsyncIterable_js_1 = require("./flattenAsyncIterable.js");
|
|
9
9
|
const invariant_js_1 = require("./invariant.js");
|
|
10
10
|
const value_or_promise_1 = require("value-or-promise");
|
|
11
|
+
/**
|
|
12
|
+
* A memoized collection of relevant subfields with regard to the return
|
|
13
|
+
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
14
|
+
* saves overhead when resolving lists of values.
|
|
15
|
+
*/
|
|
16
|
+
const collectSubfields = (0, utils_1.memoize3)((exeContext, returnType, fieldNodes) => (0, utils_1.collectSubFields)(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes));
|
|
11
17
|
/**
|
|
12
18
|
* Implements the "Executing requests" section of the GraphQL specification,
|
|
13
19
|
* including `@defer` and `@stream` as proposed in
|
|
@@ -287,7 +293,7 @@ function executeField(exeContext, parentType, source, fieldNodes, path, asyncPay
|
|
|
287
293
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
288
294
|
// variables scope to fulfill any variable references.
|
|
289
295
|
// TODO: find a way to memoize, in case this field is within a List type.
|
|
290
|
-
const args = (0,
|
|
296
|
+
const args = (0, utils_1.getArgumentValues)(fieldDef, fieldNodes[0], exeContext.variableValues);
|
|
291
297
|
// The resolve function's optional third argument is a context value that
|
|
292
298
|
// is provided to every resolve function within an execution. It is commonly
|
|
293
299
|
// used to represent an authenticated user, or request-specific caches.
|
|
@@ -628,7 +634,7 @@ function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
|
628
634
|
}
|
|
629
635
|
function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result, asyncPayloadRecord) {
|
|
630
636
|
// Collect sub-fields to execute to complete this value.
|
|
631
|
-
const { fields: subFieldNodes, patches: subPatches } = (
|
|
637
|
+
const { fields: subFieldNodes, patches: subPatches } = collectSubfields(exeContext, returnType, fieldNodes);
|
|
632
638
|
const subFields = executeFields(exeContext, returnType, result, path, subFieldNodes, asyncPayloadRecord);
|
|
633
639
|
for (const subPatch of subPatches) {
|
|
634
640
|
const { label, fields: subPatchFieldNodes } = subPatch;
|
|
@@ -897,7 +903,7 @@ function executeSubscription(exeContext) {
|
|
|
897
903
|
// It differs from "ResolveFieldValue" due to providing a different `resolveFn`.
|
|
898
904
|
// Build a JS object of arguments from the field.arguments AST, using the
|
|
899
905
|
// variables scope to fulfill any variable references.
|
|
900
|
-
const args = (0,
|
|
906
|
+
const args = (0, utils_1.getArgumentValues)(fieldDef, fieldNodes[0], variableValues);
|
|
901
907
|
// The resolve function's optional third argument is a context value that
|
|
902
908
|
// is provided to every resolve function within an execution. It is commonly
|
|
903
909
|
// used to represent an authenticated user, or request-specific caches.
|
package/esm/execution/execute.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { locatedError, Kind, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, assertValidSchema, getDirectiveValues, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef,
|
|
2
|
-
import { createGraphQLError, inspect, isAsyncIterable, isIterableObject, isObjectLike, isPromise, pathToArray, addPath, promiseReduce, getDefinedRootType, mapAsyncIterator, GraphQLStreamDirective, collectFields, collectSubFields, } from '@graphql-tools/utils';
|
|
1
|
+
import { locatedError, Kind, isAbstractType, isLeafType, isListType, isNonNullType, isObjectType, assertValidSchema, getDirectiveValues, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, } from 'graphql';
|
|
2
|
+
import { createGraphQLError, inspect, isAsyncIterable, isIterableObject, isObjectLike, isPromise, pathToArray, addPath, getArgumentValues, promiseReduce, memoize3, getDefinedRootType, mapAsyncIterator, GraphQLStreamDirective, collectFields, collectSubFields as _collectSubfields, } from '@graphql-tools/utils';
|
|
3
3
|
import { getVariableValues } from './values.js';
|
|
4
4
|
import { promiseForObject } from './promiseForObject.js';
|
|
5
5
|
import { flattenAsyncIterable } from './flattenAsyncIterable.js';
|
|
6
6
|
import { invariant } from './invariant.js';
|
|
7
7
|
import { ValueOrPromise } from 'value-or-promise';
|
|
8
|
+
/**
|
|
9
|
+
* A memoized collection of relevant subfields with regard to the return
|
|
10
|
+
* type. Memoizing ensures the subfields are not repeatedly calculated, which
|
|
11
|
+
* saves overhead when resolving lists of values.
|
|
12
|
+
*/
|
|
13
|
+
const collectSubfields = memoize3((exeContext, returnType, fieldNodes) => _collectSubfields(exeContext.schema, exeContext.fragments, exeContext.variableValues, returnType, fieldNodes));
|
|
8
14
|
/**
|
|
9
15
|
* Implements the "Executing requests" section of the GraphQL specification,
|
|
10
16
|
* including `@defer` and `@stream` as proposed in
|
|
@@ -620,7 +626,7 @@ function invalidReturnTypeError(returnType, result, fieldNodes) {
|
|
|
620
626
|
}
|
|
621
627
|
function collectAndExecuteSubfields(exeContext, returnType, fieldNodes, path, result, asyncPayloadRecord) {
|
|
622
628
|
// Collect sub-fields to execute to complete this value.
|
|
623
|
-
const { fields: subFieldNodes, patches: subPatches } =
|
|
629
|
+
const { fields: subFieldNodes, patches: subPatches } = collectSubfields(exeContext, returnType, fieldNodes);
|
|
624
630
|
const subFields = executeFields(exeContext, returnType, result, path, subFieldNodes, asyncPayloadRecord);
|
|
625
631
|
for (const subPatch of subPatches) {
|
|
626
632
|
const { label, fields: subPatchFieldNodes } = subPatch;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/executor",
|
|
3
|
-
"version": "0.0.10
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@repeaterjs/repeater": "3.0.4",
|
|
10
|
-
"@graphql-tools/utils": "9.1.2
|
|
10
|
+
"@graphql-tools/utils": "9.1.2",
|
|
11
11
|
"@graphql-typed-document-node/core": "3.1.1",
|
|
12
12
|
"tslib": "^2.4.0",
|
|
13
13
|
"value-or-promise": "1.0.11"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { GraphQLError } from 'graphql';
|
|
3
|
-
import { MaybePromise } from '@graphql-tools/utils';
|
|
4
|
-
import type { Maybe, Path } from '@graphql-tools/utils';
|
|
3
|
+
import { Path, Maybe, MaybePromise } from '@graphql-tools/utils';
|
|
5
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
6
5
|
export interface SingularExecutionResult<TData = any, TExtensions = any> {
|
|
7
6
|
errors?: ReadonlyArray<GraphQLError>;
|
|
@@ -97,8 +96,8 @@ export interface FormattedIncrementalStreamResult<TData = Array<unknown>, TExten
|
|
|
97
96
|
label?: string;
|
|
98
97
|
extensions?: TExtensions;
|
|
99
98
|
}
|
|
100
|
-
export
|
|
101
|
-
export
|
|
99
|
+
export type IncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = IncrementalDeferResult<TData, TExtensions> | IncrementalStreamResult<TData, TExtensions>;
|
|
100
|
+
export type FormattedIncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = FormattedIncrementalDeferResult<TData, TExtensions> | FormattedIncrementalStreamResult<TData, TExtensions>;
|
|
102
101
|
export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
103
102
|
schema: GraphQLSchema;
|
|
104
103
|
document: TypedDocumentNode<TData, TVariables>;
|
|
@@ -275,7 +274,7 @@ declare class StreamRecord {
|
|
|
275
274
|
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
276
275
|
setIsCompletedIterator(): void;
|
|
277
276
|
}
|
|
278
|
-
|
|
277
|
+
type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
279
278
|
/**
|
|
280
279
|
* This method looks up the field on the given type definition.
|
|
281
280
|
* It has special casing for the three introspection fields,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GraphQLFormattedError, FieldNode, FragmentDefinitionNode, OperationDefinitionNode, GraphQLField, GraphQLFieldResolver, GraphQLObjectType, GraphQLResolveInfo, GraphQLTypeResolver, GraphQLSchema } from 'graphql';
|
|
2
2
|
import type { GraphQLError } from 'graphql';
|
|
3
|
-
import { MaybePromise } from '@graphql-tools/utils';
|
|
4
|
-
import type { Maybe, Path } from '@graphql-tools/utils';
|
|
3
|
+
import { Path, Maybe, MaybePromise } from '@graphql-tools/utils';
|
|
5
4
|
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
6
5
|
export interface SingularExecutionResult<TData = any, TExtensions = any> {
|
|
7
6
|
errors?: ReadonlyArray<GraphQLError>;
|
|
@@ -97,8 +96,8 @@ export interface FormattedIncrementalStreamResult<TData = Array<unknown>, TExten
|
|
|
97
96
|
label?: string;
|
|
98
97
|
extensions?: TExtensions;
|
|
99
98
|
}
|
|
100
|
-
export
|
|
101
|
-
export
|
|
99
|
+
export type IncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = IncrementalDeferResult<TData, TExtensions> | IncrementalStreamResult<TData, TExtensions>;
|
|
100
|
+
export type FormattedIncrementalResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = FormattedIncrementalDeferResult<TData, TExtensions> | FormattedIncrementalStreamResult<TData, TExtensions>;
|
|
102
101
|
export interface ExecutionArgs<TData = any, TVariables = any, TContext = any> {
|
|
103
102
|
schema: GraphQLSchema;
|
|
104
103
|
document: TypedDocumentNode<TData, TVariables>;
|
|
@@ -275,7 +274,7 @@ declare class StreamRecord {
|
|
|
275
274
|
addItems(items: MaybePromise<Array<unknown> | null>): void;
|
|
276
275
|
setIsCompletedIterator(): void;
|
|
277
276
|
}
|
|
278
|
-
|
|
277
|
+
type AsyncPayloadRecord = DeferredFragmentRecord | StreamRecord;
|
|
279
278
|
/**
|
|
280
279
|
* This method looks up the field on the given type definition.
|
|
281
280
|
* It has special casing for the three introspection fields,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type AsyncIterableOrGenerator<T> = AsyncGenerator<T, void, void> | AsyncIterable<T>;
|
|
2
2
|
/**
|
|
3
3
|
* Given an AsyncIterable of AsyncIterables, flatten all yielded results into a
|
|
4
4
|
* single AsyncIterable.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type AsyncIterableOrGenerator<T> = AsyncGenerator<T, void, void> | AsyncIterable<T>;
|
|
2
2
|
/**
|
|
3
3
|
* Given an AsyncIterable of AsyncIterables, flatten all yielded results into a
|
|
4
4
|
* single AsyncIterable.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MaybeAsyncIterable, ExecutionResult, MaybePromise } from '@graphql-tools/utils';
|
|
2
2
|
import { ExecutionArgs } from './execute.cjs';
|
|
3
3
|
export declare function normalizedExecutor<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<MaybeAsyncIterable<ExecutionResult<TData>>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MaybeAsyncIterable, ExecutionResult, MaybePromise } from '@graphql-tools/utils';
|
|
2
2
|
import { ExecutionArgs } from './execute.js';
|
|
3
3
|
export declare function normalizedExecutor<TData = any, TVariables = any, TContext = any>(args: ExecutionArgs<TData, TVariables, TContext>): MaybePromise<MaybeAsyncIterable<ExecutionResult<TData>>>;
|