/apollo-rest-example

Apollo Rest API Server Adaptor Example

Primary LanguageTypeScript

apollo-rest-example

Demo of wrapping a REST API Server via Apollo Server.

Start REST API Server

cd graphql-server
yarn start # or `yarn watch` for dev

Changes are only stored in memory, so all data is reset when restarting the server.

You can see all currently stored data via http://localhost:8080/books.

Start Apollo Server

cd graphql-server
yarn start # or `yarn watch` for dev
yarn graphql-generate # generate typings for resolvers based on schema

open http://localhost:4000/ to see the GraphQL Playground

GraphQL Queries

Get Data

All Books

{
  books {
    title
    author
  }
}

Get the title of the book at index 2

{
  book(id: 2) {
    title
  }
}

Post data

Adds a new book

mutation {
  addBook(input: { title: "Another exciting book", author: "Stephen King" }) {
    title
    author
  }
}

Put data

Updates an existing book (by index)

mutation {
  updateBook(
    id: 2
    input: { title: "Another exciting book", author: "Stephen King" }
  ) {
    title
    author
  }
}