Demo of wrapping a REST API Server via Apollo Server.
- Fully type safe
- Uses
@graphql-codegen/typescript-resolvers
to auto-generate the resolver types based on the Schema Seegraphql-server/codegen.yml
for configuration
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
.
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
All Books
{
books {
title
author
}
}
Get the title of the book at index 2
{
book(id: 2) {
title
}
}
Adds a new book
mutation {
addBook(input: { title: "Another exciting book", author: "Stephen King" }) {
title
author
}
}
Updates an existing book (by index)
mutation {
updateBook(
id: 2
input: { title: "Another exciting book", author: "Stephen King" }
) {
title
author
}
}