Skip to content

Commit

Permalink
fix(graphql): root level custom query connection fields now nullable (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Sep 8, 2020
1 parent 9265262 commit 131c6ac
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 195 deletions.
Expand Up @@ -3,7 +3,7 @@ import type { Plugin } from "graphile-build";

export default (function PgQueryProceduresPlugin(
builder,
{ pgSimpleCollections }
{ pgSimpleCollections, disableIssue641Fix = false }
) {
builder.hook(
"GraphQLObjectType:fields",
Expand Down Expand Up @@ -76,6 +76,7 @@ export default (function PgQueryProceduresPlugin(
[fieldName]: makeProcField(fieldName, proc, build, {
fieldWithHooks,
forceList,
isRootQuery: !disableIssue641Fix,
}),
},
`Adding query field for ${describePgEntity(
Expand Down
15 changes: 11 additions & 4 deletions packages/graphile-build-pg/src/plugins/makeProcField.js
Expand Up @@ -26,11 +26,13 @@ export default function makeProcField(
fieldWithHooks,
computed = false,
isMutation = false,
isRootQuery = false,
forceList = false,
}: {
fieldWithHooks: FieldWithHooksFunction,
computed?: boolean,
isMutation?: boolean,
isRootQuery?: boolean,
forceList?: boolean,
}
) {
Expand Down Expand Up @@ -209,7 +211,7 @@ export default function makeProcField(
)}' for '${TableType.name}' so cannot create procedure field`
);
}
type = new GraphQLNonNull(ConnectionType);
type = ConnectionType;
fieldScope.isPgFieldConnection = true;
}
fieldScope.pgFieldIntrospectionTable = returnTypeTable;
Expand Down Expand Up @@ -249,7 +251,7 @@ export default function makeProcField(
)}' for '${RecordType.name}' so cannot create procedure field`
);
}
type = new GraphQLNonNull(ConnectionType);
type = ConnectionType;
fieldScope.isPgFieldConnection = true;
}
} else {
Expand All @@ -275,7 +277,7 @@ export default function makeProcField(
returnFirstValueAsValue = true;
fieldScope.isPgFieldSimpleCollection = true;
} else {
type = new GraphQLNonNull(ConnectionType);
type = ConnectionType;
fieldScope.isPgFieldConnection = true;
// We don't return the first value as the value here because it gets
// sent down into PgScalarFunctionConnectionPlugin so the relevant
Expand Down Expand Up @@ -584,7 +586,12 @@ export default function makeProcField(
: isTableLike && proc.returnsSet
? `Reads and enables pagination through a set of \`${TableType.name}\`.`
: null,
type: nullableIf(GraphQLNonNull, !proc.tags.notNull, ReturnType),
type: nullableIf(
GraphQLNonNull,
!proc.tags.notNull &&
(!fieldScope.isPgFieldConnection || isMutation || isRootQuery),
ReturnType
),
args: args,
resolve: computed
? (data, _args, resolveContext, resolveInfo) => {
Expand Down
Expand Up @@ -7237,7 +7237,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): PeopleConnection! @deprecated(reason: "This is deprecated (comment on function c.badly_behaved_function).")
): PeopleConnection @deprecated(reason: "This is deprecated (comment on function c.badly_behaved_function).")

"""Reads a single \`CompoundKey\` using its globally unique \`ID\`."""
compoundKey(
Expand Down Expand Up @@ -7269,7 +7269,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): CompoundTypesConnection!
): CompoundTypesConnection
currentUserId: Int

"""Reads a single \`DefaultValue\` using its globally unique \`ID\`."""
Expand Down Expand Up @@ -7305,7 +7305,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncOutComplexSetofConnection!
): FuncOutComplexSetofConnection
funcOutOut: FuncOutOutRecord
funcOutOutCompoundType(i1: Int): FuncOutOutCompoundTypeRecord
funcOutOutSetof(
Expand All @@ -7326,7 +7326,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncOutOutSetofConnection!
): FuncOutOutSetofConnection
funcOutOutUnnamed: FuncOutOutUnnamedRecord
funcOutSetof(
"""Read all values in the set after (below) this cursor."""
Expand All @@ -7346,7 +7346,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncOutSetofConnection!
): FuncOutSetofConnection
funcOutTable: Person

"""Reads and enables pagination through a set of \`Person\`."""
Expand All @@ -7368,7 +7368,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): PeopleConnection!
): PeopleConnection
funcOutUnnamed: Int
funcOutUnnamedOutOutUnnamed: FuncOutUnnamedOutOutUnnamedRecord
funcReturnsTableMultiCol(
Expand All @@ -7390,7 +7390,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncReturnsTableMultiColConnection!
): FuncReturnsTableMultiColConnection
funcReturnsTableOneCol(
"""Read all values in the set after (below) this cursor."""
after: Cursor
Expand All @@ -7410,7 +7410,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncReturnsTableOneColConnection!
): FuncReturnsTableOneColConnection

"""Reads a single \`Input\` using its globally unique \`ID\`."""
input(
Expand Down Expand Up @@ -7439,7 +7439,7 @@ type Query implements Node {
x: Int
y: Int
z: Int
): IntSetQueryConnection!
): IntSetQueryConnection

"""Reads a single \`Issue756\` using its globally unique \`ID\`."""
issue756(
Expand Down Expand Up @@ -7548,7 +7548,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): QueryIntervalSetConnection!
): QueryIntervalSetConnection
queryOutputTwoRows(leftArmId: Int, postId: Int, txt: String): QueryOutputTwoRowsRecord
queryTextArray: [String]

Expand Down Expand Up @@ -7613,7 +7613,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): StaticBigIntegerConnection!
): StaticBigIntegerConnection
tableQuery(id: Int): Post

"""Reads and enables pagination through a set of \`Person\`."""
Expand Down Expand Up @@ -7643,7 +7643,7 @@ type Query implements Node {

"""The method to use when ordering \`Person\`."""
orderBy: [PeopleOrderBy!]
): PeopleConnection!
): PeopleConnection

"""Reads and enables pagination through a set of \`Person\`."""
tableSetQueryPlpgsql(
Expand All @@ -7664,7 +7664,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): PeopleConnection!
): PeopleConnection

"""Reads a single \`Type\` using its globally unique \`ID\`."""
type(
Expand Down Expand Up @@ -7693,7 +7693,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): TypesConnection!
): TypesConnection
typeFunctionList: [Type]
typesQuery(a: BigInt!, b: Boolean!, c: String!, d: [Int]!, e: JSON!, f: FloatRangeInput!): Boolean
uniqueForeignKeyByCompoundKey1AndCompoundKey2(compoundKey1: Int!, compoundKey2: Int!): UniqueForeignKey
Expand Down Expand Up @@ -17317,7 +17317,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): PeopleConnection! @deprecated(reason: "This is deprecated (comment on function c.badly_behaved_function).")
): PeopleConnection @deprecated(reason: "This is deprecated (comment on function c.badly_behaved_function).")

"""Reads a single \`CompoundKey\` using its globally unique \`ID\`."""
compoundKey(
Expand Down Expand Up @@ -17349,7 +17349,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): CompoundTypesConnection!
): CompoundTypesConnection
currentUserId: Int

"""Reads a single \`DefaultValue\` using its globally unique \`ID\`."""
Expand Down Expand Up @@ -17385,7 +17385,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncOutComplexSetofConnection!
): FuncOutComplexSetofConnection
funcOutOut: FuncOutOutRecord
funcOutOutCompoundType(i1: Int): FuncOutOutCompoundTypeRecord
funcOutOutSetof(
Expand All @@ -17406,7 +17406,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncOutOutSetofConnection!
): FuncOutOutSetofConnection
funcOutOutUnnamed: FuncOutOutUnnamedRecord
funcOutSetof(
"""Read all values in the set after (below) this cursor."""
Expand All @@ -17426,7 +17426,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncOutSetofConnection!
): FuncOutSetofConnection
funcOutTable: Person

"""Reads and enables pagination through a set of \`Person\`."""
Expand All @@ -17448,7 +17448,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): PeopleConnection!
): PeopleConnection
funcOutUnnamed: Int
funcOutUnnamedOutOutUnnamed: FuncOutUnnamedOutOutUnnamedRecord
funcReturnsTableMultiCol(
Expand All @@ -17470,7 +17470,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncReturnsTableMultiColConnection!
): FuncReturnsTableMultiColConnection
funcReturnsTableOneCol(
"""Read all values in the set after (below) this cursor."""
after: Cursor
Expand All @@ -17490,7 +17490,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): FuncReturnsTableOneColConnection!
): FuncReturnsTableOneColConnection

"""Reads a single \`Input\` using its globally unique \`ID\`."""
input(
Expand Down Expand Up @@ -17519,7 +17519,7 @@ type Query implements Node {
x: Int
y: Int
z: Int
): IntSetQueryConnection!
): IntSetQueryConnection

"""Reads a single \`Issue756\` using its globally unique \`ID\`."""
issue756(
Expand Down Expand Up @@ -17628,7 +17628,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): QueryIntervalSetConnection!
): QueryIntervalSetConnection
queryOutputTwoRows(leftArmId: Int, postId: Int, txt: String): QueryOutputTwoRowsRecord
queryTextArray: [String]

Expand Down Expand Up @@ -17693,7 +17693,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): StaticBigIntegerConnection!
): StaticBigIntegerConnection
tableQuery(id: Int): Post

"""Reads and enables pagination through a set of \`Person\`."""
Expand Down Expand Up @@ -17723,7 +17723,7 @@ type Query implements Node {

"""The method to use when ordering \`Person\`."""
orderBy: [PeopleOrderBy!]
): PeopleConnection!
): PeopleConnection

"""Reads and enables pagination through a set of \`Person\`."""
tableSetQueryPlpgsql(
Expand All @@ -17744,7 +17744,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): PeopleConnection!
): PeopleConnection

"""Reads a single \`Type\` using its globally unique \`ID\`."""
type(
Expand Down Expand Up @@ -17773,7 +17773,7 @@ type Query implements Node {
based pagination. May not be used with \`last\`.
"""
offset: Int
): TypesConnection!
): TypesConnection
typeFunctionList: [Type]
typesQuery(a: BigInt!, b: Boolean!, c: String!, d: [Int]!, e: JSON!, f: FloatRangeInput!): Boolean
uniqueForeignKeyByCompoundKey1AndCompoundKey2(compoundKey1: Int!, compoundKey2: Int!): UniqueForeignKey
Expand Down

0 comments on commit 131c6ac

Please sign in to comment.