Skip to content

Commit

Permalink
Correct test and lint stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Aug 25, 2024
1 parent 1d120d0 commit 47ff0fb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
38 changes: 22 additions & 16 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { inspect } from '../../jsutils/inspect.js';

import { GraphQLError } from '../../error/GraphQLError.js';

import { DirectiveLocation } from '../../language/directiveLocation.js';
import { Kind } from '../../language/kinds.js';
import { parse } from '../../language/parser.js';

Expand All @@ -22,15 +23,15 @@ import {
GraphQLObjectType,
GraphQLScalarType,
} from '../../type/definition.js';
import {
GraphQLDirective,
GraphQLIncludeDirective,
} from '../../type/directives.js';
import { GraphQLBoolean, GraphQLString } from '../../type/scalars.js';
import { GraphQLSchema } from '../../type/schema.js';

import { executeSync } from '../execute.js';
import { executeSync, experimentalExecuteIncrementally } from '../execute.js';
import { getVariableValues } from '../values.js';
import { GraphQLSkipDirective } from '../../type/directives.js';
import { GraphQLIncludeDirective } from '../../type/directives.js';
import { GraphQLDirective } from '../../type/directives.js';
import { DirectiveLocation } from '../../language/directiveLocation.js';

const TestFaultyScalarGraphQLError = new GraphQLError(
'FaultyScalarErrorMessage',
Expand Down Expand Up @@ -1498,17 +1499,22 @@ describe('Execute: Handles inputs', () => {
});

it('when a nullable argument to a directive with a field default is not provided and shadowed by an operation variable', () => {
const result = executeQueryWithFragmentArguments(`
query($value: Boolean) {
...a
}
fragment a($value: Boolean) on TestType {
fieldWithNonNullableStringInput @skip(if: $value)
}
`);
expect(result).to.deep.equal({
data: {},
});
// this test uses the @defer directive and incremental delivery because the `if` argument for skip/include have no field defaults
const document = parse(
`
query($shouldDefer: Boolean = false) {
...a
}
fragment a($shouldDefer: Boolean) on TestType {
... @defer(if: $shouldDefer) {
fieldWithDefaultArgumentValue
}
}
`,
{ experimentalFragmentArguments: true },
);
const result = experimentalExecuteIncrementally({ schema, document });
expect(result).to.include.keys('initialResult', 'subsequentResults');
});
});
});
40 changes: 34 additions & 6 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ function collectFieldsImpl(
for (const selection of selectionSet.selections) {
switch (selection.kind) {
case Kind.FIELD: {
const vars = localVariableValues ?? variableValues;
if (!shouldIncludeNode(vars, selection)) {
if (
!shouldIncludeNode(
variableValues,
selection,
context.localVariableValues,
)
) {
continue;
}
groupedFieldSet.add(getFieldEntryKey(selection), {
Expand All @@ -177,7 +182,11 @@ function collectFieldsImpl(
}
case Kind.INLINE_FRAGMENT: {
if (
!shouldIncludeNode(variableValues, selection) ||
!shouldIncludeNode(
variableValues,
selection,
context.localVariableValues,
) ||
!doesFragmentConditionMatch(schema, selection, runtimeType)
) {
continue;
Expand All @@ -188,6 +197,7 @@ function collectFieldsImpl(
variableValues,
selection,
deferUsage,
context.localVariableValues,
);

if (!newDeferUsage) {
Expand Down Expand Up @@ -219,12 +229,17 @@ function collectFieldsImpl(
variableValues,
selection,
deferUsage,
context.localVariableValues,
);

if (
!newDeferUsage &&
(visitedFragmentNames.has(fragmentName) ||
!shouldIncludeNode(variableValues, selection))
!shouldIncludeNode(
variableValues,
selection,
context.localVariableValues,
))
) {
continue;
}
Expand Down Expand Up @@ -291,8 +306,14 @@ function getDeferUsage(
variableValues: { [variable: string]: unknown },
node: FragmentSpreadNode | InlineFragmentNode,
parentDeferUsage: DeferUsage | undefined,
fragmentVariableValues: { [variable: string]: unknown } | undefined,
): DeferUsage | undefined {
const defer = getDirectiveValues(GraphQLDeferDirective, node, variableValues);
const defer = getDirectiveValues(
GraphQLDeferDirective,
node,
variableValues,
fragmentVariableValues,
);

if (!defer) {
return;
Expand Down Expand Up @@ -320,8 +341,14 @@ function getDeferUsage(
function shouldIncludeNode(
variableValues: { [variable: string]: unknown },
node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
fragmentVariableValues: { [variable: string]: unknown } | undefined,
): boolean {
const skip = getDirectiveValues(GraphQLSkipDirective, node, variableValues);
const skip = getDirectiveValues(
GraphQLSkipDirective,
node,
variableValues,
fragmentVariableValues,
);
if (skip?.if === true) {
return false;
}
Expand All @@ -330,6 +357,7 @@ function shouldIncludeNode(
GraphQLIncludeDirective,
node,
variableValues,
fragmentVariableValues,
);
if (include?.if === false) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ function getStreamUsage(
const stream = getDirectiveValues(
GraphQLStreamDirective,
fieldGroup[0].node,
fieldGroup[0].fragmentVariableValues ?? exeContext.variableValues,
exeContext.variableValues,
fieldGroup[0].fragmentVariableValues,
);

if (!stream) {
Expand Down
8 changes: 7 additions & 1 deletion src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,18 @@ export function getDirectiveValues(
directiveDef: GraphQLDirective,
node: { readonly directives?: ReadonlyArray<DirectiveNode> | undefined },
variableValues?: Maybe<ObjMap<unknown>>,
fragmentVariables?: Maybe<ObjMap<unknown>>,
): undefined | { [argument: string]: unknown } {
const directiveNode = node.directives?.find(
(directive) => directive.name.value === directiveDef.name,
);

if (directiveNode) {
return getArgumentValues(directiveNode, directiveDef.args, variableValues);
return getArgumentValues(
directiveNode,
directiveDef.args,
variableValues,
fragmentVariables,
);
}
}

0 comments on commit 47ff0fb

Please sign in to comment.