Skip to content

Commit 331ab84

Browse files
authored
fix: INHERIT should default to defaultValue (#35)
1 parent 08eaa0b commit 331ab84

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/index.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const makeUtils = (
6666
);
6767
}
6868

69+
const defaultValue = build.options[`pg${Keyword}Default`] || "NO";
70+
6971
const tables = rawTables
7072
? (rawTables as string[]).map((t) => {
7173
const [schemaOrTable, tableOnly, ...rest] = t.split(".");
@@ -219,6 +221,13 @@ const makeUtils = (
219221
// any extra WHERE clauses.
220222
return;
221223
}
224+
// INHERIT is equivalent to defaultValue if there's no valid parent
225+
const relevantSettingIfNotInherit =
226+
relevantSetting !== "INHERIT"
227+
? relevantSetting
228+
: defaultValue !== "INHERIT"
229+
? defaultValue
230+
: "NO";
222231
if (
223232
capableOfInherit &&
224233
relevantSetting === "INHERIT" &&
@@ -233,15 +242,11 @@ const makeUtils = (
233242
sql,
234243
myAlias,
235244
)} is ${localDetails.visibleFragment})`;
236-
} else if (
237-
relevantSetting === "NO" ||
238-
// INHERIT is equivalent to NO if there's no valid parent
239-
relevantSetting === "INHERIT"
240-
) {
245+
} else if (relevantSettingIfNotInherit === "NO") {
241246
fragment = sql.fragment`${localDetails.expression(sql, myAlias)} is ${
242247
localDetails.visibleFragment
243248
}`;
244-
} else if (relevantSetting === "EXCLUSIVELY") {
249+
} else if (relevantSettingIfNotInherit === "EXCLUSIVELY") {
245250
fragment = sql.fragment`${localDetails.expression(sql, myAlias)} is ${
246251
localDetails.invisibleFragment
247252
}`;
@@ -362,6 +367,7 @@ const generator = (keyword = "archived"): GraphileEnginePlugin => {
362367
const {
363368
graphql: { GraphQLEnumType },
364369
} = build;
370+
const defaultValue = build.options[`pg${Keyword}Default`] || "NO";
365371
build.newWithHooks(
366372
GraphQLEnumType,
367373
{
@@ -381,7 +387,9 @@ const generator = (keyword = "archived"): GraphileEnginePlugin => {
381387
value: "EXCLUSIVELY",
382388
},
383389
INHERIT: {
384-
description: `If there is a parent GraphQL record and it is ${keyword} then this is equivalent to YES, in all other cases this is equivalent to NO.`,
390+
description: `If there is a parent GraphQL record and it is ${keyword} then this is equivalent to YES, in all other cases this is equivalent to ${
391+
defaultValue === "INHERIT" ? "NO" : defaultValue
392+
}.`,
385393
value: "INHERIT",
386394
},
387395
},

0 commit comments

Comments
 (0)