MichalLytek / MichalLytek/type-graphql
Directives and astNode
- Dominant language
- TypeScript
- Stars
- 8.1k
- Forks
- 672
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the Bug**
When using `graphql-modules` with `type-graphql` and `@Directive` decorator functionality - unexpected behaviour was spotted.
It turned down to [`printSchemaWithDirectives`](https://github.com/ardatan/graphql-tools/blob/ae7c968deb/packages/utils/src/print-schema-with-directives.ts#L21) function from `graphql-tools`.
Specifically [this](https://github.com/ardatan/graphql-tools/blob/ae7c968deb/packages/utils/src/print-schema-with-directives.ts#L21) and [this](https://github.com/ardatan/graphql-tools/blob/ae7c968deb/packages/utils/src/print-schema-with-directives.ts#L92) place.
It seems that `astNode` representation in `type-graphql` has slight mismatch between one produced by `makeExecutableSchema`, affecting (in this case) `type-graphql` and `graphql-modules` integration (specifically for `directives`).
**To Reproduce**
It has the following effect - directives on `type` and on `input` are present, but on their fields - they are lost.
1. Case of `type Query`:

where `result` was created by `makeExecutableSchema` (from graphql-tools also), and `buildedSchema` was created by `buildSchemaSync`.
In this case `type-graphql`'s version don't have `astNode` for `type Query`. Thus [this place](https://github.com/ardatan/graphql-tools/blob/ae7c968deb/packages/utils/src/print-schema-with-directives.ts#L90) is omitted (due to `undefined`) and fields of `type Query` lost their directives meta. This probably will take place for `type Mutation`, and for `type Subscription` too.
2. Custom type case:

in `type-graphql`'s version there are no `astNode.fields` - which prevents [this part ](https://github.com/ardatan/graphql-tools/blob/ae7c968deb/packages/utils/src/print-schema-with-directives.ts#L92) of handling `directives`.
**Expected Behavior**
`astNode` of `type` and `root types` exists, and it provides `fields` (if present) to avoid directives lost in case of usage with other libraries (this affects `graphql-tools` and `graphql-modules`, but might affect others, if they are using `graphql-tools`).
If you agree with this change - i'll try to prepare PR.
Contributor guide
Assessment
This issue has not been assessed yet.