graphile-contrib / postgraphile-plugin-connection-filter

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

Support many-to-many in a simple way? #119

Open crubier opened 4 years ago

crubier commented 4 years ago

Right now this plugin does not support many-to-many relations simply. You have to go through the relation table in GraphQL query, which is not ideal, or at least not consistent with the behaviour of Prisma that we are migrating away from.

The many-to-many plugin ( https://github.com/graphile-contrib/pg-many-to-many ) support this, but only in GraphQL selection sets, not in query arguments.

Is there any way or plan to support the simplification of many-to-many filters in this plugin?

mattbretl commented 4 years ago

I don't have any plans to implement this due to the level of effort required. Sorry!

If anyone wants to take a shot at it, these three files contain most of the necessary logic:

https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/blob/4cba3cbe571480a9333906241ea6b24796498f81/src/PgConnectionArgFilterBackwardRelationsPlugin.js

https://github.com/graphile-contrib/pg-many-to-many/blob/15bd02c045b5d460bfbc7244ad3edde44246aef3/src/PgManyToManyRelationPlugin.js

https://github.com/graphile-contrib/pg-many-to-many/blob/15bd02c045b5d460bfbc7244ad3edde44246aef3/src/manyToManyRelationships.js

crubier commented 4 years ago

@mattbretl my company would be willing to pay to get this feature done (as open sourced of course👍), is this a possibility?

crubier commented 4 years ago

I have a data model that definitely involve many-to-many relations. We used to use Prisma and many-to-many relations used to be fairly straightforward, just like one-to-many or one-to-one relations basically. Now with Graphile we have to add one "layer" of nesting in query fields arguments every time we have many-to-many relations, while one-to-many or one-to-one relations are fine on the other hand.

Basically in Prisma, 1-1, 1-m, and m-m were treated the same way. In Graphile, 1-1 an 1-m are treated that same way, but m-m are treated in their own different way (with 1 level of nesting in query parameters). That additional level of nesting is not present on selection sets, thanks to the many-to-many plugin. So it strikes me as odd that the plugin solves half the problem (selection sets) while leaving the other half open (mutations and query parameters)

The end result in our API is something some internally already start to call "nesting hell":

image (32)

This is the API we used to have and that we wished we could get with a plugin:

Screenshot 2020-07-03 at 14 54 24