Introduce register_graphql_connection_where_arg
API
#3065
Labels
component: connections
Relating to GraphQL Connections
component: query
Relating to GraphQL Queries
scope: api
Issues related to access functions, actions, and filters
type: enhancement
Improvements to existing functionality
What problem does this address?
When trying to do things like add Where Args to all connections to a specific type it's cumbersome to do so.
With Object Types, we can add a field to
ContentNode
and all Types that implement the interface get the field.But with Input Types there's no concept of Input Interfaces, so each unique connection cannot inherit a general set of fields like Object Types can.
If we wanted to add a custom where arg to all "post" connections, it becomes tricky.
If using
register_graphql_field()
I would have to know the names of all possiblePost
connections and do something like:...and so on
This doesn't scale!
I can't / don't want to attempt to keep up with all the possible types I would need to filter. When it comes to things like ACF that add even more Types to the Schema, etc it is essentially impossible to know all the connections that may exist in the schema.
To get around this, we could add a filter like so:
This should work and is certainly better than
register_graphql_field()
for unknown to add a where arg to all Post connections, but feels clunky. . .and I'd still have to map how the input argument impacts the underlying resolution.Another (cleaner) option would be hooking into the connection Instantiation like so:
This is looking much better!
But I still need to map the new arg to underlying resolution.
What is your proposed solution?
I propose we introduce a
register_graphql_connection_where_arg()
API that makes it easier to add an argument to connection(s) AND map the argument to the underlying execution.Something to the tune of:
which could be used like so:
What alternatives have you considered?
(see possible alternatives above)
Additional Context
No response
The text was updated successfully, but these errors were encountered: