-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding default condition doesn't work as expected (requires change to GraphQL Spec) #691
Comments
This is, indeed, an issue in GraphQL itself (arguably in the spec) To reproduce:
You'd expect all these results to be the same, but this isn't the case:
We can (and should) work around this in Graphile Engine. |
It seems obvious to me that the And added it to the next GraphQL WG: https://github.com/graphql/graphql-wg/blob/master/agendas/2020-12-03.md#agenda |
Having had an in-depth discussion with Ivan (maintainer of GraphQL.js), I'm going to hold off on fixing this. Implementation is here: #692 and you can do it yourself with a plugin if you need it in the interrim. |
Work on this is progressing as part of the GraphQL Spec Working Group; see recent working group agendas and notes (and linked PRs) for info. |
This is unlikely to make it into V4 because it's still awaiting fixes to the GraphQL spec |
Adding a default value for a condition (e.g.
fields.includeArchived = { type: GraphQLBoolean, defaultValue: false}
) doesn't apply unless you pass an empty condition object (e.g.{myCollection { ... } }
doesn't respect it, but{myCollection(condition: {}) { ... } }
does). However this cannot be solved by setting thedefaultValue
of thecondition
argument to be{}
; though this gets correctly exposed in GraphiQL:The results of running a query show that this condition wasn't actually applied, since the two queries above would produce different results when they should not.
I don't know why this is, but at the moment I'm leaning towards it being a bug in the way that Graphile Engine processes arguments (perhaps not applying defaults recursively?). It might actually be a GraphQL thing, but that has yet to be determined.
Interestingly, if you set the default value for the
condition
argument todefaultValue: {includeArchived: false}
then it works as it should, but it should not be necessary to do this additional lookup.Warrants further investigation. Also, once solved, we should give
condition
a default value of{}
so these default conditions can apply automatically.The text was updated successfully, but these errors were encountered: