Support for Apollo Federation
A while ago Apollo introduced a new strategy for merging GraphQL schemas together in a more sensible way than schema stitching. It would be great to see this supported in Lighthouse too.
https://www.apollographql.com/docs/apollo-server/federation/introduction/ https://www.apollographql.com/docs/apollo-server/federation/federation-spec/
IssueHunt Summary
Backers (Total: $0.00)
Become a backer now!
Or submit a pull request to get the deposits!
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
Are you willing to work on this?
I'm also searching for a way to implement it. Anyone else working on it?
I could try but I don't think that I have a good enough understanding of the code to make that big implementations yet.
I'm trying to implement this too. Does anybody found some clear information about this specification, or examples from other implementations?
@RPSimon here's a Ruby implementation of it https://github.com/Gusto/apollo-federation-ruby
We're happy to fund development of this if anyone is interested!
Hey, if no one is doing this right now, I would read the specs and try to implement this.
@renepardon go for it!
Make sure to check out https://github.com/nuwave/lighthouse/blob/master/CONTRIBUTING.md to get going. We put a big emphasis on tests!
I came across the following idea:
key Directive: https://gist.github.com/renepardon/6751168cc12bc9b32f32c7897169d112 federation Query: https://gist.github.com/renepardon/58b34ba1be427fade9cd2f8020dd1d89 federation.graphql: https://gist.github.com/renepardon/a5a65a050893d56a8a9994b70c475a11 example schema.graphql: https://gist.github.com/renepardon/3654a2be62a1d7dc629126e386adfa7c
And last but not least an additional method within the SchemaPrinter class:
/**
* @param Schema $schema
* @param array $options
*
* @return string
*/
public static function printFederatedSchema(Schema $schema, array $options = []): string
{
$fields = $directives = [];
$originalQueryType = $schema->getQueryType();
$federationFields = ['_service', '_entities'];
$federationDirectives = ['external', 'requires', 'provides', 'key', 'extends'];
foreach ($originalQueryType->getFields() as $key => $field) {
if (in_array($key, $federationFields)) {
continue;
}
$fields[] = $field;
}
foreach ($schema->getDirectives() as $directive) {
if (in_array($directive->name, $federationDirectives)) {
continue;
}
$directives[] = $directive;
}
$queryType = new ObjectType([
'name' => 'Query',
'fields' => $fields,
'interfaces' => $originalQueryType->getInterfaces(),
]);
$newSchema = new Schema([
'query' => $queryType,
'mutation' => $schema->getMutationType(),
'subscription' => $schema->getSubscriptionType(),
'directives' => $directives,
]);
return self::printFilteredSchema(
$newSchema,
static function (Directive $type) {
return !Directive::isSpecifiedDirective($type);
},
static function ($type) {
return !Type::isBuiltInType($type);
},
$options
);
}
What's missing so far? Within the printFilteredSchema I have the option federated available but the @key(...), @extends etc. directives are not yet printed into the sdl field of _Service type.
Maybe you have an idea how to do this without extending the ObjectType.
@renepardon - My team would be happy to help you work on a solution to this. What is the best way to get involved?
@jerredhurst Right now I no longer work on it. I switched to NestJS
@renepardon could you put up your WIP as a PR?
Is anyone working on it?
@RodriigoGS Feel free to continue https://github.com/nuwave/lighthouse/pull/1051
@renepardon @RodriigoGS i pulled the changes of #1051 to a branch. Whoever wants to work on it can fork and branch from there. Thanks
Is anyone actively looking at this? I have a team that's interested in developing GraphQL servers using Lighthouse, but we're using Apollo Federation and would need that support to really make it work.
https://github.com/webonyx/graphql-php/issues/552 is still open. Problem is also that most of the methods used within the graphql-php library are private which makes it pretty hard to extend/adjust the library as required for federation to work. You need to copy a lot of things just to make small adjustments within the schema printer. And I don't think it's a good idea to do so. This way you would just manage your own version of GraphQL library.
Let's see if we can make the SchemaPrinter extendable at least: https://github.com/webonyx/graphql-php/issues/552#issuecomment-641105589
I would be fine with maintaining a modified version of the SchemaPrinter for Federation, as it seems to be a really popular and useful addition to Lighthouse.
Would php-graphql-federation help? It’s built to extend webonyx/graphql-php with federation and recommend by Apollo.
Feel free to fork, branch from https://github.com/nuwave/lighthouse/tree/federation and give it a try.