Skip to content

Commit d035ffb

Browse files
authored
feat: enable inverting archive behaviour (#15)
1 parent 19c005b commit d035ffb

File tree

4 files changed

+446
-340
lines changed

4 files changed

+446
-340
lines changed

README.md

+34-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ This Graphile Engine plugin can be used to give your schema support for
44
"soft-deletes" - where you set an `is_archived` or `is_deleted` column to true
55
and expect the record to be omitted by default (but it's still available to be
66
recovered should you need to). It's also useful for hiding certain other classes
7-
of records by default, but allowing them to be shown by passing a parameter.
7+
of records by default, but allowing them to be shown by passing a parameter; for
8+
example you could hide drafts via a `published_at` column and require an
9+
explicit `includeDrafts: YES` setting to show them.
810

9-
It's possible to use this plugin multiple times (for different column
10-
names/meanings).
11+
It's possible (and common) to use this plugin multiple times (for different
12+
column names/meanings).
1113

1214
## Installing
1315

@@ -58,6 +60,7 @@ app.use(
5860
appendPlugins: [PgOmitArchived],
5961
graphileBuildOptions: {
6062
pgArchivedColumnName: "is_archived",
63+
pgArchivedColumnImpliesVisible: false,
6164
},
6265
/* ☝️☝️☝️ */
6366
}),
@@ -84,11 +87,22 @@ app.use(
8487
customPgOmitArchived("archived"),
8588
customPgOmitArchived("deleted"),
8689
customPgOmitArchived("template"),
90+
customPgOmitArchived("draft"), // e.g. draft vs published
8791
],
8892
graphileBuildOptions: {
93+
// Options for 'archived':
8994
pgArchivedColumnName: "is_archived", // boolean column -> checked as "IS NOT TRUE"
95+
pgArchivedColumnImpliesVisible: false, // when true, hide; when false, visible
96+
97+
// Options for 'deleted':
9098
pgDeletedColumnName: "deleted_at", // non-boolean column -> checked as "IS NULL"
99+
100+
// Options for 'template':
91101
pgTemplateColumnName: "is_template",
102+
103+
// Options for 'draft':
104+
pgDraftColumnName: "is_published", // Column name doesn't have to match keyword name
105+
pgDraftColumnImpliesVisible: true, // When true -> published -> visible; when false -> unpublished -> hiddel
92106
},
93107
/* ☝️☝️☝️ */
94108
}),
@@ -97,6 +111,23 @@ app.use(
97111
app.listen(process.env.PORT || 3000);
98112
```
99113

114+
### Usage - advanced options
115+
116+
By default we'll look for a column named after your keyword (e.g. if you use the
117+
'deleted' keyword, we'll look for an `is_deleted` column). You may override the
118+
column adding the `pg<Keyword>ColumnName: 'my_column_name_here'` setting to
119+
`graphileBuildOptions`, where `<Keyword>` is your keyword with the first
120+
character uppercased (see above for examples).
121+
122+
This plugin was built expecting to hide things when `true` (boolean) or non-null
123+
(e.g. nullable timestamp) - this works well for things like `is_archived`,
124+
`deleted_at`, and `is_template`. However sometimes you want this inverse of this
125+
behaviour; e.g. if your column is `published_at` you'd want it visible when
126+
non-null and hidden when null. To invert the behaviour, add the
127+
`pg<Keyword>ColumnImpliesVisible: true` setting to `graphileBuildOptions`, where
128+
`<Keyword>` is your keyword with the first character uppercased (see above for
129+
examples).
130+
100131
## Behaviour
101132

102133
Root level query fields will omit archived records by default.

0 commit comments

Comments
 (0)