Skip to main content

Apollo Federation

Apollo Federation is a specification for GraphQL servers to implement combining multiple services into a single GraphQL API. It is also an extension for Apollo Server that performs this combining. The GraphQL server combining multiple services into one is called a "gateway" in the GraphQL world.

Federation support in Saleor

Saleor supports Apollo Federation. Types that can be used in federated relations are part of the _Entity union.

Most types in the schema use their ID attribute as a key, but the User type supports both id and email while Product, ProductVariant, and Collection use composite keys made of id and channel slug:

typekeyalternative key
Addressid
Appid
Categoryid
Collectionid channel
Groupid
PageTypeid
Productid channel
ProductMediaid
ProductTypeid
ProductVariantid channel
Useridemail

Known issues and limitations

Apollo Federation doesn't handle the scenario when the federated server doesn't return the requested object too well. The GraphQL gateway will report an error when Saleor fails to return the requested entity, either because it was deleted, the request is missing authorization required, or its ID was incorrect.

Rely on webhooks to update or clear relations stored in your service's database when objects are deleted in Saleor.

Different types can require different permissions to retrieve by the federation, and two users may not have access to the objects of the same type. Resolvers implemented by your service that return keys for federation may require additional implementation checks. Likewise, some data (e.g., review author's names) is better duplicated across services and kept in sync with webhooks instead of being queried over the federation.

In some cases, it may be required to set up an application account in your store's dashboard and to configure your gateway server to use application credentials when communicating with Saleor GraphQL API.