type-graphql
type-graphql copied to clipboard
Directives and astNode
Describe the Bug
When using graphql-modules
with type-graphql
and @Directive
decorator functionality - unexpected behaviour was spotted.
It turned down to printSchemaWithDirectives
function from graphql-tools
.
Specifically this and this 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.
- 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 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.
- Custom type case:
in
type-graphql
's version there are noastNode.fields
- which prevents this part of handlingdirectives
.
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.
If you agree on this change - i'll try to prepare PR.
I'm not sure what is the issue you're describing but sure, you can try to illustrate that with a PR 😉
It seems like I'm having the same issue. Though it took me some time to figure out where the issue is located 😅
At first I thought the issue was happening withgraphql-modules
, but that doesn't seem be the case. I tried the first script from this issue https://github.com/Urigo/graphql-modules/issues/453 and that worked like a charm. So directives worked in graphql-modules
.
When I tried to alter this script by adding the types using type-graphql
the directive wasn't triggered, presumably due to the issue described above.
When I skipped my GraphQL Modules and directly build my schema using Type-Graphql alone, my directives worked. So I can definitely confirm that the combination between GraphQL-Modules (or graphql-tools
as was mentioned) and Type-GraphQL is what makes my code fail.
@rostislavv did you manage to fix or workaround the issue by any change? And you said you are able to make a PR? Because I don't know where to begin and I'd love to continue using Type-GraphQL.
@rostislavv @harm-less Did you manage to start on a PR?
@MentalGear
I'm not sure what is the issue you're describing