magidoc icon indicating copy to clipboard operation
magidoc copied to clipboard

Show directives applied to a field/query

Open pelletier197 opened this issue 2 years ago • 2 comments

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.

pelletier197 avatar Jun 06 '22 11:06 pelletier197

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.

pelletier197 avatar Jun 12 '22 18:06 pelletier197

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)

pelletier197 avatar Sep 06 '22 20:09 pelletier197

This has been implemented and merged!

pelletier197 avatar Dec 10 '22 12:12 pelletier197