php-graphql-federation
php-graphql-federation copied to clipboard
Issues with Redefinition and missing @key
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?
Yep. I'm getting that too.
Here's a quick workaround that's working for me...
- Add the following to your schema:
type Query {
… other stuff in your query root here
_service: _Service!
}
type _Service {
sdl: String
}
- Remove your call to
$federation->extendSchemabut leave the one foraddResolversToRootValue
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.