@@ -4,10 +4,12 @@ This Graphile Engine plugin can be used to give your schema support for
4
4
"soft-deletes" - where you set an ` is_archived ` or ` is_deleted ` column to true
5
5
and expect the record to be omitted by default (but it's still available to be
6
6
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.
8
10
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).
11
13
12
14
## Installing
13
15
@@ -58,6 +60,7 @@ app.use(
58
60
appendPlugins: [PgOmitArchived],
59
61
graphileBuildOptions: {
60
62
pgArchivedColumnName: " is_archived" ,
63
+ pgArchivedColumnImpliesVisible: false ,
61
64
},
62
65
/* ☝️☝️☝️ */
63
66
}),
@@ -84,11 +87,22 @@ app.use(
84
87
customPgOmitArchived (" archived" ),
85
88
customPgOmitArchived (" deleted" ),
86
89
customPgOmitArchived (" template" ),
90
+ customPgOmitArchived (" draft" ), // e.g. draft vs published
87
91
],
88
92
graphileBuildOptions: {
93
+ // Options for 'archived':
89
94
pgArchivedColumnName: " is_archived" , // boolean column -> checked as "IS NOT TRUE"
95
+ pgArchivedColumnImpliesVisible: false , // when true, hide; when false, visible
96
+
97
+ // Options for 'deleted':
90
98
pgDeletedColumnName: " deleted_at" , // non-boolean column -> checked as "IS NULL"
99
+
100
+ // Options for 'template':
91
101
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
92
106
},
93
107
/* ☝️☝️☝️ */
94
108
}),
@@ -97,6 +111,23 @@ app.use(
97
111
app .listen (process .env .PORT || 3000 );
98
112
```
99
113
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
+
100
131
## Behaviour
101
132
102
133
Root level query fields will omit archived records by default.
0 commit comments