Skip to content

Commit bb8e574

Browse files
authored
polish(ast): prefer undefined over empty arrays (#4206)
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.
1 parent cdd293d commit bb8e574

22 files changed

+184
-165
lines changed

src/execution/execute.ts

-2
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ export function validateExecutionArgs(
561561
return [new GraphQLError('Must provide an operation.')];
562562
}
563563

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

src/execution/values.ts

-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ export function experimentalGetArgumentValues(
224224
): { [argument: string]: unknown } {
225225
const coercedValues: { [argument: string]: unknown } = {};
226226

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

src/language/__tests__/parser-test.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ describe('Parser', () => {
259259
loc: { start: 0, end: 40 },
260260
operation: 'query',
261261
name: undefined,
262-
variableDefinitions: [],
263-
directives: [],
262+
variableDefinitions: undefined,
263+
directives: undefined,
264264
selectionSet: {
265265
kind: Kind.SELECTION_SET,
266266
loc: { start: 0, end: 40 },
@@ -290,7 +290,7 @@ describe('Parser', () => {
290290
loc: { start: 9, end: 14 },
291291
},
292292
],
293-
directives: [],
293+
directives: undefined,
294294
selectionSet: {
295295
kind: Kind.SELECTION_SET,
296296
loc: { start: 16, end: 38 },
@@ -304,8 +304,8 @@ describe('Parser', () => {
304304
loc: { start: 22, end: 24 },
305305
value: 'id',
306306
},
307-
arguments: [],
308-
directives: [],
307+
arguments: undefined,
308+
directives: undefined,
309309
selectionSet: undefined,
310310
},
311311
{
@@ -317,8 +317,8 @@ describe('Parser', () => {
317317
loc: { start: 30, end: 34 },
318318
value: 'name',
319319
},
320-
arguments: [],
321-
directives: [],
320+
arguments: undefined,
321+
directives: undefined,
322322
selectionSet: undefined,
323323
},
324324
],
@@ -349,8 +349,8 @@ describe('Parser', () => {
349349
loc: { start: 0, end: 29 },
350350
operation: 'query',
351351
name: undefined,
352-
variableDefinitions: [],
353-
directives: [],
352+
variableDefinitions: undefined,
353+
directives: undefined,
354354
selectionSet: {
355355
kind: Kind.SELECTION_SET,
356356
loc: { start: 6, end: 29 },
@@ -364,8 +364,8 @@ describe('Parser', () => {
364364
loc: { start: 10, end: 14 },
365365
value: 'node',
366366
},
367-
arguments: [],
368-
directives: [],
367+
arguments: undefined,
368+
directives: undefined,
369369
selectionSet: {
370370
kind: Kind.SELECTION_SET,
371371
loc: { start: 15, end: 27 },
@@ -379,8 +379,8 @@ describe('Parser', () => {
379379
loc: { start: 21, end: 23 },
380380
value: 'id',
381381
},
382-
arguments: [],
383-
directives: [],
382+
arguments: undefined,
383+
directives: undefined,
384384
selectionSet: undefined,
385385
},
386386
],

0 commit comments

Comments
 (0)