apollo-kotlin icon indicating copy to clipboard operation
apollo-kotlin copied to clipboard

Validation for custom schema directives

Open theBradfo opened this issue 3 years ago • 3 comments

Use case Our schema has a few custom server-side directives defined, but the validation does not seem to exist at code generation time when evaluating the GraphQL operation source.

Describe the solution you'd like Currently with the apollo introspected schema, the server directives are not written to the defined schema file from the introspection task. This makes validation likely not possible if these custom directives are added to the operation files. It would be great if these directives could be written to the introspected schema file output by apollo, and also validated in the operation source files. I realize that generated source with these directives is not yet possible (and detailed discussion present in #3985), but it would be great if at generation time these directives could at least be validated, to help prevent things like typos for example.

theBradfo avatar Jun 17 '22 14:06 theBradfo

Hi! 👋

Yes, it would certainly be possible to save the directives there. An additional plus is that their usage won't be red in the IDE when using the GraphQL plugin 😊

Would you be interested in trying a PR for this?

BoD avatar Jun 17 '22 16:06 BoD

If you could point me in the right direction i can maybe find some time to take this on 😁

theBradfo avatar Jun 17 '22 16:06 theBradfo

🙏

The downloading of the schema happens here.

The introspection query introspectionQuery already requests the directives, so that's ✅.

But then it's parsed here (using Moshi) into this model.

As you can see it doesn't have a directives field so the one from the json response is simply ignored.

Then this model is converted to a GQLDocument here - so that would need to be improved to use the added directives field.

The last step is to transform this GQLDocument to a SDL text - that part shouldn't need to be touched.

Once that's ✅, it looks like we already have validation in place here, so maybe that will be enough to avoid mistakes/typos etc.

BoD avatar Jun 17 '22 16:06 BoD