-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Coercing Variable Values when hasValue is not true and defaultValue does NOT exist #1044
Comments
null is value too, it should be coerced into no-value or empty. |
In pure GraphQL Java, you have DataFetchingEnvironment.containsArgument(String) to detect such cases. But maybe higher level abstractions like Spring integrations the behaviour is different? All in all, I'd say this doesn't belong in the spec. Different resolver handle the absence of an argument differently but resolver implementations are outside the spec. |
@martinbonnin Sorry, I got the example I posted slightly wrong. Here is an updated version that illustrates the issue:
If no variables are suppled in the request, this gets resolved to:
It is now not possible to determine if the query should be filtered by That said, my actual point here is that the spec does not define how to resolve an input that uses a variable when the variable does not have a value and the input does not have a default value. This leaves the behavior undefined. The two reference implementations I used both do the same thing, but it seems like it wouldn't be out of spec to use |
It's the same thing. The handling of absent input values is left to your resolver. In your GraphQL Java resolver, you'll have something like so: Map<String, Object> map = environment.getArgument("where") as Map<String, Object>;
map.containsKey("id") // false
map.containsKey("name") // false So your resolver has to decide what to do and in your specific case, certainly return an error if it doesn't not know if it should filter by All in all, input UserInput {
name: String
phoneNumber: String
email: String
}
mutation DeleteEmail {
# delete email, leave name and phoneNumber unchanged
updateUser(userInput: {email: null}) {
status
}
} It's up to your resolver to know how to handle the different cases, the spec doesn't know how to interpret them. |
@martinbonnin But based on my reading of the spec it doesn't say that what the value should be if hasValue is false and there is no default. Since it is not specified in the spec, a resolver could reasonable resolve the value to |
I think it's in the spec? Your initial post is about variable coercion but what you're looking for is more like argument coercion? https://spec.graphql.org/October2021/#sel-NANRHHCJFTDFBDCAACGBq0B:
https://spec.graphql.org/October2021/#sel-HAHhBVHBABAB2KhtV:
|
@martinbonnin yes thank you! I missed that part of the spec. I will close this issue. |
Edited to fix the example and provide some additional clarification.
As far as I can tell the spec is missing the case when a variable does not have a value and does not have a default value.
For example with this spec
And this query:
What should be the expected behavior if no value is provided for
$name
?In the graphql-java implementation the behavior is to omit the field entirely from the input object. So the query ends up resolving to:
Here is what the spec says:
But there is no case for no value supplied and no default value for a nullable input.
The text was updated successfully, but these errors were encountered: