Skip to content

Commit

Permalink
Consider attribute's isNotNull flag for polymorphic types (#1875)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Nov 30, 2023
2 parents 4f2fb57 + dc2bff7 commit 5450bde
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-guests-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"graphile-build-pg": patch
---

Consider attribute's `isNotNull` flag for polymorphic types
14 changes: 12 additions & 2 deletions graphile-build/graphile-build-pg/src/plugins/PgAttributesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function processAttribute(
| GraphileBuild.ContextInterfaceFields,
attributeName: string,
overrideName?: string,
isNotNull?: boolean,
): void {
const { extend, inflection } = build;

Expand Down Expand Up @@ -126,7 +127,7 @@ function processAttribute(
});
const resolveResult = build.pgResolveOutputType(
attribute.codec,
attribute.notNull || attribute.extensions?.tags?.notNull,
isNotNull || attribute.notNull || attribute.extensions?.tags?.notNull,
);
if (!resolveResult) {
console.warn(
Expand Down Expand Up @@ -386,6 +387,7 @@ export const PgAttributesPlugin: GraphileConfig.Plugin = {

for (const attributeName in pgCodec.attributes) {
let overrideName: string | undefined = undefined;
let isNotNull: boolean | undefined = undefined;
if (pgPolymorphism) {
switch (pgPolymorphism.mode) {
case "single": {
Expand All @@ -401,6 +403,7 @@ export const PgAttributesPlugin: GraphileConfig.Plugin = {
if (match?.rename) {
overrideName = match.rename;
}
isNotNull = match?.isNotNull;

break;
}
Expand All @@ -418,7 +421,14 @@ export const PgAttributesPlugin: GraphileConfig.Plugin = {
}
}
}
processAttribute(fields, build, context, attributeName, overrideName);
processAttribute(
fields,
build,
context,
attributeName,
overrideName,
isNotNull,
);
}
return fields;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7103,7 +7103,7 @@ type SingleTableTopic implements Node & SingleTableItem {
"""The method to use when ordering `SingleTableItem`."""
orderBy: [SingleTableItemsOrderBy!] = [PRIMARY_KEY_ASC]
): SingleTableItemsConnection!
title: String
title: String!
type: ItemType!
updatedAt: Datetime!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6375,7 +6375,7 @@ type SingleTableTopic implements SingleTableItem {
"""The method to use when ordering `SingleTableItem`."""
orderBy: [SingleTableItemsOrderBy!] = [PRIMARY_KEY_ASC]
): SingleTableItemsConnection!
title: String
title: String!
type: ItemType!
updatedAt: Datetime!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7546,7 +7546,7 @@ type SingleTableTopic implements SingleTableItem {
"""The method to use when ordering `SingleTableItem`."""
orderBy: [SingleTableItemOrderBy!] = [PRIMARY_KEY_ASC]
): SingleTableItemConnection!
title: String
title: String!
type: ItemType!
updatedAt: Datetime!
}
Expand Down

0 comments on commit 5450bde

Please sign in to comment.