graphile-contrib / postgraphile-plugin-connection-filter

Filtering on PostGraphile connections
MIT License
286 stars 32 forks source link

feat: allow specifying to use list inflectors #177

Closed benjie closed 2 years ago

benjie commented 2 years ago

Currently this plugin uses the presence of connections to indicate whether the "connection" or "simple" (list) inflectors are used for backwards relations:

https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/blob/fda1bc1e4474a3a64be10f3228c81b88560f6799/src/PgConnectionArgFilterBackwardRelationsPlugin.ts#L9

https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/blob/fda1bc1e4474a3a64be10f3228c81b88560f6799/src/PgConnectionArgFilterBackwardRelationsPlugin.ts#L302-L314

It's common to change your choice as to whether you want simple collections, connections, or both in your GraphQL schema (and you can change it on a resource-by-resource basis), so it's designed to be non-breaking when you expand from one of the options to using both. As such, we require explicit opt-out of having the -list suffix; the @graphile-contrib/pg-simplify-inflector plugin offers this via the pgOmitListSuffix option.

Ideally we'd switch this plugin to use that option too, but that would be a breaking change. So instead, I have introduced a new option connectionFilterUseListInflectors that tells the plugin explicitly whether to use the list inflectors or not, if present it will override the default logic.

The main value of this is for users who have simpleCollections: "both" and pgOmitListSuffix: true.