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/
- 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
query Book {
books {
id
genre
publisher
title
}
}
{
"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"
},
]
}
}
query Author {
authors {
id
name
nationality
publisher
}
}
{
"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"
}
]
}
}
query Book {
books {
id
genre
publisher
title
}
authors {
id
name
nationality
publisher
}
}
{
"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"
}
]
}
}
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
}
}
}
{
"bookId": "2",
"authorId": "2",
"publisher": "O'Reilly Group"
}
{
"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"
}
}
}
}