php-graphql-federation icon indicating copy to clipboard operation
php-graphql-federation copied to clipboard

Issues with Redefinition and missing @key

Open dougogodinho opened this issue 5 years ago • 1 comments

Hey friend, thanks for sharing your code... Im having the folowing issue:

Directive "external" already exists in the schema. It cannot be redefined.
Directive "requires" already exists in the schema. It cannot be redefined.
Directive "provides" already exists in the schema. It cannot be redefined.
Directive "key" already exists in the schema. It cannot be redefined.
Directive "extends" already exists in the schema. It cannot be redefined.

Any idea?

dougogodinho avatar Feb 18 '20 13:02 dougogodinho

Yep. I'm getting that too.

Here's a quick workaround that's working for me...

  1. Add the following to your schema:
type Query {
  … other stuff in your query root here
  _service: _Service!
}

type _Service {
  sdl: String
}
  1. Remove your call to $federation->extendSchema but leave the one for addResolversToRootValue

Explanation: The Apollo docs are a bit unclear on this, but the _service query is meant to return your service definition without additional directives declared:

This SDL does not include the additions of the federation spec above.

The extendSchema function adds all that stuff to the schema (which is correct), but then the resolver for _service returns the full schema unmodified, so Apollo gets upset that you didn't strip that stuff out before generating the SDL

I'll get a PR together if I have time.

angry-dan avatar Mar 11 '20 08:03 angry-dan