I have a simplified schema.graphql file with one type and one custom directive (at the field and object level). In Typescript, how can I programmatically get the type and type directive, and iterate over the fields and field directives?
type Test @myCustomDirective() {
id: String! @myCustomDirective()
}
This post says "This is not currently supported by GraphQL":
Is there any way to read GraphQL Directives on a Type with Query Introspection?
And the GitHub issue says this feature is being considered:
https://github.com/graphql/graphql-spec/issues/300
Then how is AWS AppSync doing this? See below.
// The following keeps custom directives:
parse(schema); // Return type: graphql.DocumentNode
// The following removes custom directives:
buildSchema(schema); // Return type: GraphQLSchema
- AWS AppSync > Export Schema > Schema.json does include custom directives but is an AWS AppSync specific solution and is an expensive API operation.
aws appsync get-introspection-schema --api-id abc123 --format JSON --include-directives output.json
I tried GraphQL Code Generator Introspection plugin. But it removes custom directives from types and fields.
https://www.graphql-code-generator.com/plugins/introspection
I tried graphql/utilities but it also removes custom directives from types and fields.
graphql.introspectionFromSchema(graphqlSchema)
// or
graphql.graphqlSync({ schema: graphqlSchema, source: graphql.getIntrospectionQuery() }).data as unknown as graphql.IntrospectionQuery;