Skip to content

Commit

Permalink
Change many-relationship graphQL type to [Item!]! (#3261)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Jul 21, 2020
1 parent 39ed515 commit c3883e0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .changeset/wet-masks-sort.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 1 addition & 3 deletions packages/fields/src/types/Relationship/Implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` : '',
];
}
Expand Down Expand Up @@ -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`];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
},
},
},
Expand Down Expand Up @@ -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',
},
},
},
},
},
Expand Down

0 comments on commit c3883e0

Please sign in to comment.