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 Apollo Managed federation #28

Open
StarpTech opened this issue May 21, 2021 · 2 comments
Open

Support Apollo Managed federation #28

StarpTech opened this issue May 21, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@StarpTech
Copy link

StarpTech commented May 21, 2021

The difference between federation is that the gateway is no longer responsible to specify the service configurations. The entire composed graph is fetched by the gateway. This allows to dynamically adding and removing services and schema updates without restarting the gateway.

https://www.apollographql.com/docs/rover/supergraphs

Specs:

Example:

https://github.com/StarpTech/graphql-registry/tree/main/examples/apollo-managed-federation

@mcollina
Copy link
Contributor

mcollina commented May 21, 2021

I think this is extremely simple to add, we should just expand refresh() to accept a new list of services. Or maybe does this include a little bit more work?

@StarpTech
Copy link
Author

StarpTech commented May 21, 2021

That would be a limited workaround. Apollo produces a supergraph-sdl that includes service endpoints and the federated schema. The gateway is only responsible to read the schema and make the federated schema working.

For example, based on the federation example:

schema
  @core(feature: "https://specs.apollo.dev/core/v0.1"),
  @core(feature: "https://specs.apollo.dev/join/v0.1")
{
  query: Query
}

directive @core(feature: String!) repeatable on SCHEMA

directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet) on FIELD_DEFINITION

directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on OBJECT | INTERFACE

directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

scalar join__FieldSet

enum join__Graph {
  ACCOUNTS @join__graph(name: "accounts" url: "http://localhost:4001/graphql")
  INVENTORY @join__graph(name: "inventory" url: "http://localhost:4004/graphql")
  PRODUCTS @join__graph(name: "products" url: "http://localhost:4003/graphql")
  REVIEWS @join__graph(name: "reviews" url: "http://localhost:4002/graphql")
}

type Product
  @join__owner(graph: PRODUCTS)
  @join__type(graph: PRODUCTS, key: "upc")
  @join__type(graph: REVIEWS, key: "upc")
  @join__type(graph: INVENTORY, key: "upc")
{
  upc: String! @join__field(graph: PRODUCTS)
  name: String @join__field(graph: PRODUCTS)
  price: Int @join__field(graph: PRODUCTS)
  weight: Int @join__field(graph: PRODUCTS)
  reviews: [Review] @join__field(graph: REVIEWS)
  inStock: Boolean @join__field(graph: INVENTORY)
  shippingEstimate: Int @join__field(graph: INVENTORY, requires: "price weight")
}

type Query {
  topProducts(first: Int = 5): [Product] @join__field(graph: PRODUCTS)
  me: User @join__field(graph: ACCOUNTS)
}

type Review
  @join__owner(graph: REVIEWS)
  @join__type(graph: REVIEWS, key: "id")
{
  id: ID! @join__field(graph: REVIEWS)
  body: String @join__field(graph: REVIEWS)
  author: User @join__field(graph: REVIEWS, provides: "username")
  product: Product @join__field(graph: REVIEWS)
}

type User
  @join__owner(graph: ACCOUNTS)
  @join__type(graph: ACCOUNTS, key: "id")
  @join__type(graph: REVIEWS, key: "id")
{
  id: ID! @join__field(graph: ACCOUNTS)
  name: String @join__field(graph: ACCOUNTS)
  username: String @join__field(graph: ACCOUNTS)
  reviews: [Review] @join__field(graph: REVIEWS)
}

@mcollina mcollina added the enhancement New feature or request label May 21, 2021
@codeflyer codeflyer transferred this issue from mercurius-js/mercurius Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants