graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Feature Request: Support Apollo Graphql Federation

Open StevenACoffman opened this issue 5 years ago • 15 comments

Feature Request:

Please consider supporting Graphql Federation. This does not necessarily mean implementing all of the Apollo Federation Spec in this library, but just what would be necessary for someone implementing Apollo Federation to use this library for that purpose.

https://www.apollographql.com/docs/apollo-server/federation/federation-spec/

Background:

We use hundreds of microservices, and a monolithic GraphQL server becomes an unacceptable development bottleneck and single point of failure, so it becomes necessary to divide the graph's implemention into separate parts. We tried schema stitching, but would prefer federation for three reasons:

  1. With federation, microservices all expose a proper part of the overall graph and can refer directly to types that live in other services, without the need to add foreign keys or superfluous relationship root fields to your schema.
  2. Federation is fully declarative and doesn't require any user code to be running in the gateway.
  3. Execution is efficient and predictable, because it relies on a query plan generated ahead of time with full knowledge of the overall query, instead of on runtime schema delegation that gets invoked as part of normal resolver-based execution.

StevenACoffman avatar Jul 01 '19 17:07 StevenACoffman

this seems outside the scope of this project.

bhoriuchi avatar Jul 04 '19 14:07 bhoriuchi

How so? Supporting the parts of the Apollo spec to allow others to use this project to build federated graphql microservices seems pretty in scope.

StevenACoffman avatar Jul 04 '19 14:07 StevenACoffman

Federation is an Apollo spec not a graphql spec. This library implements the graphql spec https://graphql.github.io/graphql-spec/June2018/ which has no mention of federation.

bhoriuchi avatar Jul 04 '19 21:07 bhoriuchi

Actually I apologize. I realize you are just asking this library to support the additions not federation itself. I believe the additions should be in scope

bhoriuchi avatar Jul 04 '19 21:07 bhoriuchi

No worries, I clarified my request. Sorry for not being more clear from the beginning.

StevenACoffman avatar Jul 04 '19 21:07 StevenACoffman

You could implement federation in a separate library. See for example: https://github.com/0xR/graphql-transform-federation. It takes an existing schema and with some configuration it can add federation support. Note that that is a NodeJS implementation, but I'm sure it could be implemented in Go as well.

If you're ok with running NodeJS you can add federation support to your Go service by using graphql-transform-federation as a middleware service. It can take a remote schema as input as well.

0xR avatar Oct 01 '19 07:10 0xR

@chris-cp

Is there interest in this library supporting this? I've read the federation spec a couple of times now and it seems at a high level this library would need to support:

  1. _service query would need this library to either support printing the schema as this spec describes or exposing the AST of a schema created with graphql.NewSchema so that another library could handle printing out the SDL.

  2. Stub types could probably already be implemented by another library, but again it would require we are able to read an AST in order to know what fields to implement a stub for. I wasn't able to find a way to get an AST from a schema created with graphql.NewSchema, but I might be overlooking it?

  3. Entities again could probably be implemented in another library provided this library is able to expose its AST so that we can create a union type as described in the spec.

  4. Directives should not need to be implemented as that appears to be entirely handled at the gateway level and not individual federated services.

It seems that this spec could be entirely implemented in another package as long as this package is able to expose its AST. If anyone has any thoughts or feedback I'm interested in hearing them. Also if @chris-cp is interested in supporting this but maybe does not have the time, then I would happy to take a shot and open a PR.

itmayziii avatar Nov 14 '19 03:11 itmayziii

Anyone knows about any library to handle this?

remorses avatar May 05 '20 12:05 remorses

gqlgen has supported it for some time.

StevenACoffman avatar May 05 '20 20:05 StevenACoffman

Federation is not exclusive to Apollo https://movio.co/blog/building-a-new-api-platform-for-movio/

luisdavim avatar Jul 28 '21 10:07 luisdavim

If someone es is looking for this, you can build your own with: https://github.com/jensneuse/graphql-go-tools

MoritzGruber avatar Nov 05 '21 17:11 MoritzGruber

Any plan to support this feature in the future?

ktutnik avatar Dec 28 '21 03:12 ktutnik

Huge +1! The team at MongoDB also uses this package for our hosted GraphQL API endpoint. It would be a great add-on feature on top of our generated GraphQL Schema and would be valuable to get customers on-board with adopting GraphQL more widely in their organizations in a scalable manner.

sumedhamehta avatar Feb 04 '22 02:02 sumedhamehta

I took a stab at implementing federation with this library and it seems like the primary blocker here is that we can't specify directives for types (ie, ObjectConfig doesn't support setting directives). It is also non-obvious if it is possible to render an SDL from a Schema object.

jesse-apollo avatar Feb 14 '22 16:02 jesse-apollo

Hello 👋 If anyone is interested I got a working example integration in https://github.com/apollographql/apollo-federation-subgraph-compatibility/tree/main/implementations/graphql-go

I forked graphql-go/graphql to get my PRs (https://github.com/graphql-go/graphql/pull/651, https://github.com/graphql-go/graphql/pull/652 and https://github.com/graphql-go/graphql/pull/653) merged and created new federation module -> https://github.com/dariuszkuc/graphql/tree/federation

I've also created a tag for easier integration -> https://github.com/dariuszkuc/graphql/releases/tag/v0.9.0-federation

Would love to get some feedback!

dariuszkuc avatar Nov 04 '22 14:11 dariuszkuc