Skip to content

Proof of concept showing 3 Elixir services behind an Apollo Federated gateway

License

Notifications You must be signed in to change notification settings

DivvyPayHQ/federation_poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Federation PoC

This is to showcase how GraphQL federation would be used in practice with Elixir.

Setup

Start each of the Elixir subgraph services in separate terminal windows.

$ cd <products|reviews|inventory>
$ mix deps.get
$ mix phx.server

Start the federated gateway.

$ cd gateway
$ yarn
$ yarn start

GraphiQL Playgrounds

Schemas

schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: ["@key", "@extends", "@external"]) {
  query: RootQueryType
  mutation: RootMutationType
}

type Product @extends @key(fields: "upc") {
  upc: String! @external
  inStock: Boolean
}

type RootQueryType @extends {}

type RootMutationType {
  decrementInventory(upc: String!, amount: Int): String
}
schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key"]) {
  query: RootQueryType
  mutation: RootMutationType
}

type Product @key(fields: "upc") {
  upc: String!
  name: String!
  price: Int
}

type RootQueryType {
  product(upc: String!): Product
}

type RootMutationType {
  addDiscount(upc: String!, amount: Int!): String
}

Note: The reviews schema does not import the Federation v2 directives but it will be converted to v2 schema by the gateway.

schema {
  query: RootQueryType
}

type Product @extends @key(fields: "upc") {
  upc: String! @external
  reviews: [Review]
}

type Review @key(fields: "id") {
  id: ID!
}

type RootQueryType @extends {
  review(id: ID!): Review
}

Information

The meat of this PoC is in the schema.ex of each service and in the absinthe_federation library that pulls in some additional macros

About

Proof of concept showing 3 Elixir services behind an Apollo Federated gateway

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks