-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Directives from Scalar/Enum/Input/Type/Interface extensions #2512
Directives from Scalar/Enum/Input/Type/Interface extensions #2512
Conversation
fe6ad4d
to
0a01356
Compare
Seems it will not work. So, I don't know how to extend directives for standard types and thus they will be processing like custom scalars. This is means that the following graphql will do nothing (the same as before the PR). scalar Int @scalar(class: "xxx")
extend scalar Int @directive(location: "extend") Also, another possible BC: if the |
9b8fb41
to
b8dd562
Compare
Looks like failed tests are not releated to the PR |
Yep, these tests are randomly failing. Just re-run them. |
Do you have a use cases for changing the standard types? If not, I would rather not spend effort on it. |
Yep, for
Me too. Maybe will be easy to implement it after webonyx/graphql-php#1426 (but I didn't dig into pr) |
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 ↩