Skip to content

konjoinfinity/gqltest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"
      }
    }
  }
}