Skip to content

Latest commit

 

History

History
102 lines (75 loc) · 2.02 KB

README.md

File metadata and controls

102 lines (75 loc) · 2.02 KB

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