Giter VIP home page Giter VIP logo

gqltest's Introduction

gqltest - GraphQL Stitching

Getting Started

First install the dependencies:

npm install
# Or with yarn
yarn install

To run the graphql server, run:

nodemon gateway.js

Then you should see:

Gateway running at http://localhost:4000/

To access the Apollo GraphQL Studio Explorer, go to:

http://localhost:4000/

A simple GraphQL instance that:

  • Connects to two API data sources
  • Combines both schemas using stitching
  • Makes both data sources accessible using one query request
  • Shared schema data properties are kept in sync
  • Shared property mutations update both APIs

Example Query and Mutation

Books Query

query Book {
  books {
    id
    genre
    publisher
    title
  }
}

Example Response

{
  "data": {
    "books": [
      {
        "id": "1",
        "genre": "capacitor",
        "publisher": "Random House",
        "title": "saepe dolores voluptas"
      },
      {
        "id": "2",
        "genre": "City Accounts Gender",
        "publisher": "Greenholt - Nitzsche",
        "title": "voluptatem sunt accusamus"
      },
      {
        "id": "3",
        "genre": "Coupe dismiss",
        "publisher": "Green and Sons",
        "title": "dolores ea veniam"
      },
    ]
  }
}

Authors Query

query Author {
  authors {
    id
    name
    nationality
    publisher
  }
}

Example Response

{
  "data": {
    "authors": [
      {
        "id": "1",
        "name": "Elaine Bahringer",
        "nationality": "Cuba",
        "publisher": "Random House"
      },
      {
        "id": "2",
        "name": "Jermaine VonRueden",
        "nationality": "Aruba",
        "publisher": "Lindgren - Ernser"
      },
      {
        "id": "3",
        "name": "Ed Fisher",
        "nationality": "Vietnam",
        "publisher": "Kuphal - Hoppe"
      }
    ]
  }
}

Stitched Books and Authors Query

query Book {
  books {
    id
    genre
    publisher
    title
  }
  authors {
    id
    name
    nationality
    publisher
  }
}

Example Response

{
  "data": {
    "books": [
      {
        "id": "1",
        "genre": "capacitor",
        "publisher": "Random House",
        "title": "saepe dolores voluptas"
      },
      {
        "id": "2",
        "genre": "City Accounts Gender",
        "publisher": "O'Reilly Group",
        "title": "voluptatem sunt accusamus"
      }
    ],
    "authors": [
      {
        "id": "1",
        "name": "Elaine Bahringer",
        "nationality": "Cuba",
        "publisher": "Random House"
      },
      {
        "id": "2",
        "name": "Jermaine VonRueden",
        "nationality": "Aruba",
        "publisher": "O'Reilly Group"
      }
    ]
  }
}

Update Book and Author Publisher Mutation

mutation UpdateBookAndAuthor($bookId: ID!, $authorId: ID!, 
$publisher: String!) {
  updateBookAndAuthor(bookId: $bookId, authorId: $authorId, publisher: $publisher) {
    book {
      id
      title
      genre
      publisher
    }
    author {
      id
      name
      nationality
      publisher
    }
  }
}

Mutation Variables

{
"bookId": "2",
"authorId": "2",
"publisher": "O'Reilly Group"
}

Example Response

{
  "data": {
    "updateBookAndAuthor": {
      "book": {
        "id": "2",
        "title": "voluptatem sunt accusamus",
        "genre": "City Accounts Gender",
        "publisher": "O'Reilly Group"
      },
      "author": {
        "id": "2",
        "name": "Jermaine VonRueden",
        "nationality": "Aruba",
        "publisher": "O'Reilly Group"
      }
    }
  }
}

gqltest's People

Contributors

konjoinfinity avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.