Directives from Scalar/Enum/Input/Type/Interface extensions #2512
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.
extend scalar X
directives are lost #2509Changes
Directives defined in Scalar/Enum/Input/Type/Interface type extensions will be merged into target. The following schema will create type
A
with two directives@foo
and@bar
(previously only with@foo
).Custom scalars seems fine, but for standard (
Int
/String
/etc) the AST node is required. And I'm not sure how it should work.Technically, it is possible to add
scalar Int
, but it will not work without@scalar
1. Adding@scalar(class: "GraphQL\Type\Definition\IntType")
for standard scalars looks superfluous, IMHO. Moreover despitescalar Int @scalar(class: "My\Custom\Class")
is fully valid, but seems useless, becauseType::getStandardTypes()
has a bigger priority and thusMy\Custom\Class
will not be used (at least inSchema::getType()
).Another issue - to get directives we need AST node, standard types don't have it, so we probably need to assign it somewhere.
My proposal is to extend
TypeRegistry::resolveScalarType()
toextend Int @mydirective
)2.@scalar
What do you think?
Also, would be nice if someone can clarify usage of
scalar Int @scalar(class: "My\Custom\Class")
(allowed/should work or not).Breaking changes
ASTBuilder::missingBaseDefinition()
andASTBuilder::assertExtensionMatchesDefinition()
changed to acceptScalarTypeDefinitionNode
/ScalarTypeExtensionNode
extend scalar X
is used alone (= no scalar X defined it the schema) there will be an error that was not present before. But I think this is ok, because it works the same as for extending other types.Footnotes
Failed to find class Int extends GraphQL\Type\Definition\ScalarType in namespaces [App\GraphQL\Scalars] for the scalar Int. ↩
I'm not sure that is will work in all cases, will try to test it tomorrow ↩