Skip to content

Support for Apollo Federation #1728

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

Merged
merged 67 commits into from
Apr 22, 2021
Merged

Support for Apollo Federation #1728

merged 67 commits into from
Apr 22, 2021

Conversation

spawnia
Copy link
Collaborator

@spawnia spawnia commented Feb 8, 2021

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

Resolves #911

Changes

Allows Lighthouse to function as a federation capable service in Apollo Federation.

Breaking changes

No.

@tristanpemble
Copy link

tristanpemble commented Feb 9, 2021

hello! I was in the middle of trying to implement Apollo Federation in Lighthouse myself. from what I could tell, there was no good way to extend the webonyx/graphql-php schema printer to handle printing directives due to the use of static methods. I ended up adapting it to write my own. I did not expect to share this, and went a little crazy with generators as an experiment for cleaner reading code/ease of extensibility. however, it seems to function well. take whatever you need: https://gist.github.com/tristanpemble/f6d427034a33a06392f44ed17fb278dc

you should, in theory, be able to just throw this into your code and call FederationSchemaPrinter::printFederationSchema($schema) in place

@tristanpemble
Copy link

it would seem the repo linked in the original report has a much simpler extension of SchemaPrinter

@spawnia
Copy link
Collaborator Author

spawnia commented Feb 10, 2021

Thank you @tristanpemble, that was some good inspiration :)

@tristanpemble
Copy link

from what I see most of what is needed for federation is implemented - is there anywhere else I can help (maybe just by testing it out)?

@spawnia
Copy link
Collaborator Author

spawnia commented Feb 10, 2021

I am not quite sure how to interpret https://www.apollographql.com/docs/federation/federation-spec/#create-stub-types

A federated service should take the @external fields and types and create them locally so the service can run on its own.

Do we need some kind of mocking / generator?

@tristanpemble
Copy link

tristanpemble commented Feb 11, 2021

hm. I am definitely not an expert on this, but, I interpret that sentence as leaving the onus on the end-user and not on the framework. I'm not sure how you would automatically mock out types/fields from other federated services if the user did not provide them.

I think the take away from that section could impact this implementation could be here:

All fields referred to in @key, @requires, and @provides directives need to have corresponding @external fields in the same service.

perhaps you could insert schema validation wrapped in helpful messaging for the library user to tell them they need to define the external type or field in their schema if it is not present.

@tristanpemble
Copy link

tristanpemble commented Feb 11, 2021

I dug a little deeper on the official JS implementation, I think these validations will help you: https://github.com/apollographql/federation/tree/main/federation-js/src/composition/validate

specifically these are similar to what I was imagining:

anyway, I think digging through their validations will help! it could be that some of these are used from their gateway only, and not the federated service.

edit: after a little more digging I think that all of these validations are from the gateway on composition :) I think still a helpful reference to make sure you are compliant

@spawnia spawnia added the enhancement A feature or improvement label Feb 13, 2021
@spawnia spawnia marked this pull request as ready for review April 22, 2021 17:55
@spawnia spawnia merged commit 678d447 into master Apr 22, 2021
@spawnia spawnia deleted the federation branch July 18, 2021 20:36
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
Development

Successfully merging this pull request may close these issues.

Support for Apollo Federation
2 participants