Open leebyron opened 6 years ago
Currently working on a PR for this issue. I am going to make it more strict, for now. So we will validate all of:
SCHEMA
directive on a type definition.My plan is to add this within the validateSchema
function, as we already are doing a minor bit of directive validation there.
I'm also working on it for a couple of weeks and I tried a few different approaches. Currently, I'm working on creating validateSDL
and an accompanying set of rules. Idea is to share the majority of code with validate
function and reuse some of the existing rules. For example:
directives are only used once per location in the schema
A few benefits:
validateSchema
will fail if you didn't define query type).@mjmahone What do you think about this aproach? I will try to publish WIP PR tomorrow.
@IvanGoncharov that sounds like you're further along than me. I want basically everything you described, but I am willing to take a shortcut and just extend validateSchema
to get this out sooner. I've got all the validation (I think) working as-is (putting up a PR imminently).
On thing is that I really want to have us push 14.0.0
as soon as possible. I keep reaching for the "schema directive" tool and then remembering "oh right, that won't be available until we release 14." I don't think my work would be difficult to undo, though, so we could always publish a 14.1
where we switch validateSchema
to be run purely on the schema AST nodes.
I don't think my work would be difficult to undo, though, so we could always publish a 14.1 where we switch validateSchema to be run purely on the schema AST nodes.
validateSchema
is part of public API and people using it:
https://github.com/search?q=graphql+validateSchema+-filename%3AvalidateSchema&type=Code
Also some 3rd-party implementations synchronise their codebase with graphql-js
after each release, e.g. graphql-php
.
It's not a super big problem but still moving functionality from one public function to another is a breaking change.
Can you wait until monday morning your time? I will limit scope of my PR to two checks you implemented in your PR and it should take me 1-2 days together with tests.
Yup I will wait. I would much rather have validation that can be run on the SDL AST than on an already-created schema, and like that this validation would mirror what we already do with validate
.
@IvanGoncharov if there's a branch I could work on top of, or if you want me to create that branch, I might be able to add more validation, or move more validation from validateSchema to individual SDL validation rules.
if there's a branch I could work on top of, or if you want me to create that branch, I might be able to add more validation, or move more validation from validateSchema to individual SDL validation rules.
I'm trying to figure out if it's possible to reuse the same context for buildSchema and extendSchema since they are totally different use cases so I'm mostly figuring API for ValidationContext. I will reuse tests from your PR and I will try to push WIP PR after I have stable API to get feedback from you.
@mjmahone Update: I finally figured out how to solve the last major problem. I will open a couple of PRs implementing this feature in the next few hours.
@IvanGoncharov is there more SDL validation you think we need prior to the 14.0 release? If so, anything I can do to help push it forward? I'd like us to put up at least an RC release by Monday if possible.
@mjmahone Sorry for the silence. I'm working on a PR that will add a few more rules. I will push hard to publish it until Sunday morning your time so we can discuss the next steps.
I'd like us to put up at least an RC release by Monday if possible.
Monday seems reasonable due date for RC release 👍
@IvanGoncharov not sure what other validations you have in mind. But validating input types on Directive args would be nice. Down to help with this if needed. Thanks for the hard work. 💯
@IvanGoncharov I think with #1463, this release is ready for at least a public RC? If so, I can put up a PR to bump the version tomorrow. I should also be able to do the upgrade across Relay's packages as well, although we might wait to actually bump the Relay version (@kassens would know that process better than me).
But validating input types on Directive args would be nice.
@Hendrixer You absolutely right, we still don't validate directives fully since this rule doesn't support SDL: https://github.com/graphql/graphql-js/blob/master/src/validation/rules/ValuesOfCorrectType.js
But I think it less important and we could add this support later minor release. Since breaking change is not about fully validating directives but about forcing developers to actually define them. At the moment we validating
Down to help with this if needed.
It would be great if you try current master: https://github.com/graphql/graphql-js#want-to-ride-the-bleeding-edge And provide feedback on it. Here is an example of how directives could be specified: https://github.com/graphql/graphql-js/blob/463174438d913bc0a2bf16a8b36b27d2fc3a66a1/src/utilities/__tests__/extendSchema-test.js#L1292-L1303
@mjmahone In the last few weeks, I also discover a couple of pretty small issues that technically a breaking change. They all about removing a few obscure features so I will try to make PRs in a next few hours.
Is this feature still being considered? I ask because it's mentioned in https://github.com/ardatan/graphql-tools/issues/920. It's hard to trust/rely on directives when a graphql server can be started without directive functions and the directives in the SDL get skipped over/ignored.
I believe directive usage is validated now. Your issue over at graphql-tools https://github.com/ardatan/graphql-tools/issues/920#issuecomment-762265595 suggests that you have a slightly different ask, see my response over there
Well, validated in a sense that the directives have to exist, I don't know if the arguments are validated / coerced yet...
Thanks for the help, all I want is to ensure that the directive functions exist, although yes I believe that the original author of the issue on graphql-tools wants to verify that the implementation is also correct.
I've been trying this with 15.3.0 and 14.5.8 and finding that the directive functions don't have to exist, but I'll give it another go.
Any updates on validating the argument types?
https://spec.graphql.org/October2021/#sec-Values-of-Correct-Type seems to suggest that all literals should be validated, not just in executable. Shall we extend ValuesOfCorrectTypeRule.ts to SDL?
From #1383: