Skip to content

Commit

Permalink
use enableIncremental instead of disableIncremental (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR authored Jan 14, 2022
1 parent 6b97308 commit 672a743
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
9 changes: 9 additions & 0 deletions .changeset/new-pianos-lie.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
Expand All @@ -98,7 +98,7 @@ async function complete(
schema,
document,
rootValue: {},
disableIncremental: !enableDeferStream,
enableIncremental,
});

if (isAsyncIterable(result)) {
Expand All @@ -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: {
Expand Down
10 changes: 5 additions & 5 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,20 @@ 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],
});
const result = await execute({
schema,
document,
rootValue,
disableIncremental: !enableDeferStream,
enableIncremental,
});

if (isAsyncIterable(result)) {
Expand Down Expand Up @@ -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: {
Expand Down
26 changes: 13 additions & 13 deletions src/execution/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ interface ExecutionContext {
fieldResolver: GraphQLFieldResolver<any, any>;
typeResolver: GraphQLTypeResolver<any, any>;
forceQueryAlgorithm: boolean;
disableIncremental: boolean;
enableIncremental: boolean;
resolveField: FieldResolver;
rootPayloadContext: PayloadContext;
iterators: Set<AsyncIterator<unknown>>;
Expand Down Expand Up @@ -136,7 +136,7 @@ export interface ExecutorExecutionArgs {
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
forceQueryAlgorithm?: Maybe<boolean>;
disableIncremental?: Maybe<boolean>;
enableIncremental?: Maybe<boolean>;
}

/**
Expand Down Expand Up @@ -223,14 +223,14 @@ export class Executor {
returnType: GraphQLObjectType,
fieldNodes: ReadonlyArray<FieldNode>,
) => {
const { fragments, variableValues, disableIncremental } = exeContext;
const { fragments, variableValues, enableIncremental } = exeContext;
return _collectSubfields(
this._executorSchema,
fragments,
variableValues,
returnType,
fieldNodes,
disableIncremental,
!enableIncremental,
);
},
);
Expand Down Expand Up @@ -537,7 +537,7 @@ export class Executor {
typeResolver,
subscribeFieldResolver,
forceQueryAlgorithm,
disableIncremental,
enableIncremental,
} = args;

// If arguments are missing or incorrectly typed, this is an internal
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -662,7 +662,7 @@ export class Executor {
rootValue,
operation,
variableValues,
disableIncremental,
enableIncremental,
rootPayloadContext,
} = exeContext;

Expand All @@ -673,7 +673,7 @@ export class Executor {
fragments,
variableValues,
operation,
disableIncremental,
enableIncremental,
);
const path = undefined;

Expand Down Expand Up @@ -702,7 +702,7 @@ export class Executor {
fragments: ObjMap<FragmentDefinitionNode>,
variableValues: { [variable: string]: unknown },
operation: OperationDefinitionNode,
disableIncremental: boolean,
enableIncremental: boolean,
): {
rootType: GraphQLObjectType;
fieldsAndPatches: FieldsAndPatches;
Expand All @@ -721,7 +721,7 @@ export class Executor {
variableValues,
rootType,
operation.selectionSet,
disableIncremental,
!enableIncremental,
);

return {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1728,7 +1728,7 @@ export class Executor {
rootValue,
operation,
variableValues,
disableIncremental,
enableIncremental,
} = exeContext;

const {
Expand All @@ -1738,7 +1738,7 @@ export class Executor {
fragments,
variableValues,
operation,
disableIncremental,
enableIncremental,
);

const [responseName, fieldNodes] = [...fields.entries()][0];
Expand Down

0 comments on commit 672a743

Please sign in to comment.