-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
A possible minor bug in ExecutionContext.complete_value #187
Comments
Hi @ipeterov, thank you for reporting this problem. For background, the code that you quoted actually replicates the corresponding code in GraphQL.js here and here. As a fix, we could change the check for exceptions like this: if isinstance(result, Exception) and result is not Undefined:
raise result But actually this does not feel right and reveals that the way how the type of I think we should change this in the upcoming 3.3 release add instead make it a subclass of The above fix could be applied in the 3.2.x maintenance branch because it is more backward compatible. What do you think about this? We also need a test for this. It's strange that this was not caught by one of the existing tests. |
If I interpreted your issue correctly, you are trying to set a required field to undefined in a response. This should not be possible when you are trying to stay in line with the GQL spec, check this comment here: graphql/graphql-js#1298 (comment) If you have incorrect permission to read a required field your only option would be to throw an error which will traverse up the AST to the next nullable node and set it to zero. If you set a field to undefined that means it is not present in the response. All requested fields of the query must be present in the response unless there is an error. (Or an error moved to the next nullable parent node in the AST for required fields). I strongly suggest throwing errors instead of trying to set fields to None. Defensive contract first API design can save you many headaches later (e.g. an API consumer using gql codegen expecting that field to always be present). |
I agree with @erikwrede but @ipeterov is also right in that this check does not work as it should. Will look a bit deeper into this when I have more time. |
@Cito The other part of my comment got lost because I had to change trains, so I'll add it here 🙂 |
I have changed this now so that Keeping this open for feedback until the next version with this change is released. |
I like the change! |
This change is now implemented in 3.3.0a3. |
I'm trying to figure out a way to return
None
for non-nullable fields if the requesting user doesn't have permission to view them.I was trying to pass
Undefined
fromgraphql.pyutils.undefined
, but it doesn't work. It looks like the second check in this linecan never run because
Undefined
is actually a descendant ofValueError
and therefore triggers this check.I don't know if this was meant as an escape hatch for returning null values if you really wanted to (which is what I really need right now), but the code itself seems wrong either way.
The text was updated successfully, but these errors were encountered: