Giter VIP home page Giter VIP logo

hasuracon-federation-workshop's Introduction

HasuraCon'22 Data Federation using Hasura GraphQL

Things to know

Types of Joins

  • GraphQL <> GraphQL Joins
  • Database <> GraphQL Joins
  • Database <> Database Joins

GraphQL <> GraphQL Joins Example

An example of joining two GraphQL schemas, a store service and a fulfillment service, with Hasura. Both services were made with GraphQL Code Generator and GraphQL Yoga.

Run Example With Hasura Cloud

  1. Deploy the fulfillment and store service to any online host.

  2. In your Hasura Cloud project, add the FULFILLMENT_SERVICE_URL and STORE_SERVICE_URL enviroment variables. Also add a database named default.

Store Service

The store service is an example of an ecommerce schema with items and orders containing items

type Item {
  id: Int!
  name: String!
  price: Float!
}

type LineItem {
  quantity: Int!
  itemId: Int!
  item: Item
}

type Order {
  id: Int!
  lineItems: [LineItem!]!
}

type Query {
  item(id: Int!): Item
  items: [Item!]!
  order(id: Int!): Order
  orders: [Order]!
}

Fulfillment Service

The fulfillment service is an example of a shipping company schema with each fulfillment having an order ID and a status

enum Status {
  PACKING
  SHIPPED
  DELIVERED
}

type Fulfillment {
  id: Int!
  orderId: Int!
  status: Status!
}

type Query {
  fulfillment(orderId: Int!): Fulfillment!
  fulfillments: [Fulfillment]!
}

Joining the Schemas

Using Hasura GraphQL Joins we can combine the schemas together! From the fulfillment schema orderId key we join order information from store schema using the order type ID field. Without any code we have joined two separate services!

Screen Shot 2022-04-26 at 19 32 30

{
  fulfillment(orderId: 1) {
    status
    order {
      lineItems {
        item {
          name
        }
      }
    }
  }
}
{
  "data": {
    "fulfillment": {
      "status": "PACKING",
      "order": {
        "lineItems": [
          {
            "item": {
              "name": "Sunglasses"
            }
          }
        ]
      }
    }
  }
}

hasuracon-federation-workshop's People

Contributors

praveenweb avatar

Stargazers

 avatar Emmanuel Salomon avatar

Watchers

Aaron Johnson avatar Rajoshi Ghosh avatar Vamshi Surabhi avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.