Generated schema.graphql does not include directive usages

I am testing some GraphQL documentation generators and trying to use .redwood/schema.graphql as input (instead of introspection). I noticed while testing that the generated .redwood/schema.graphql does not include directive usages on objects.

The directives themselves are defined, for example my generated file has:

directive @requireUserAuth(roles: [String]) on FIELD_DEFINITION
directive @skipAuth on FIELD_DEFINITION

But that is the only place those directives appear in the generated file. The directives are all working correctly, I’m just trying to understand why they are not in the generated file.

For example I have an SDL that includes:

  type Query {
    likes: [Like!]! @requireUserAuth
    like(id: String!): Like @requireUserAuth
  }

And in the generated file it’s:

type Query {
  [...]
  like(id: String!): Like
  likes: [Like!]!
  [...]
}

But what I was expecting to see was:

type Query {
  [...]
  like(id: String!): Like @requireUserAuth
  likes: [Like!]! @requireUserAuth
  [...]
}

The only directive I do see in the generated file is @deprecated in a few places where we have used that.

Is this expected? Again, the directives are working fine. I’m just confused about where/how they are enforced (and I guess about what the function of .redwood/schema.graphql is).

On further review it seems this is the expected state of things – that custom directives don’t show up in generated schema.

This came up because a number of the GraphQL documentation generator tools can use directives to hide or show various pieces of the schema. But this can’t be used effectively without the custom directives on the generated schema.

What I ended up doing was to follow the documentation for setting up Docusaurus and modifying the plugins configuration to load both the generated schema and the code files. This doesn’t quite fit my use case (I want to hide most of the schema) but it’s definitely workable.

Example plugins configuration:

plugins: [
    [
      '@graphql-markdown/docusaurus',
      {
        baseURL: 'graphql-api',
        groupByDirective: {
          directive: 'doc',
          fallback: 'Undocumented',
          field: 'category',
        },
        linkRoot: '../../..',
        loaders: {
          CodeFileLoader: '@graphql-tools/code-file-loader',
          GraphQLFileLoader: '@graphql-tools/graphql-file-loader',
        },
        printTypeOptions: { useApiGroup: false },
        rootPath: './docs',
        schema: ['../.redwood/schema.graphql', '../api/src/graphql/*.sdl.ts'],
      },
    ],
  ],

With a custom directive like this:

directive @doc(
  category: String
) on ENUM | FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | UNION