GraphQL

in a Microservice setup

Michael Staib

{
  me {
    name
  }
}
{
  "me": {
    "name": "Michael Staib"
  }
}
{
  me {
    name
  }
}
{
  me {
    name
    image {
      width
      height
      url
    }
  }
}
{
  "me": {
    "name": "Michael Staib",
    "image": {
      "width": 200,
      "height": 300,
      "url": "http://some/images/123.png"          
    }
  }
}
{
  me {
    name
    image {
      width
      height
      url
    }
  }
}
{
  me {
    name
    lastSeen
    friends {
      name
      lastSeen
    }
  }
}
{
  "me": {
    "name": "Michael Staib",
    "lastSeen": "2018-05-19T18:45",
    "friends": [
      {
        "name": "Rafael Staib",
        "lastSeen": "2018-05-24T12:37"
      },
      {
        "name": "Pascal Senn",
        "lastSeen": "2018-06-07T17:13"
      }
    ]
  }
}
{
  me {
    name
    lastSeen
    friends {
      name
      lastSeen
    }
  }
}
{
  "me": {
    "name": "Michael Staib",
    "lastSeen": "2018-05-19T18:45",
    "friends": [
      {
        "name": "Rafael Staib",
        "lastSeen": "2018-05-24T12:37"
      },
      {
        "name": "Pascal Senn",
        "lastSeen": "2018-06-07T17:13"
      }
    ]
  }
}
{
  me {
    ... PersonInfo
    friends {
      ... PersonInfo
    }
  }
}
fragment PersonInfo on Person {
  name
  lastSeen
}
  • One Endpoint
  • One Request
  • No over- or under-fetching
  • Type System
  • Predictable

GraphQL

Business Layer

Storage Layer

type Review {
  body: String
  author: User
  product: Product
}
type Product {
  name: String
  price: String
  inStock: Boolean
  shippingEstimate: Int
  reviews: [Review]
}
type User {
  name: String
  reviews: [Review]
}
{
  me {
    name
    reviews {
      body
      product {
        name
      }
    }
  }
}
{
  topProducts(first: 5) {
    name
    shipingEstimate
    inStock
    reviews {
      body
      author {
      	name
      }
    }
  }
}

GraphQL

Account
Service

Products
Service

Client

Review
Service

Inventory
Service

type Review {
  body: String
}
type Product {
  name: String
  price: String
}
type User {
  name: String
}
extend type Product {
  inStock: Boolean
  shippingEstimate: Int
}
extend type Product {
  reviews: [Review]
}
extend type User {
  reviews: [Review]
}

Account

Product

Inventory

Review

extend type Review {
  author: [User]
}
extend type Review {
  product: Product
}
{
  topProducts(first: 5) {
    name
    shipingEstimate
    inStock
    reviews {
      body
      author {
      	name
      }
    }
  }
}

Account
Service

Products
Service

Review
Service

Inventory
Service

GraphQL Gateway

GraphQL

GraphQL

Client

GraphQL

GraphQL

GraphQL

GraphQL

GraphQL

GraphQL

Approaches to Graph Distribution

  • Schema Stitching

  • Schema Federation


Demo
 

{
  me {
    name
    reviews {
      body
      product {
        name
      }
    }
  }
}

Account
Service

Products
Service

Review
Service

Inventory
Service

GraphQL Gateway

{
  topProducts(first: 5) {
    name
    shipingEstimate
    inStock
    reviews {
      body
      author {
      	name
      }
    }
  }
}

Account
Service

Products
Service

Review
Service

Inventory
Service

GraphQL Gateway

Conclusion

  • Iterate faster.

  • Be more flexible.

  • Deploy when you want.

  • Divide your graph into logical units.

https://chillicream.com

https://github.com/chillicream/hotchocolate

Virtual NetCoreConf 2021 - Schema Stitching

By Michael Ingmar Staib

Virtual NetCoreConf 2021 - Schema Stitching

  • 543