From a3f118d2bcee756eb112dc3b8abf8e6c491d2e64 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Sat, 13 Apr 2019 20:28:49 +0100 Subject: [PATCH] fix(graphql): --no-setof-functions-contain-nulls now applies to simple collections too (#441) --- .../src/plugins/makeProcField.js | 16 ++++++-- ...disabledTagsNoLegacyRelations.test.js.snap | 6 +-- ...RelationsOnlyLegacyJsonNoTags.test.js.snap | 6 +-- .../noDefaultMutations.test.js.snap | 6 +-- .../__snapshots__/pgColumnFilter.test.js.snap | 2 +- .../schema/__snapshots__/relay1.test.js.snap | 6 +-- .../simple-collections.test.js.snap | 40 +++++++++---------- 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/packages/graphile-build-pg/src/plugins/makeProcField.js b/packages/graphile-build-pg/src/plugins/makeProcField.js index 1bd26e1e2..8f993a3b7 100644 --- a/packages/graphile-build-pg/src/plugins/makeProcField.js +++ b/packages/graphile-build-pg/src/plugins/makeProcField.js @@ -64,7 +64,10 @@ export default function makeProcField( describePgEntity, sqlCommentByAddingTags, pgField, - options: { subscriptions = false }, + options: { + subscriptions = false, + pgForbidSetofFunctionsToReturnNull = false, + }, } = build; if (computed && isMutation) { @@ -184,9 +187,15 @@ export default function makeProcField( if (isTableLike) { if (proc.returnsSet) { if (isMutation) { - type = new GraphQLList(TableType); + const innerType = pgForbidSetofFunctionsToReturnNull + ? new GraphQLNonNull(TableType) + : TableType; + type = new GraphQLList(innerType); } else if (forceList) { - type = new GraphQLList(TableType); + const innerType = pgForbidSetofFunctionsToReturnNull + ? new GraphQLNonNull(TableType) + : TableType; + type = new GraphQLList(innerType); fieldScope.isPgFieldSimpleCollection = true; } else { const ConnectionType = getTypeByName( @@ -207,6 +216,7 @@ export default function makeProcField( } else { type = TableType; if (rawReturnType.isPgArray) { + // Not implementing pgForbidSetofFunctionsToReturnNull here because it's not a set type = new GraphQLList(type); } fieldScope.pgFieldIntrospectionTable = returnTypeTable; diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/disabledTagsNoLegacyRelations.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/disabledTagsNoLegacyRelations.test.js.snap index 14299a8c7..368dd8bce 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/disabledTagsNoLegacyRelations.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/disabledTagsNoLegacyRelations.test.js.snap @@ -1353,7 +1353,7 @@ type Issue756SetMutationPayload { \\"\\"\\"The method to use when ordering \`Issue756\`.\\"\\"\\" orderBy: [Issue756SOrderBy!] = [PRIMARY_KEY_ASC] ): Issue756SEdge - issue756S: [Issue756] + issue756S: [Issue756!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -2454,7 +2454,7 @@ type MutationOutTableSetofPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( @@ -3798,7 +3798,7 @@ type TableSetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/legacyRelationsOnlyLegacyJsonNoTags.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/legacyRelationsOnlyLegacyJsonNoTags.test.js.snap index d60296cee..5903858f8 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/legacyRelationsOnlyLegacyJsonNoTags.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/legacyRelationsOnlyLegacyJsonNoTags.test.js.snap @@ -1353,7 +1353,7 @@ type Issue756SetMutationPayload { \\"\\"\\"The method to use when ordering \`Issue756\`.\\"\\"\\" orderBy: [Issue756SOrderBy!] = [PRIMARY_KEY_ASC] ): Issue756SEdge - issue756S: [Issue756] + issue756S: [Issue756!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -2454,7 +2454,7 @@ type MutationOutTableSetofPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( @@ -3850,7 +3850,7 @@ type TableSetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/noDefaultMutations.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/noDefaultMutations.test.js.snap index 59c31de6b..4c9535e06 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/noDefaultMutations.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/noDefaultMutations.test.js.snap @@ -653,7 +653,7 @@ type Issue756SetMutationPayload { \\"\\"\\"The method to use when ordering \`Issue756\`.\\"\\"\\" orderBy: [Issue756SOrderBy!] = [PRIMARY_KEY_ASC] ): Issue756SEdge - issue756S: [Issue756] + issue756S: [Issue756!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -1414,7 +1414,7 @@ type MutationOutTableSetofPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( @@ -2706,7 +2706,7 @@ type TableSetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap index 3a20770a3..fd7b2e785 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap @@ -2399,7 +2399,7 @@ type PostManyPayload { \\"\\"\\"The method to use when ordering \`Post\`.\\"\\"\\" orderBy: [PostsOrderBy!] = [PRIMARY_KEY_ASC] ): PostsEdge - posts: [Post] + posts: [Post!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/relay1.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/relay1.test.js.snap index 613e72a82..809c5de96 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/relay1.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/relay1.test.js.snap @@ -1352,7 +1352,7 @@ type Issue756SetMutationPayload { \\"\\"\\"The method to use when ordering \`Issue756\`.\\"\\"\\" orderBy: [Issue756SOrderBy!] = [PRIMARY_KEY_ASC] ): Issue756SEdge - issue756S: [Issue756] + issue756S: [Issue756!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -2455,7 +2455,7 @@ type MutationOutTableSetofPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( @@ -3831,7 +3831,7 @@ type TableSetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simple-collections.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simple-collections.test.js.snap index e200800e5..4465866a7 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simple-collections.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simple-collections.test.js.snap @@ -1353,7 +1353,7 @@ type Issue756SetMutationPayload { \\"\\"\\"The method to use when ordering \`Issue756\`.\\"\\"\\" orderBy: [Issue756SOrderBy!] = [PRIMARY_KEY_ASC] ): Issue756SEdge - issue756S: [Issue756] + issue756S: [Issue756!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -2457,7 +2457,7 @@ type MutationOutTableSetofPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( @@ -2997,7 +2997,7 @@ type Person implements Node { \\"\\"\\"The method to use when ordering \`Person\`.\\"\\"\\" orderBy: [PeopleOrderBy!] - ): [Person] + ): [Person!] \\"\\"\\"The primary unique identifier for the person\\"\\"\\" id: Int! @@ -3105,7 +3105,7 @@ type Person implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Type] + ): [Type!] typeFunctionList: [Type] } @@ -3699,7 +3699,7 @@ type Query implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Person] @deprecated(reason: \\"This is deprecated (comment on function c.badly_behaved_function).\\") + ): [Person!] @deprecated(reason: \\"This is deprecated (comment on function c.badly_behaved_function).\\") \\"\\"\\"Reads a single \`CompoundKey\` using its globally unique \`ID\`.\\"\\"\\" compoundKey( @@ -3738,7 +3738,7 @@ type Query implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [CompoundType] + ): [CompoundType!] currentUserId: Int funcInInout(i: Int, ino: Int): Int funcInOut(i: Int): Int @@ -3861,7 +3861,7 @@ type Query implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Person] + ): [Person!] funcOutUnnamed: Int funcOutUnnamedOutOutUnnamed: FuncOutUnnamedOutOutUnnamedRecord funcReturnsTableMultiCol( @@ -4068,7 +4068,7 @@ type Query implements Node { \\"\\"\\"The method to use when ordering \`Person\`.\\"\\"\\" orderBy: [PeopleOrderBy!] - ): [Person] + ): [Person!] typesQuery(a: BigInt!, b: Boolean!, c: String!, d: [Int]!, e: JSON!, f: FloatRangeInput!): Boolean } @@ -4120,7 +4120,7 @@ type TableSetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\"An edge for our \`Person\`. May be used by Relay 1.\\"\\"\\" personEdge( @@ -5713,7 +5713,7 @@ type Issue756SetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - issue756S: [Issue756] + issue756S: [Issue756!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -6779,7 +6779,7 @@ type MutationOutTableSetofPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -7138,7 +7138,7 @@ type Person implements Node { \\"\\"\\"The method to use when ordering \`Person\`.\\"\\"\\" orderBy: [PeopleOrderBy!] - ): [Person] + ): [Person!] \\"\\"\\"The primary unique identifier for the person\\"\\"\\" id: Int! @@ -7167,7 +7167,7 @@ type Person implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Type] + ): [Type!] typeFunctionList: [Type] } @@ -7482,7 +7482,7 @@ type Query implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Person] @deprecated(reason: \\"This is deprecated (comment on function c.badly_behaved_function).\\") + ): [Person!] @deprecated(reason: \\"This is deprecated (comment on function c.badly_behaved_function).\\") \\"\\"\\"Reads a single \`CompoundKey\` using its globally unique \`ID\`.\\"\\"\\" compoundKey( @@ -7500,7 +7500,7 @@ type Query implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [CompoundType] + ): [CompoundType!] currentUserId: Int funcInInout(i: Int, ino: Int): Int funcInOut(i: Int): Int @@ -7542,7 +7542,7 @@ type Query implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Person] + ): [Person!] funcOutUnnamed: Int funcOutUnnamedOutOutUnnamed: FuncOutUnnamedOutOutUnnamedRecord funcReturnsTableMultiColList( @@ -7658,7 +7658,7 @@ type Query implements Node { \\"\\"\\"The method to use when ordering \`Person\`.\\"\\"\\" orderBy: [PeopleOrderBy!] - ): [Person] + ): [Person!] typesQuery(a: BigInt!, b: Boolean!, c: String!, d: [Int]!, e: JSON!, f: FloatRangeInput!): Boolean } @@ -7710,7 +7710,7 @@ type TableSetMutationPayload { unchanged and unused. May be used by a client to track mutations. \\"\\"\\" clientMutationId: String - people: [Person] + people: [Person!] \\"\\"\\" Our root query field type. Allows us to run any query from our mutation payload. @@ -8533,7 +8533,7 @@ type Person implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Pet] + ): [Pet!] \\"\\"\\"Reads and enables pagination through a set of \`Pet\`.\\"\\"\\" petsByOwnerIdList( @@ -9163,7 +9163,7 @@ type Person implements Node { \\"\\"\\"Skip the first \`n\` values.\\"\\"\\" offset: Int - ): [Pet] + ): [Pet!] \\"\\"\\"Reads and enables pagination through a set of \`Pet\`.\\"\\"\\" petsByOwnerId(