Skip to content

Commit 2aace37

Browse files
committed
Add connectionFilterAllowedOperators plugin option
1 parent 36ef81f commit 2aace37

File tree

4 files changed

+2661
-28
lines changed

4 files changed

+2661
-28
lines changed

README.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# postgraphile-plugin-connection-filter
22
This plugin adds a `filter` argument to Connection types in PostGraphile v4.
33

4-
## Disclaimer
4+
> **Note:** This plugin targets the alpha release of PostGraphile v4. Because of possible API changes, releases of this plugin are pinned to specific alpha versions of PostGraphile. See the Compatibility table below for details.
55
6-
This plugin targets the alpha release of PostGraphile v4. Bug reports and pull requests are very much welcome.
6+
> **Warning:** This plugin exposes a large number of operators (including some that can perform expensive pattern matching) by default. Before enabling this plugin in production, you should consider the performance and security implications. Use of the `connectionFilterAllowedOperators` option to limit the operators exposed through GraphQL is strongly encouraged.
77
88
## Compatibility
99

@@ -177,12 +177,49 @@ For additional examples, see the [tests](https://github.com/mattbretl/postgraphi
177177

178178
When using PostGraphile as a library, the following plugin options can be passed via `graphileBuildOptions` (called `graphqlBuildOptions` in PostGraphile 4.0.0-alpha2.20 and earlier):
179179

180+
### connectionFilterAllowedOperators
181+
182+
Restrict filtering to specific operators
183+
``` js
184+
postgraphile(pgConfig, schema, {
185+
graphileBuildOptions: {
186+
connectionFilterAllowedOperators: [
187+
"null",
188+
"equalTo",
189+
"notEqualTo",
190+
"distinctFrom",
191+
"notDistinctFrom",
192+
"lessThan",
193+
"lessThanOrEqualTo",
194+
"greaterThan",
195+
"greaterThanOrEqualTo",
196+
"in",
197+
"notIn",
198+
],
199+
},
200+
})
201+
```
202+
203+
For a full list of the available operators, see the Comparison Operators table above.
204+
205+
### connectionFilterAllowedFieldTypes
206+
207+
Restrict filtering to specific field types
208+
``` js
209+
postgraphile(pgConfig, schema, {
210+
graphileBuildOptions: {
211+
connectionFilterAllowedFieldTypes: ["String", "Int"],
212+
},
213+
})
214+
```
215+
216+
The available field types will depend on your database schema.
217+
180218
### connectionFilterOperatorNames
181219

182220
Use alternative names (e.g. `eq`, `ne`) for operators
183221
``` js
184222
postgraphile(pgConfig, schema, {
185-
...
186223
graphileBuildOptions: {
187224
connectionFilterOperatorNames: {
188225
equalTo: "eq",
@@ -195,7 +232,6 @@ postgraphile(pgConfig, schema, {
195232
Note: The `connectionFilterUsesShortNames` option was removed in v1.0.0-alpha.6. To restore the old functionality, you can use this:
196233
``` js
197234
postgraphile(pgConfig, schema, {
198-
...
199235
graphileBuildOptions: {
200236
connectionFilterOperatorNames: {
201237
equalTo: "eq",
@@ -221,26 +257,12 @@ postgraphile(pgConfig, schema, {
221257
like: "like",
222258
notLike: "nlike",
223259
likeInsensitive: "ilike",
224-
notLikeInsensitive: "nilike"
260+
notLikeInsensitive: "nilike",
225261
},
226262
},
227263
})
228264
```
229265

230-
### connectionFilterAllowedFieldTypes
231-
232-
Restrict filters to specific field types
233-
``` js
234-
postgraphile(pgConfig, schema, {
235-
...
236-
graphileBuildOptions: {
237-
connectionFilterAllowedFieldTypes: ["String", "Int"],
238-
},
239-
})
240-
```
241-
242-
To add/remove/modify individual operators, you can edit src/PgConnectionArgFilterOperatorsPlugin.js.
243-
244266
## Development
245267

246268
To establish a test environment, create an empty Postgres database (e.g. `graphile_build_test`) and set a `TEST_DATABASE_URL` environment variable with your connection string (e.g. `postgres://localhost:5432/graphile_build_test`). Ensure that `psql` is installed locally and then run:

0 commit comments

Comments
 (0)