Skip to content

Commit

Permalink
Beginnings of making '-*' default behavior work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Sep 2, 2023
1 parent 3f47a41 commit 122ca69
Show file tree
Hide file tree
Showing 38 changed files with 382 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,10 @@ export const PgCustomTypeFieldPlugin: GraphileConfig.Plugin = {
finalBuild.behavior.pgCodecMatches(param.codec, "type:node")
? "nodeId"
: "input");
const thing = `Argument ${index} (name: ${param.name}, type: ${param.codec.name}) of function '${resource.name}' (${resource.extensions?.pg?.schemaName}.${resource.extensions?.pg?.name})`;
if (variant === "nodeId" && !param.codec.attributes) {
throw new Error(
`Argument is marked as nodeId, but it doesn't seem to be a record type. Lists of nodeIds are not yet supported.`,
`${thing} is marked as nodeId, but it doesn't seem to be a record type. Lists of nodeIds are not yet supported.`,
);
}
const baseInputType =
Expand All @@ -391,17 +392,27 @@ export const PgCustomTypeFieldPlugin: GraphileConfig.Plugin = {
if (variant === "nodeId" && !finalBuild.nodeIdSpecForCodec) {
// ERRORS: tell them how to turn the nodeId variant off
throw new Error(
`Argument is configured to use nodeId variant, but build is not configured with Node support - there is no 'build.nodeFetcherByTypeName'. Did you skip NodePlugin?`,
`${thing} is configured to use nodeId variant, but build is not configured with Node support - there is no 'build.nodeFetcherByTypeName'. Did you skip NodePlugin?`,
);
}
const getSpec =
variant === "nodeId"
? finalBuild.nodeIdSpecForCodec(paramBaseCodec)
: null;
if (variant === "nodeId" && !getSpec) {
console.log({
variant: param.extensions?.variant,
pgFunctionsPreferNodeId,
isMutation: resource.isMutation,
hasAttributes: !!param.codec.attributes,
behavior: finalBuild.behavior.pgCodecMatches(
param.codec,
"type:node",
),
});
// ERRORS: tell them how to turn the nodeId variant off
throw new Error(
`Argument is configured to use nodeId variant, but we don't know how to get the spec for codec '${paramBaseCodec.name}'`,
`${thing} is configured to use nodeId variant, but we don't know how to get the spec for codec '${paramBaseCodec.name}'`,
);
}
const codecResource =
Expand All @@ -411,7 +422,7 @@ export const PgCustomTypeFieldPlugin: GraphileConfig.Plugin = {
if (variant === "nodeId" && !codecResource) {
// ERRORS: tell them how to turn the nodeId variant off
throw new Error(
`Argument is configured to use nodeId variant, but we couldn't find a suitable resource to pull a '${paramBaseCodec.name}' record from`,
`${thing} is configured to use nodeId variant, but we couldn't find a suitable resource to pull a '${paramBaseCodec.name}' record from`,
);
}
const fetcher =
Expand Down Expand Up @@ -1222,6 +1233,7 @@ export const PgCustomTypeFieldPlugin: GraphileConfig.Plugin = {
}
}

// console.log(`${resource.name} ${listFieldBehaviorScope}`);
if (
build.behavior.pgResourceMatches(
resource,
Expand All @@ -1237,6 +1249,9 @@ export const PgCustomTypeFieldPlugin: GraphileConfig.Plugin = {
: inflection.computedAttributeListField({
resource,
});
// console.log(
// `${resource.name} ${listFieldBehaviorScope} ${fieldName}`,
// );
memo = build.recoverable(memo, () =>
build.extend(
memo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const PgMutationCreatePlugin: GraphileConfig.Plugin = {
provides: ["default"],
before: ["inferred", "override"],
callback(behavior, resource) {
const newBehavior = [behavior, "+insert:resource:select"];
const newBehavior = ["+insert:resource:select"];
if (
!resource.parameters &&
!!resource.codec.attributes &&
Expand All @@ -86,6 +86,7 @@ export const PgMutationCreatePlugin: GraphileConfig.Plugin = {
newBehavior.unshift("insert");
newBehavior.unshift("record");
}
newBehavior.push(behavior);
return newBehavior;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const PgTableNodePlugin: GraphileConfig.Plugin = {
provides: ["default"],
before: ["inferred", "override"],
callback(behavior, codec, build) {
const newBehavior = [behavior];
const newBehavior = [];
if (
!codec.isAnonymous &&
!!codec.attributes &&
Expand All @@ -50,12 +50,14 @@ export const PgTableNodePlugin: GraphileConfig.Plugin = {
if (codec.polymorphism) {
newBehavior.push("interface:node");
} else {
console.log(`${resource.name} is type:node`);
newBehavior.push("type:node");
}
} else {
// Meh
}
}
newBehavior.push(behavior);
return newBehavior;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ enum CompoundKeysOrderBy {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
computedField: Int
Expand All @@ -512,6 +513,8 @@ type CompoundType {
f: EnumWithEmptyString
fooBar: Int
g: Interval
query: CompoundType
queryCompoundTypeArray: [CompoundType]
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down Expand Up @@ -7143,6 +7146,7 @@ type Query implements Node {
"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeArrayQuery(object: CompoundTypeInput): [CompoundType]
compoundTypeComputedField(compoundType: CompoundTypeInput): Int
compoundTypeQuery(object: CompoundTypeInput): CompoundType

"""Reads and enables pagination through a set of `CompoundType`."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ enum CompoundKeysOrderBy {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
computedField: Int
Expand All @@ -512,6 +513,8 @@ type CompoundType {
f: EnumWithEmptyString
fooBar: Int
g: Interval
query: CompoundType
queryCompoundTypeArray: [CompoundType]
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down Expand Up @@ -7143,6 +7146,7 @@ type Query implements Node {
"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeArrayQuery(object: CompoundTypeInput): [CompoundType]
compoundTypeComputedField(compoundType: CompoundTypeInput): Int
compoundTypeQuery(object: CompoundTypeInput): CompoundType

"""Reads and enables pagination through a set of `CompoundType`."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ type CompoundType {
g: Interval
}

"""An input for mutations affecting `CompoundType`"""
input CompoundTypeInput {
a: Int
b: String
c: Color
d: UUID
e: EnumCaps
f: EnumWithEmptyString
fooBar: Int
g: IntervalInput
}

"""A connection to a list of `CompoundType` values."""
type CompoundTypesConnection {
"""
Expand Down Expand Up @@ -1276,6 +1288,33 @@ type Interval {
years: Int
}

"""
An interval of time that has passed where the smallest distinct unit is a second.
"""
input IntervalInput {
"""A quantity of days."""
days: Int

"""A quantity of hours."""
hours: Int

"""A quantity of minutes."""
minutes: Int

"""A quantity of months."""
months: Int

"""
A quantity of seconds. This is the only non-integer field, as all the other
fields will dump their overflow into a smaller unit of time. Intervals don’t
have a smaller unit than seconds.
"""
seconds: Float

"""A quantity of years."""
years: Int
}

type Issue756 implements Node {
id: Int!

Expand Down Expand Up @@ -3509,6 +3548,7 @@ type Query implements Node {

"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeComputedField(compoundType: CompoundTypeInput): Int

"""Reads and enables pagination through a set of `CompoundType`."""
compoundTypeSetQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ type CompoundType {
g: Interval
}

"""An input for mutations affecting `CompoundType`"""
input CompoundTypeInput {
a: Int
b: String
c: Color
d: UUID
e: EnumCaps
f: EnumWithEmptyString
fooBar: Int
g: IntervalInput
}

"""A connection to a list of `CompoundType` values."""
type CompoundTypesConnection {
"""
Expand Down Expand Up @@ -1287,6 +1299,33 @@ type Interval {
years: Int
}

"""
An interval of time that has passed where the smallest distinct unit is a second.
"""
input IntervalInput {
"""A quantity of days."""
days: Int

"""A quantity of hours."""
hours: Int

"""A quantity of minutes."""
minutes: Int

"""A quantity of months."""
months: Int

"""
A quantity of seconds. This is the only non-integer field, as all the other
fields will dump their overflow into a smaller unit of time. Intervals don’t
have a smaller unit than seconds.
"""
seconds: Float

"""A quantity of years."""
years: Int
}

type Issue756 implements Node {
id: Int!

Expand Down Expand Up @@ -3536,6 +3575,7 @@ type Query implements Node {

"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeComputedField(compoundType: CompoundTypeInput): Int

"""Reads and enables pagination through a set of `CompoundType`."""
compoundTypeSetQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ enum CompoundKeysOrderBy {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
computedField: Int
Expand All @@ -512,6 +513,8 @@ type CompoundType {
f: EnumWithEmptyString
fooBar: Int
g: Interval
query: CompoundType
queryCompoundTypeArray: [CompoundType]
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down Expand Up @@ -7055,6 +7058,7 @@ type Query implements Node {
"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeArrayQuery(object: CompoundTypeInput): [CompoundType]
compoundTypeComputedField(compoundType: CompoundTypeInput): Int
compoundTypeQuery(object: CompoundTypeInput): CompoundType

"""Reads and enables pagination through a set of `CompoundType`."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ enum CompoundKeysOrderBy {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
computedField: Int
Expand All @@ -512,6 +513,8 @@ type CompoundType {
f: EnumWithEmptyString
fooBar: Int
g: Interval
query: CompoundType
queryCompoundTypeArray: [CompoundType]
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down Expand Up @@ -7143,6 +7146,7 @@ type Query implements Node {
"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeArrayQuery(object: CompoundTypeInput): [CompoundType]
compoundTypeComputedField(compoundType: CompoundTypeInput): Int
compoundTypeQuery(object: CompoundTypeInput): CompoundType

"""Reads and enables pagination through a set of `CompoundType`."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ enum CompoundKeysOrderBy {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
computedField: Int
Expand All @@ -473,6 +474,8 @@ type CompoundType {
f: EnumWithEmptyString
fooBar: Int
g: Interval
query: CompoundType
queryCompoundTypeArray: [CompoundType]
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down Expand Up @@ -6859,6 +6862,7 @@ type Query implements Node {
"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeArrayQuery(object: CompoundTypeInput): [CompoundType]
compoundTypeComputedField(compoundType: CompoundTypeInput): Int
compoundTypeQuery(object: CompoundTypeInput): CompoundType

"""Reads and enables pagination through a set of `CompoundType`."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ enum CompoundKeysOrderBy {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
computedField: Int
Expand All @@ -517,6 +518,8 @@ type CompoundType {
f: EnumWithEmptyString
fooBar: Int
g: I
query: CompoundType
queryCompoundTypeArray: [CompoundType]
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down Expand Up @@ -7148,6 +7151,7 @@ type Q implements N {
"""Get a single `CompoundKey`."""
compoundKeyByPersonId1AndPersonId2(personId1: Int!, personId2: Int!): CompoundKey
compoundTypeArrayQuery(object: CompoundTypeInput): [CompoundType]
compoundTypeComputedField(compoundType: CompoundTypeInput): Int
compoundTypeQuery(object: CompoundTypeInput): CompoundType

"""Reads and enables pagination through a set of `CompoundType`."""
Expand Down
2 changes: 2 additions & 0 deletions postgraphile/postgraphile/__tests__/schema/v4/jwt.1.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ enum Color {
"""Awesome feature!"""
type CompoundType {
a: Int
arrayQuery: [CompoundType]
b: String
c: Color
d: UUID
e: EnumCaps
f: EnumWithEmptyString
fooBar: Int
g: Interval
query: CompoundType
}

"""All input for the `compoundTypeArrayMutation` mutation."""
Expand Down
Loading

0 comments on commit 122ca69

Please sign in to comment.