magidoc
magidoc copied to clipboard
Show directives applied to a field/query
We must find a way to show the directives applied to a given field, since some directives may contain useful information, like validations and permissions.
Well, apparently this is not possible at the moment, because directives are not conserved in the introspection: https://github.com/graphql/graphql-spec/issues/300
This would require reading the schema in a different format than the introspection query (like AST JSON format). I don't know if it's possible, but in any case, this is not a low hanging fruit.
After some digging, I discovered that this is possible if we pass the SDL
directly to the template rather than the introspection
JSON. It does have the downside that this feature will only be available if magidoc uses the SDL files directly, and will not work when using any of the other method to provide introspection.
See
-
graphql.js: printSchema
(converts a schema to SDL) -
schema.getQueryType().getFields()["search"].astNode.directives
(get directives on a field) -
schema.getQueryType().getFields()["search"].args[0].astNode.directives
(get directives on an argument)
This has been implemented and merged!