Repository navigation
Check scalar arguments when building the schema - #891
Merged
Merged
Conversation
The data fetchers looked each argument's type up in the request's schema. The scanner already knows the scalar names, so each argument is checked once when its data fetcher is created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rough A [[String]] argument for a List<Set<String>> parameter was passed through as a list of lists, because every list level checked the outer parameter type. Each level now checks its element type, so the inner lists are converted to sets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #859
Checklist
Description
MethodFieldResolverpasses an argument straight to the resolver only if the value already fits the parameter class and the argument is a scalar other thanID. Otherwise it converts it with Jackson. To know if the argument is a scalar, it looked the type name up inenvironment.graphQLSchema, for every argument on every call.Now
SchemaClassScannerpasses the scalar names (spec scalars +scalardefinitions in the SDL) throughFieldResolverScannertoMethodFieldResolver, andcreateDataFetcherdecides once per argument. The data fetchers don't read the schema anymore, so the environments inMethodFieldResolverDataFetcherTestno longer need the schema #849 gave them.The answer stays the same: an argument type has to be a spec scalar or be defined in the SDL, otherwise
TypeClassMatcherrejects it at build. Every scalar in the built schema comes from one of those two. About theSchemaTransformerquestion in the issue, the runtime lookup would only give a different answer if something replaced a scalar with a non-scalar type of the same name after the build. I can't think of a reason anyone would do that.Also fixed the list case while I was in there (slice 2 of the resolver type cleanup, no issue). Each list level checked the outer parameter type instead of its element type. So this built:
But the list of lists was passed through unconverted, and every call failed with:
Now each level checks its element type, so Jackson converts the inner lists to sets.
List<List<String>>is still passed through like before. One side effect is thatList<Collection<String>>now goes through Jackson instead of being passed through, with the same values. RawListparameters can't hit this because they already fail at build ("generic type information was lost").Release note: a nested list argument for a parameter with a non-
Listinner collection, e.g.[[String]]forList<Set<String>>, is now converted instead of failing with aClassCastException.Added a
MethodFieldResolverTestcase for nested sets ofStringand of a custom scalar. Both failed with theClassCastExceptionbefore the fix.mvn clean verifypasses on JDK 25, against graphql-java 26.1 and 25.1.Also checked through the public API with a custom scalar Jackson can't build (
Tagand[Tag!]!),IDinto aLongparameter, and[[String!]!]!intoList<Set<String>>andList<List<String>>. On master the nested sets query fails with theClassCastExceptionand the other three return the same results as on this branch. On this branch all four work, also with graphql-java 25.1 at runtime.