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
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鈥檚 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.
@matthewhall-ca has funded $200.00 to this issue.
Looking to fund to get this developed - feel free to email my address on my profile if you want to discuss specifics or need a larger bounty for this feature
If nobody else is interested, I can see it in my spare time.
Hey everyone, I've setup a simple package that provides Federation support for Lighthouse (service only).
A few things to note:
I hope someone who's willing to implement this as a core feature can find a good starting point in the repo. Also thanks to everyone who tried implementing this - definitely helped a lot!
You can find the repo here: https://github.com/awardis/federation
If you have trouble getting this package to work I'm willing to provide an example project.
@matthewhall-ca Bounty goes to the one implementing this into core :-)
I have been talking to @matthewhall-ca and will look into supporting this.
Removing the funds from Issue Hunt as @spawnia and I have discussed direct compensation over email
@matthewhall-ca has cancelled funding for this issue.(Cancelled amount: $200.00) See it on IssueHunt
Hi, is this still something that is being worked on?
https://github.com/nuwave/lighthouse/pull/1728 has a working version. There is a little bit of work to be done, mostly documentation. I plan to release it as an experimental feature soon.
Released as an experimental feature as of https://github.com/nuwave/lighthouse/releases/tag/v5.6.0. Thanks to everyone involved and in particular @matthewhall-ca for getting this funded.
Most helpful comment
I have been talking to @matthewhall-ca and will look into supporting this.