Skip to content

Commit

Permalink
polish(ast): prefer undefined over empty arrays (#4206)
Browse files Browse the repository at this point in the history
see:
#2405 (comment)

Manually created ASTs always allowed undefined in place of empty arrays;
this change simply updates the parser to more closely follow the manual
approach. This is therefore not technically a breaking change, but
considering that there may be tools not aware of this, we have labelled
it a BREAKING_CHANGE to highlight it for consumers.

This closes #2203 as our tests now cover the undefined case by default
whenever there is an empty array.
  • Loading branch information
yaacovCR authored Oct 14, 2024
1 parent cdd293d commit bb8e574
Show file tree
Hide file tree
Showing 22 changed files with 184 additions and 165 deletions.
2 changes: 0 additions & 2 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,6 @@ export function validateExecutionArgs(
return [new GraphQLError('Must provide an operation.')];
}

// FIXME: https://github.com/graphql/graphql-js/issues/2203
/* c8 ignore next */
const variableDefinitions = operation.variableDefinitions ?? [];
const hideSuggestions = args.hideSuggestions ?? false;

Expand Down
2 changes: 0 additions & 2 deletions src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ export function experimentalGetArgumentValues(
): { [argument: string]: unknown } {
const coercedValues: { [argument: string]: unknown } = {};

// FIXME: https://github.com/graphql/graphql-js/issues/2203
/* c8 ignore next */
const argumentNodes = node.arguments ?? [];
const argNodeMap = new Map(argumentNodes.map((arg) => [arg.name.value, arg]));

Expand Down
26 changes: 13 additions & 13 deletions src/language/__tests__/parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ describe('Parser', () => {
loc: { start: 0, end: 40 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
variableDefinitions: undefined,
directives: undefined,
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 0, end: 40 },
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('Parser', () => {
loc: { start: 9, end: 14 },
},
],
directives: [],
directives: undefined,
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 16, end: 38 },
Expand All @@ -304,8 +304,8 @@ describe('Parser', () => {
loc: { start: 22, end: 24 },
value: 'id',
},
arguments: [],
directives: [],
arguments: undefined,
directives: undefined,
selectionSet: undefined,
},
{
Expand All @@ -317,8 +317,8 @@ describe('Parser', () => {
loc: { start: 30, end: 34 },
value: 'name',
},
arguments: [],
directives: [],
arguments: undefined,
directives: undefined,
selectionSet: undefined,
},
],
Expand Down Expand Up @@ -349,8 +349,8 @@ describe('Parser', () => {
loc: { start: 0, end: 29 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
variableDefinitions: undefined,
directives: undefined,
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 6, end: 29 },
Expand All @@ -364,8 +364,8 @@ describe('Parser', () => {
loc: { start: 10, end: 14 },
value: 'node',
},
arguments: [],
directives: [],
arguments: undefined,
directives: undefined,
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 15, end: 27 },
Expand All @@ -379,8 +379,8 @@ describe('Parser', () => {
loc: { start: 21, end: 23 },
value: 'id',
},
arguments: [],
directives: [],
arguments: undefined,
directives: undefined,
selectionSet: undefined,
},
],
Expand Down
Loading

0 comments on commit bb8e574

Please sign in to comment.