Repository navigation
Apply directives and @specifiedBy to scalars - #894
Open
oryan-block wants to merge 1 commit into
Open
oryan-block wants to merge 1 commit into
oryan-block wants to merge 1 commit into
Conversation
Scalars were rebuilt in SchemaClassScanner from the provided GraphQLScalarType with only its name, description and coercing, so directives from the SDL, @specifiedBy, the provided specifiedByUrl and onScalar wiring were all lost. Co-Authored-By: Claude <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 #864
Checklist
Description
SchemaClassScannerrebuilt every custom scalar from the providedGraphQLScalarTypewith only its name, description and coercing. So directives from the SDL never made it, on the scalar or onextend scalar, and neither did@specifiedBy, the provided scalar'sspecifiedByUrlorSchemaDirectiveWiring.onScalar:printed as
scalar Date, and introspection returnedspecifiedByURL: null.Now
SchemaParserbuilds scalars like the other types:directivesOf,buildAppliedDirectives/buildDirectivesatSCALAR, then the newDirectiveWiringHelper#wireScalar. The scanner only checks that each scalar the schema uses was provided.Main issue is that graphql-java compares types by identity, so every field, argument, input field and directive argument has to hold the same scalar instance. And a scalar's directives can take that scalar as an argument (
directive @since(date: Date)+scalar Date @since(date: "2020-01-01")). So:SchemaParser#scalarTypebuilds a scalar the first time it's looked up and keeps it. It's the only way to get one now.SchemaDirectivesbuilds the scalars that apply no directives and uses a type reference for the rest.Date's own@since(date:). graphql-java replaces it when it builds the schema, but insideonScalargetValue()on that argument returnsnull.What wins when both set something: the SDL description, then the provided one (same as before). The SDL
@specifiedBy, then the providedspecifiedByUrl. The provided scalar's own directives are dropped, like graphql-java'sSchemaGeneratordoes and like before this change. Copying them meant fixing up their argument types and dealing with undeclared ones, for something nobody asked for.Release notes:
@specifiedByandonScalarwiring. Static directive wirings and aWiringFactorynow getonScalarcalls for custom scalars too.specifiedByUrl(e.g. from extended scalars) now shows up in introspection, and in the printed schema with graphql-java 26.@specifiedBy(url: 5)) now fails the build in graphql-java's schema validation, like on every other type. Before it built because the directive was ignored.Tests: scalar cases in
TypeExtensionTest(directives of the scalar and its extension, wired) andDirectiveTest(SDL vs providedspecifiedByUrland description through introspection, the cycle above in both declaration orders, the undeclared directive warning, and a custom scalar argument read during wiring when its directive is applied inside its own argument type). They all fail on master except the last one, which passes on master and guards a regression an earlier version of this change had.mvn clean verifypasses on JDK 25 against graphql-java 26.1 and 25.1.Also checked through the public API with a probe app (SDL file,
.scalars(...), a wiring per directive). On master the scalars print bare and everyspecifiedByURLisnull. On this branch:DateTime's URL comes from the provided scalar. The@since(null)is the reference case above. Same results with graphql-java 25.1 at runtime, except its printer doesn't show a URL that only the provided scalar sets (introspection does).