Is there any way to read GraphQL Directives on a Type with Query Introspection?

Viewed 1131

For use cases like authentication it may be of use to add custom directives to a GraphQL schema as shown in the documentation: https://www.graphql-java.com/documentation/v16/sdl-directives

For example the Employee type has a salary field that had a directive on it meaning that only the manager role is allowed to read it:

directive @auth(role: String!) on FIELD_DEFINITION

type Employee {
  id: ID
  name: String!
  startDate: String!
  salary: Float @auth(role: "manager")
}

From the client side I would like to be able to read these directives on the Employee type using an Introspection query.

Is that possible at all? Would you be able provide a sample query for the example above?

1 Answers

This is not currently supported by GraphQL. You can use introspection to find out what directives exist in the schema, but you cannot use it to find out which fields had directives applied to them. You can see additional discussion around this issue here.

Related