Skip to content

A simple proof-of-concept using Apollo GraphQL Federation

License

Notifications You must be signed in to change notification settings

titel-media/gql-federation-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Federation Proof-of-Concept

A simple prototype using Apollo GraphQL Federation to combine two small elixir Graphql services

Setup

We have 3 services. Start the elixir services first, then run the federator.

  • product_api
    • cd product_api && mix deps.get && iex -S mix
    • runs on port 3010 by default (see config/config.exs)
    • example query:
query test {
  product: product(id: 1) {
    name
    brand
  }
  • user_api
    • cd user_api && mix deps.get && iex -S mix
    • runs on port 3020 by default (see config/config.exs)
    • example query:
query test {
  user: fetchUserById(id: 3) {
    email
  }
}
  • federator
    • cd federator && npm install && npm start server
    • runs on port 4000 by default

Try it out

Send this query to the federator:

query test {
  # from the user service
  user: fetchUserById(id: 2) {
    email
  }
  # from the product service
  product: product(id: 2) {
    name
    brand
  }
  # from both, using federation
  user_with_products: fetchUserById(id: 1) {
    products {
      name
      brand
      priceUSD
    }
    email
  }
}

You should see this response

{
  "data": {
    "user": {
      "email": "[email protected]"
    },
    "product": {
      "name": "Blue Hat",
      "brand": "Balenciaga"
    },
    "user_with_products": {
      "products": [
        {
          "name": "Red Belt",
          "brand": "Gucci",
          "priceUSD": 1000
        },
        {
          "name": "Blue Hat",
          "brand": "Balenciaga",
          "priceUSD": 2000
        },
        {
          "name": "Green Scarf",
          "brand": "Vetements",
          "priceUSD": 3000
        }
      ],
      "email": "[email protected]"
    }
  }
}

Read More:

Federation Specs

License

Released under the MIT License.

About

A simple proof-of-concept using Apollo GraphQL Federation

Resources

License

Stars

Watchers

Forks