Stefan Yohansson
Stefan Yohansson

Reputation: 667

Apollo Federation gateway and another server implementation

I am reading about apollo federation and how to migrate from schema stitching and a question came when I read:

The basic strategy for migrating from a stitching gateway to Apollo Federation is to start by making the underlying services federation-capable

https://www.apollographql.com/docs/apollo-server/federation/migrating-from-stitching/#adding-federation-support-to-services

basically federation gateway can't accept another service not federation aware? so there's no way to use federation with another graphql server (such https://github.com/nuwave/lighthouse) or should I misunderstood that line?

Upvotes: 1

Views: 2538

Answers (3)

Pieter Venter
Pieter Venter

Reputation: 919

Like @daniel-rearden said it does need to implement additions to the spec. Check out graphql-transform-federation to assist you with adding the required info. Also check out this blog post

Upvotes: 1

Morse
Morse

Reputation: 61

Once you have the server you also need to build the gateway, if you are using docker-compose you can use a reusable docker image as follows:


version: '3'

services:
    a:
        build: ./a # one service implementing federation
    b:
        build: ./b
    gateway:
        image: xmorse/apollo-federation-gateway
        ports:
            - 8000:80
        environment: 
            CACHE_MAX_AGE: '5' # default cache
            ENGINE_API_KEY: '...' # to connect to the apollo engine
            POLL_INTERVAL: 30 # to update services changes
            URL_0: "http://a"
            URL_1: "http://b"

Check out the github repo for a working example.

Upvotes: 0

Daniel Rearden
Daniel Rearden

Reputation: 84837

Yes, any GraphQL service that's incorporated into the federation gateway has to implement Apollo's federation specification.

Federation relies on the service schema containing several specific types, directives and type extensions:

scalar _Any
scalar _FieldSet

union _Entity

type _Service {
  sdl: String
}

extend type Query {
  _entities(representations: [_Any!]!): [_Entity]!
  _service: _Service!
}

directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT
directive @extends on OBJECT

The service does not have to be a GraphQL.js implementation, but it does need to implement the above additions to the schema as outlined in the spec.

Upvotes: 5

Related Questions