Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Apollo Federation #911

Closed
juusopiikkila opened this issue Aug 12, 2019 · 33 comments · Fixed by #1728
Closed

Support for Apollo Federation #911

juusopiikkila opened this issue Aug 12, 2019 · 33 comments · Fixed by #1728
Labels
enhancement A feature or improvement

Comments

@juusopiikkila
Copy link
Contributor

juusopiikkila commented Aug 12, 2019

Issuehunt badges

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

@spawnia
Copy link
Collaborator

spawnia commented Aug 12, 2019

Are you willing to work on this?

@sl0wik
Copy link

sl0wik commented Aug 13, 2019

I'm also searching for a way to implement it. Anyone else working on it?

@spawnia spawnia added the enhancement A feature or improvement label Aug 13, 2019
@juusopiikkila
Copy link
Contributor Author

I could try but I don't think that I have a good enough understanding of the code to make that big implementations yet.

@RPSimon
Copy link

RPSimon commented Sep 4, 2019

I'm trying to implement this too. Does anybody found some clear information about this specification, or examples from other implementations?

@MatthewHallCom
Copy link

@RPSimon here's a Ruby implementation of it https://github.com/Gusto/apollo-federation-ruby

@MatthewHallCom
Copy link

We're happy to fund development of this if anyone is interested!

@renepardon
Copy link

renepardon commented Oct 15, 2019

Hey,
if no one is doing this right now, I would read the specs and try to implement this.

@spawnia
Copy link
Collaborator

spawnia commented Oct 15, 2019

@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!

@renepardon
Copy link

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.

@jerredhurst
Copy link

@renepardon - My team would be happy to help you work on a solution to this. What is the best way to get involved?

@renepardon
Copy link

@jerredhurst Right now I no longer work on it. I switched to NestJS

@spawnia
Copy link
Collaborator

spawnia commented Nov 10, 2019

@renepardon could you put up your WIP as a PR?

renepardon added a commit to renepardon/lighthouse that referenced this issue Nov 20, 2019
renepardon added a commit to renepardon/lighthouse that referenced this issue Nov 21, 2019
renepardon added a commit to renepardon/lighthouse that referenced this issue Nov 21, 2019
renepardon added a commit to renepardon/lighthouse that referenced this issue Nov 25, 2019
renepardon added a commit to renepardon/lighthouse that referenced this issue Nov 25, 2019
renepardon added a commit to renepardon/lighthouse that referenced this issue Nov 25, 2019
@RodriigoGS
Copy link

Is anyone working on it?

@renepardon
Copy link

@RodriigoGS Feel free to continue #1051

@spawnia
Copy link
Collaborator

spawnia commented Jan 30, 2020

@renepardon @RodriigoGS i pulled the changes of #1051 to a branch. Whoever wants to work on it can fork and branch from there. Thanks

@gwardwell
Copy link

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.

@renepardon
Copy link

renepardon commented Jun 9, 2020

webonyx/graphql-php#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.

@spawnia
Copy link
Collaborator

spawnia commented Jun 9, 2020

Let's see if we can make the SchemaPrinter extendable at least: webonyx/graphql-php#552 (comment)

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.

@gwardwell
Copy link

gwardwell commented Jun 9, 2020

Would php-graphql-federation help? It’s built to extend webonyx/graphql-php with federation and recommend by Apollo.

@spawnia
Copy link
Collaborator

spawnia commented Jun 9, 2020

Feel free to fork, branch from https://github.com/nuwave/lighthouse/tree/federation and give it a try.

@issuehunt-oss
Copy link

issuehunt-oss bot commented Feb 2, 2021

@matthewhall-ca has funded $200.00 to this issue.


@MatthewHallCom
Copy link

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

@RodriigoGS
Copy link

RodriigoGS commented Feb 2, 2021

If nobody else is interested, I can see it in my spare time.

@tommyschmiedel
Copy link

Hey everyone, I've setup a simple package that provides Federation support for Lighthouse (service only).

A few things to note:

  • It's a draft implementation that does not provide tests
  • Lighthouses TypeRegistry and FieldFactory currently don't provide AST Nodes in the resolved types. That's why the package includes a patch file (see readme). It's a small change that can easily be fixed in Lighthouse itself
  • The package provides a simple mechanism for resolving entities (see readme), but the final approach should be discussed by the community
  • Relations currently have to be resolved by custom resolvers/builders. Maybe there is a way this can be done nicely; much like relationships work in Lighthouse itself

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 :-)

@spawnia
Copy link
Collaborator

spawnia commented Feb 3, 2021

I have been talking to @matthewhall-ca and will look into supporting this.

@MatthewHallCom
Copy link

Removing the funds from Issue Hunt as @spawnia and I have discussed direct compensation over email

@issuehunt-oss
Copy link

issuehunt-oss bot commented Feb 14, 2021

@matthewhall-ca has cancelled funding for this issue.(Cancelled amount: $200.00) See it on IssueHunt

@sebbZA
Copy link

sebbZA commented Apr 20, 2021

Hi, is this still something that is being worked on?

@spawnia
Copy link
Collaborator

spawnia commented Apr 20, 2021

#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.

@spawnia
Copy link
Collaborator

spawnia commented Apr 22, 2021

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.

@KaduMoura
Copy link

Hi,

I'm looking for which graphql federation gateway to use, there's not much in the lighthouse docs. And in there says that the lighthouse itself cannot be used as a gateway.

What are you guys using as a gateway for the lighthouse federation?

Any info would be greatly appreciated.

Sorry for posting in here, but i don't know where else I could post it.

Thanks!

@MatthewHallCom
Copy link

@KaduMoura You just use the main Federation server thats from Apollo (written in Javascript).

https://www.apollographql.com/docs/federation/

You put it in front of your various Laravel Lighthouse servers using Federation.

If you have any other questions feel free to email me at the email on my profile

@KaduMoura
Copy link

Thanks!!!

You are awesome!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet