From c3883e01c01b83cf5938de9bebf2dd68f4861364 Mon Sep 17 00:00:00 2001 From: Tim Leslie Date: Tue, 21 Jul 2020 12:01:59 +1000 Subject: [PATCH] Change many-relationship graphQL type to [Item!]! (#3261) --- .changeset/wet-masks-sort.md | 9 +++++++ .../src/types/Relationship/Implementation.js | 4 +--- .../Relationship/tests/implementation.test.js | 24 ++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 .changeset/wet-masks-sort.md diff --git a/.changeset/wet-masks-sort.md b/.changeset/wet-masks-sort.md new file mode 100644 index 00000000000..d4996c4e650 --- /dev/null +++ b/.changeset/wet-masks-sort.md @@ -0,0 +1,9 @@ +--- +'@keystonejs/fields': major +--- + +`many` relationships now have a GraphQL type of `[Item!]!`, rather than `[Item]`. + +The old type of `[Item]` implied that the relationship field could return `null`, or that some of the items it returned could be `null`. In practice, neither of these things ever happened. The new type better reflects this reality. + +The filter argument `{path}_is_null` has also been removed for `many` relationships, as it does not apply to a non-null array type. diff --git a/packages/fields/src/types/Relationship/Implementation.js b/packages/fields/src/types/Relationship/Implementation.js index 43c6a9fb6f2..2ebd7cc482f 100644 --- a/packages/fields/src/types/Relationship/Implementation.js +++ b/packages/fields/src/types/Relationship/Implementation.js @@ -60,7 +60,7 @@ export class Relationship extends Implementation { if (this.many) { const filterArgs = refList.getGraphqlFilterFragment().join('\n'); return [ - `${this.path}(${filterArgs}): [${refList.gqlNames.outputTypeName}]`, + `${this.path}(${filterArgs}): [${refList.gqlNames.outputTypeName}!]!`, this.withMeta ? `_${this.path}Meta(${filterArgs}): _QueryMeta` : '', ]; } @@ -89,8 +89,6 @@ export class Relationship extends Implementation { ${this.path}_some: ${refList.gqlNames.whereInputName}`, `""" condition must be false for all nodes """ ${this.path}_none: ${refList.gqlNames.whereInputName}`, - `""" is the relation field null """ - ${this.path}_is_null: Boolean`, ]; } else { return [`${this.path}: ${refList.gqlNames.whereInputName}`, `${this.path}_is_null: Boolean`]; diff --git a/packages/fields/src/types/Relationship/tests/implementation.test.js b/packages/fields/src/types/Relationship/tests/implementation.test.js index 8b81b39e503..868c13ce4c0 100644 --- a/packages/fields/src/types/Relationship/tests/implementation.test.js +++ b/packages/fields/src/types/Relationship/tests/implementation.test.js @@ -296,10 +296,16 @@ describe('Type Generation', () => { }, arguments: mockFilterAST, type: { - kind: 'ListType', + kind: 'NonNullType', type: { - name: { - value: 'Zip', + kind: 'ListType', + type: { + kind: 'NonNullType', + type: { + name: { + value: 'Zip', + }, + }, }, }, }, @@ -354,10 +360,16 @@ describe('Type Generation', () => { }, arguments: mockFilterAST, type: { - kind: 'ListType', + kind: 'NonNullType', type: { - name: { - value: 'Zip', + kind: 'ListType', + type: { + kind: 'NonNullType', + type: { + name: { + value: 'Zip', + }, + }, }, }, },