-
Notifications
You must be signed in to change notification settings - Fork 172
List of IDs is not resolved correctly #367
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
Comments
This is a regression caused by this PR https://github.com/graphql-java-kickstart/graphql-java-tools/pull/358/files |
I'm having this problem too after upgrading, we're using a custom |
From GraphQL documentation:
In other words However, many users are relying on the bug so we are considering reverting to the old behaviour of the |
The GraphQL specification states that an ID should indeed serialize as a String in the JSON response, but it is more lax when treating input and makes no assumptions about internal representation:
So, there is no restriction on how the server represents IDs internally, even if they should always serialize to a String. I think it is worthwhile to allow the implementing resolvers to determine their appropriate ID type for themselves - if you have a dedicated custom If accidentally using other types that are not meant to hold IDs is a concern, then I'd be fine with registering the custom ID type explicitly when building the schema to prevent such cases. |
I've added a (failing) unit test to verify this behavior on a separate branch (see #379). We can't simply revert, because then the #240 will break again, and that should just work too. That case was actually very similar, since the single Upload scalar worked fine, while it failed when using multiple. Now we see the same behavior for the built-in ID scalar. The Any help to fix the issue is appreciated! |
Not the cleanest fix, but it works and all unit tests are green again. Basically all scalar types that represent a type that's not part of the |
The fix doesn't work in our case:
It seems like nested generic types with type arguments other than
|
That's because in your case the |
It's the other way around, actually. I would want our Btw, I also wondered why |
We'll have to add a (failing) unit test for your particular use case and fix it. Not sure when I have time to look at it though. PRs are also welcome in case you're up for it. Problem seems to be specific to generics now. |
@oliemansm Could you quickly outline what the desired behavior would be in your eyes right now? Exactly what cases should be handled by Jackson, and which should be passed through as-is? I'm thinking a minimum would be "if the input value is a String, and the type of the resolver parameter is not String, try to convert the value with Jackson" (and analogous for List, Optional etc), because I guess everything else will end up in class cast exceptions at runtime? But I might not have the complete context here. |
When fixing this bug I added this unit test. This verifies the situation where the The end to end test spec also tests a couple of use cases that are relevant, like the
And now you're facing an issue where the ID scalar isn't represented by a simple type, but instead by a parameterized type. And the new method that I added to fix this bug apparently can't cope with that apparently. In the end most important thing is that it's compliant with the specification. I'd have to dive deeper into scalars to be able to provide sensible input here, and not sure when I have that kind of time. This is becoming pretty complicated now for something seemingly simple. Ideally Jackson would just take care of stuff, but the Upload scalar mapped to |
I'm encountering this issue with a list of I'm looking at the source and see special handling for genericised lists of java.lang.* types. What are your thoughts on widening this to accept |
…t-resolved-correctly Always convert scalar ID values to the method parameter type fix #367
Consider following schema fragment:
On backend
ID
is of typeLong
.Resolver methods for above mutations expect
Long
andList<Long>
arguments:On version
5.7.1
everything works correctly.On version
6.0.0
singleID
is resolved correctly toLong
, but list of ids[ID]
is resolved toList<String>
(insteadList<Long>
)Here is a screenshot from the debugger:
version

5.7.1
(Expected behaviour)version

6.0.0
(Incorrect behaviour)The text was updated successfully, but these errors were encountered: