Skip to content

Commit c5c3834

Browse files
authored
feat: allow changing the default (#34)
1 parent 07a0267 commit c5c3834

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ you'd set `pgArchivedColumnImpliesVisible: true` rather than the default
6868
Another option is to have the plugin apply to related records with the
6969
`pgArchivedRelations: true` option - more on this below.
7070

71+
You can also change the default for `includeArchived` from `NO` to `YES` via
72+
`pgArchivedDefaultInclude: "YES"` (another option is `EXCLUSIVELY`).
73+
7174
Example:
7275

7376
```js
@@ -87,6 +90,7 @@ app.use(
8790
pgArchivedColumnName: "is_archived",
8891
pgArchivedColumnImpliesVisible: false,
8992
pgArchivedRelations: false,
93+
pgArchivedDefault: "NO",
9094
},
9195
/* ☝️☝️☝️ */
9296
}),
@@ -126,6 +130,8 @@ app.use(
126130
pgArchivedColumnImpliesVisible: false,
127131
// Only add includeArchived to tables with is_archived column:
128132
pgArchivedRelations: false,
133+
// Exclude archived by default
134+
pgArchivedDefault: "NO",
129135

130136
/* -------- Options for 'deleted' -------- */
131137
// Non-boolean column -> checked as "IS NULL":
@@ -136,6 +142,8 @@ app.use(
136142

137143
/* -------- Options for 'template' -------- */
138144
pgTemplateColumnName: "is_template",
145+
// Include templates by default
146+
pgTemplateDefault: "YES",
139147

140148
/* -------- Options for 'draft' -------- */
141149
// Column name doesn't have to match keyword name:

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ const generator = (keyword = "archived"): GraphileEnginePlugin => {
412412
Self,
413413
field,
414414
} = context;
415+
const defaultValue = build.options[`pg${Keyword}Default`] || "NO";
415416
const table: PgClass = pgFieldIntrospection;
416417
if (
417418
!(isPgFieldConnection || isPgFieldSimpleCollection) ||
@@ -462,7 +463,7 @@ const generator = (keyword = "archived"): GraphileEnginePlugin => {
462463
[argumentName]: {
463464
description: `Indicates whether ${keyword} items should be included in the results or not.`,
464465
type: OptionType,
465-
defaultValue: capableOfInherit ? "INHERIT" : "NO",
466+
defaultValue: capableOfInherit ? "INHERIT" : defaultValue,
466467
},
467468
},
468469
`Adding ${argumentName} argument to connection field '${field.name}' of '${Self.name}'`,

0 commit comments

Comments
 (0)