Skip to content

Commit c8d6d6c

Browse files
committed
polish(ast): prefer undefined over empty arrays (graphql#4206)
see: graphql#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 graphql#2203 as our tests now cover the undefined case by default whenever there is an empty array.
1 parent 2283916 commit c8d6d6c

21 files changed

+194
-174
lines changed

src/execution/execute.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ export function validateExecutionArgs(
388388
return [new GraphQLError('Must provide an operation.')];
389389
}
390390

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

src/execution/values.ts

Lines changed: 0 additions & 2 deletions
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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ describe('Parser', () => {
271271
loc: { start: 0, end: 40 },
272272
operation: 'query',
273273
name: undefined,
274-
variableDefinitions: [],
275-
directives: [],
274+
variableDefinitions: undefined,
275+
directives: undefined,
276276
selectionSet: {
277277
kind: Kind.SELECTION_SET,
278278
loc: { start: 0, end: 40 },
@@ -302,7 +302,7 @@ describe('Parser', () => {
302302
loc: { start: 9, end: 14 },
303303
},
304304
],
305-
directives: [],
305+
directives: undefined,
306306
selectionSet: {
307307
kind: Kind.SELECTION_SET,
308308
loc: { start: 16, end: 38 },
@@ -316,8 +316,8 @@ describe('Parser', () => {
316316
loc: { start: 22, end: 24 },
317317
value: 'id',
318318
},
319-
arguments: [],
320-
directives: [],
319+
arguments: undefined,
320+
directives: undefined,
321321
selectionSet: undefined,
322322
},
323323
{
@@ -329,8 +329,8 @@ describe('Parser', () => {
329329
loc: { start: 30, end: 34 },
330330
value: 'name',
331331
},
332-
arguments: [],
333-
directives: [],
332+
arguments: undefined,
333+
directives: undefined,
334334
selectionSet: undefined,
335335
},
336336
],
@@ -362,8 +362,8 @@ describe('Parser', () => {
362362
description: undefined,
363363
operation: 'query',
364364
name: undefined,
365-
variableDefinitions: [],
366-
directives: [],
365+
variableDefinitions: undefined,
366+
directives: undefined,
367367
selectionSet: {
368368
kind: Kind.SELECTION_SET,
369369
loc: { start: 6, end: 29 },
@@ -377,8 +377,8 @@ describe('Parser', () => {
377377
loc: { start: 10, end: 14 },
378378
value: 'node',
379379
},
380-
arguments: [],
381-
directives: [],
380+
arguments: undefined,
381+
directives: undefined,
382382
selectionSet: {
383383
kind: Kind.SELECTION_SET,
384384
loc: { start: 15, end: 27 },
@@ -392,8 +392,8 @@ describe('Parser', () => {
392392
loc: { start: 21, end: 23 },
393393
value: 'id',
394394
},
395-
arguments: [],
396-
directives: [],
395+
arguments: undefined,
396+
directives: undefined,
397397
selectionSet: undefined,
398398
},
399399
],
@@ -431,8 +431,8 @@ describe('Parser', () => {
431431
},
432432
operation: 'query',
433433
name: undefined,
434-
variableDefinitions: [],
435-
directives: [],
434+
variableDefinitions: undefined,
435+
directives: undefined,
436436
selectionSet: {
437437
kind: Kind.SELECTION_SET,
438438
loc: { start: 20, end: 43 },
@@ -446,8 +446,8 @@ describe('Parser', () => {
446446
loc: { start: 24, end: 28 },
447447
value: 'node',
448448
},
449-
arguments: [],
450-
directives: [],
449+
arguments: undefined,
450+
directives: undefined,
451451
selectionSet: {
452452
kind: Kind.SELECTION_SET,
453453
loc: { start: 29, end: 41 },
@@ -461,8 +461,8 @@ describe('Parser', () => {
461461
loc: { start: 35, end: 37 },
462462
value: 'id',
463463
},
464-
arguments: [],
465-
directives: [],
464+
arguments: undefined,
465+
directives: undefined,
466466
selectionSet: undefined,
467467
},
468468
],
@@ -995,7 +995,7 @@ describe('Parser', () => {
995995
loc: { start: 72, end: 75 },
996996
},
997997
defaultValue: undefined,
998-
directives: [],
998+
directives: undefined,
999999
loc: { start: 41, end: 75 },
10001000
},
10011001
{
@@ -1025,11 +1025,11 @@ describe('Parser', () => {
10251025
loc: { start: 124, end: 130 },
10261026
},
10271027
defaultValue: undefined,
1028-
directives: [],
1028+
directives: undefined,
10291029
loc: { start: 79, end: 130 },
10301030
},
10311031
],
1032-
directives: [],
1032+
directives: undefined,
10331033
selectionSet: {
10341034
kind: Kind.SELECTION_SET,
10351035
selections: [
@@ -1079,7 +1079,7 @@ describe('Parser', () => {
10791079
loc: { start: 150, end: 155 },
10801080
},
10811081
],
1082-
directives: [],
1082+
directives: undefined,
10831083
selectionSet: undefined,
10841084
loc: { start: 137, end: 156 },
10851085
},
@@ -1123,7 +1123,7 @@ describe('Parser', () => {
11231123
},
11241124
directives: [
11251125
{
1126-
arguments: [],
1126+
arguments: undefined,
11271127
kind: Kind.DIRECTIVE,
11281128
name: {
11291129
kind: Kind.NAME,
@@ -1201,7 +1201,7 @@ describe('Parser', () => {
12011201
loc: { start: 26, end: 29 },
12021202
},
12031203
defaultValue: undefined,
1204-
directives: [],
1204+
directives: undefined,
12051205
loc: { start: 13, end: 29 },
12061206
});
12071207
});

0 commit comments

Comments
 (0)