From 672a74330521f1fb973a826c905a869ff9689ae8 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Fri, 14 Jan 2022 16:43:51 +0200 Subject: [PATCH] use enableIncremental instead of disableIncremental (#133) --- .changeset/new-pianos-lie.md | 9 +++++++++ src/execution/__tests__/defer-test.ts | 10 +++++----- src/execution/__tests__/stream-test.ts | 10 +++++----- src/execution/executor.ts | 26 +++++++++++++------------- 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 .changeset/new-pianos-lie.md diff --git a/.changeset/new-pianos-lie.md b/.changeset/new-pianos-lie.md new file mode 100644 index 0000000000..d7f509024d --- /dev/null +++ b/.changeset/new-pianos-lie.md @@ -0,0 +1,9 @@ +--- +'graphql-executor': patch +--- + +use enableIncremental instead of disableIncremental + +with default of true rather than of false. + +enable-type option flags may be easier to reason about. diff --git a/src/execution/__tests__/defer-test.ts b/src/execution/__tests__/defer-test.ts index e5365c6d17..501b05487d 100644 --- a/src/execution/__tests__/defer-test.ts +++ b/src/execution/__tests__/defer-test.ts @@ -84,12 +84,12 @@ const query = new GraphQLObjectType({ async function complete( document: DocumentNode, - opts?: { enableDeferStream?: boolean }, + opts?: { enableIncremental?: boolean }, ) { - const enableDeferStream = opts?.enableDeferStream ?? true; + const enableIncremental = opts?.enableIncremental ?? true; const schema = new GraphQLSchema({ query, - directives: enableDeferStream + directives: enableIncremental ? [...specifiedDirectives, GraphQLDeferDirective, GraphQLStreamDirective] : [...specifiedDirectives], }); @@ -98,7 +98,7 @@ async function complete( schema, document, rootValue: {}, - disableIncremental: !enableDeferStream, + enableIncremental, }); if (isAsyncIterable(result)) { @@ -125,7 +125,7 @@ describe('Execute: defer directive', () => { name } `); - const result = await complete(document, { enableDeferStream: false }); + const result = await complete(document, { enableIncremental: false }); expectJSON(result).toDeepEqual({ data: { diff --git a/src/execution/__tests__/stream-test.ts b/src/execution/__tests__/stream-test.ts index 042099dc59..a41a5f296e 100644 --- a/src/execution/__tests__/stream-test.ts +++ b/src/execution/__tests__/stream-test.ts @@ -182,12 +182,12 @@ const query = new GraphQLObjectType({ async function complete( document: DocumentNode, rootValue: unknown = {}, - opts?: { enableDeferStream?: boolean }, + opts?: { enableIncremental?: boolean }, ) { - const enableDeferStream = opts?.enableDeferStream ?? true; + const enableIncremental = opts?.enableIncremental ?? true; const schema = new GraphQLSchema({ query, - directives: enableDeferStream + directives: enableIncremental ? [...specifiedDirectives, GraphQLDeferDirective, GraphQLStreamDirective] : [...specifiedDirectives], }); @@ -195,7 +195,7 @@ async function complete( schema, document, rootValue, - disableIncremental: !enableDeferStream, + enableIncremental, }); if (isAsyncIterable(result)) { @@ -234,7 +234,7 @@ async function completeAsync(document: DocumentNode, numCalls: number) { describe('Execute: stream directive', () => { it('Should ignore @stream if not enabled', async () => { const document = parse('{ scalarList @stream(initialCount: 1) }'); - const result = await complete(document, {}, { enableDeferStream: false }); + const result = await complete(document, {}, { enableIncremental: false }); expectJSON(result).toDeepEqual({ data: { diff --git a/src/execution/executor.ts b/src/execution/executor.ts index bdcc0cabbe..0344ae8311 100644 --- a/src/execution/executor.ts +++ b/src/execution/executor.ts @@ -95,7 +95,7 @@ interface ExecutionContext { fieldResolver: GraphQLFieldResolver; typeResolver: GraphQLTypeResolver; forceQueryAlgorithm: boolean; - disableIncremental: boolean; + enableIncremental: boolean; resolveField: FieldResolver; rootPayloadContext: PayloadContext; iterators: Set>; @@ -136,7 +136,7 @@ export interface ExecutorExecutionArgs { typeResolver?: Maybe>; subscribeFieldResolver?: Maybe>; forceQueryAlgorithm?: Maybe; - disableIncremental?: Maybe; + enableIncremental?: Maybe; } /** @@ -223,14 +223,14 @@ export class Executor { returnType: GraphQLObjectType, fieldNodes: ReadonlyArray, ) => { - const { fragments, variableValues, disableIncremental } = exeContext; + const { fragments, variableValues, enableIncremental } = exeContext; return _collectSubfields( this._executorSchema, fragments, variableValues, returnType, fieldNodes, - disableIncremental, + !enableIncremental, ); }, ); @@ -537,7 +537,7 @@ export class Executor { typeResolver, subscribeFieldResolver, forceQueryAlgorithm, - disableIncremental, + enableIncremental, } = args; // If arguments are missing or incorrectly typed, this is an internal @@ -604,7 +604,7 @@ export class Executor { fieldResolver: defaultResolveFieldValueFn, typeResolver: typeResolver ?? defaultTypeResolver, forceQueryAlgorithm: forceQueryAlgorithm ?? false, - disableIncremental: disableIncremental ?? false, + enableIncremental: enableIncremental ?? true, resolveField: operation.operation === 'subscription' && !forceQueryAlgorithm ? this.buildFieldResolver( @@ -662,7 +662,7 @@ export class Executor { rootValue, operation, variableValues, - disableIncremental, + enableIncremental, rootPayloadContext, } = exeContext; @@ -673,7 +673,7 @@ export class Executor { fragments, variableValues, operation, - disableIncremental, + enableIncremental, ); const path = undefined; @@ -702,7 +702,7 @@ export class Executor { fragments: ObjMap, variableValues: { [variable: string]: unknown }, operation: OperationDefinitionNode, - disableIncremental: boolean, + enableIncremental: boolean, ): { rootType: GraphQLObjectType; fieldsAndPatches: FieldsAndPatches; @@ -721,7 +721,7 @@ export class Executor { variableValues, rootType, operation.selectionSet, - disableIncremental, + !enableIncremental, ); return { @@ -1125,7 +1125,7 @@ export class Executor { initialCount?: number; label?: string; } { - if (exeContext.disableIncremental) { + if (!exeContext.enableIncremental) { return; } // validation only allows equivalent streams on multiple fields, so it is @@ -1728,7 +1728,7 @@ export class Executor { rootValue, operation, variableValues, - disableIncremental, + enableIncremental, } = exeContext; const { @@ -1738,7 +1738,7 @@ export class Executor { fragments, variableValues, operation, - disableIncremental, + enableIncremental, ); const [responseName, fieldNodes] = [...fields.entries()][0];