graphql-modules icon indicating copy to clipboard operation
graphql-modules copied to clipboard

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

Open rahul22048 opened this issue 5 years ago • 6 comments

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?

rahul22048 avatar Nov 26 '20 04:11 rahul22048

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.

kamilkisiela avatar Nov 26 '20 08:11 kamilkisiela

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

rahul22048 avatar Nov 26 '20 09:11 rahul22048

Monday 🥳

kamilkisiela avatar Nov 26 '20 09:11 kamilkisiela

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

rahul22048 avatar Nov 26 '20 09:11 rahul22048

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()?

hparfen avatar Dec 10 '20 17:12 hparfen

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?

TravisDimmig-Intelex avatar Nov 14 '23 16:11 TravisDimmig-Intelex