Воркшоп по созданию GraphQL сервера на Node.JS
Чтобы начать, перейдите к шагу 0
git checkout step0-start
- Гит не видит нужных веток
git fetch origin
- Как подсмотреть решение, не теряя прогресс?
# Текущая ветка git checkout step0-start
git stash # сохраните изменения
git checkout step0 # перейдите в ветку с решением
git checkout step0-start # вернитесь
git stash apply # загрузите сохранение
Далее следует оригинальное ридми, которое содержит множество полезных ссылок.
This is the repository for the afternoon workshop at GraphQL Day 🇳🇱
This git repository contains several branches that correspond to the "steps" to be performed throughout the workshops. The master
branch contains the final version of the code.
- Step 0: Minimal GraphQL server
- Step 1: Extend API with query arguments
- Step 2: Complete API operations
- Step 3: Add database layer with Prisma and Prisma bindings
- Step 4: Complete API operations against the database
git clone git@github.com:nikolasburk/graphqlday-workshop.git
cd graphqlday-workshop
npm install -g prisma
prisma deploy
Note: If you don't have Docker installed on your machine, you need to remove the
cluster
property fromprisma.yml
and select a development cluster when prompted by the CLI where to deploy your Prisma API. The endpoint that's then printed by the CLI needs to be pasted intoindex.js
wherePrisma
is instantied.
node src/index.js
npm install -g graphql-cli
graphql playground
The Playground now allows to work with both GraphQL APIs side-by-side. It receives its information about the corresponding endpoints and schemas from the configuration in .graphqlconfig.yml
:
app
: The application layer built withgraphql-yoga
database
The database layer configured with Prisma
In the following queries/mutation,
__POST_ID__
is a placeholder that needs to be replaced with theid
of an actualPost
item in your database.
post(id: "__POST_ID__") {
id
title
content
published
}
mutation {
createDraft(
title: "How to GraphQL"
content: "Learn best practices all around developing GraphQL APIs"
) {
id
published
}
}
mutation {
publish(id: "__POST_ID__") {
id
published
}
}
mutation {
deletePost(id: "__POST_ID__") {
id
title
content
published
}
}
query {
posts(where: { title_contains: "QL" }) {
id
title
content
published
}
}
query {
post(where: { id: "__POST_ID__" }) {
id
title
content
published
}
}
mutation {
updatePost(where: { id: "__POST_ID__" }, data: { published: true }) {
id
title
content
published
}
}
mutation {
deletePost(where: { id: "__POST_ID__" }) {
id
title
content
published
}
}
The GraphQL server in this repository is build upon the following technologies:
graphql-yoga
: A GraphQL server library based on Express.js. It features out-of-the-box support for GraphQL Playgrounds as well as realtime GraphQL subscriptions.- Prisma: A GraphQL database proxy that makes it easy to connect your GraphQL server to a database and massively simplifies your resolver implementations.
- Docker (optional): In case you have Docker installed, you can deploy your Prisma APIs locally. Otherwise you can use a free sandbox environment provided by Prisma Cloud.
Note: When using Docker to deploy Prisma locally, the Prisma API is backed by a local MySQL database. If you're using Prisma Cloud, your Prisma API is running against an instance of AWS Aurora.
- Node.JS Tutorial on How to GraphQL: In-depth tutorial covering topics like schema design, GraphQL bindings, authentication and realtime GraphQL subscriptions.
- GraphQL Boilerplates: Starter kits for your next GraphQL project, no matter if backend-only (Node, TypeScript, ...) or fullstack (React, Vue, ...). Each boilerplate is build upon industry best practices and uses the latest GraphQL tooling.
- Top 5 Reasons To Use GraphQL: Learn the top arguments why GraphQL is the future of API development.
- How to wrap a REST API with GraphQL:
- GraphQL Server Basics:
- Deployment tutorials:
Get your tickets for GraphQL Europe here.