async-graphql/docs/en/src/apollo_federation.md
2020-05-09 15:37:31 -07:00

1.2 KiB

Apollo Federation

Apollo Federation is a GraphQL gateway API which can combine multiple GraphQL services, allowing each srvice to implement the subset of the API it is responsible for. You can read more in the official documentation

Async-GraphQL supports all the functionality of Apollo Federation, but some modifications to your Schema are required.

  • You can use the extends property declaration on async_graphql::Object and async_graphql::Interface to extend a type offered by another implementing service.

  • The external property declares that a field comes from another service。

  • The provides property indicates the fields provided by a service.

The definition of a root Query type is slighly different. An entity search function must be defined. For example:

struct Query;

#[Object]
impl Query {
    #[entity]
    async fn find_user_by_id(&self, id: ID) -> User {
        User { id }
    }
}

This is equivalent to:

type User @key(id: ID!) {
    id: ID!,
}

For a complete example, refer to: https://github.com/async-graphql/examples/tree/master/federation