MichalLytek / MichalLytek/type-graphql

Directives and astNode

Open
#681 4 comments 0 reactions 1 assignee Claimed by @MichalLytek View on GitHub
Bug :bug: Community :family_man_girl: Need More Info :man_shrugging:
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`:
![type-Query](https://user-images.githubusercontent.com/11004125/90388730-f2b3bf00-e090-11ea-8d23-d9b2d57ab19a.png)

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:
![custom-type](https://user-images.githubusercontent.com/11004125/90389076-8eddc600-e091-11ea-822b-1b27d7af07a1.png)
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.