Urigo / graphql-modules

Enterprise Grade Tooling For Your GraphQL Server
https://graphql-modules.com/
MIT License
1.31k stars 114 forks source link

Schema property inside GraphQLModule object is not assignable when it contains federation directives like @key #1460

Open rahul22048 opened 3 years ago

rahul22048 commented 3 years ago

i was trying to do something like this:-

const {schema} = module;

Module is a graphQLModule, in which typedefs has @key attribute (Apollo Federation way).

At this statement it throws error:- Unknown directive "key"

Earlier i was using 0.7.7 version of @graphql-modules/core, @graphql-modules/di, then i upgraded the versions to 0.7.17, but still the issue didn't go away.

Or is it the expected behaviour?

kamilkisiela commented 3 years ago

With new version (about to be released), if there's a definition for @key directive, somewhere in your application, even outside of the module that it's used it, it should be fine. We now build a schema on application level.

In v0 I think it's expected since every module should be executable, even on its own.

rahul22048 commented 3 years ago

@kamilkisiela :- would you like to comment on the tentative date of the new release?

kamilkisiela commented 3 years ago

Monday 🥳

rahul22048 commented 3 years ago

@kamilkisiela :- Thanks for your quick update. Kindly keep this ticket open. Once we integrate the new release, we will update here.

hparfen commented 3 years ago

Still experiencing this issue after upgrading to v1.0.0. Have definitions of federation directives added to the graphql file:

directive @key(fields: _FieldSet!) on OBJECT | INTERFACE

is producing the runtime error in buildFederatedSchema() later as it tries to add federation directives:

GraphQLSchemaValidationError: Directive "key" already exists in the schema. It cannot be redefined.

Removing the federation directive from the graphql file is causing the old problem in createApplication():

Error: Unknown directive "key".

Is it possible to unregister custom directives in the built application module before calling buildFederatedSchema()?

TravisDimmig-Intelex commented 11 months ago

Has anyone worked around this issue? I'm encountering it trying to use the testkit.testModule function. Exactly as @hparfen described if I just use the directive things work as expected at runtime but the test fails with the Error: Unknown directive "key" message. If I define that directive I can make the test pass, but at runtime I get the Directive "key" already exists in the schema. error.

It seems like the testkit must be skipping a step being taken at runtime that's able to resolve those directives?