Code Monkey home page Code Monkey logo

amsjs-workshop's Introduction

Building a GraphQL Server with Node.JS

This is the repository for the morning workshop at AmsterdamJS ๐Ÿ‡ณ๐Ÿ‡ฑ

See the end of this README to get a 25% discount on your GraphQL Europe ticket ๐Ÿ‡ช๐Ÿ‡บ

Overview

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

Usage

Clone the repository

git clone [email protected]:nikolasburk/amsjs-workshop.git
cd amsjs-workshop

Deploy the Prisma service

npm install -g prisma
prisma deploy

Note: When running prisma deploy, the Prisma CLI prompts you to select a Prisma server to which the Prisma service should be deployed. Select the Demo server to deploy to Prisma Cloud or setup your own Prisma server locally with Docker. The endpoint that's then printed by the CLI needs to be pasted into index.js where Prisma is instantied.

Start the server

node src/index.js

Open a GraphQL Playground

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 with graphql-yoga
  • prisma The database layer configured with Prisma

Sample queries/mutations

In the following queries/mutation, __POST_ID__ is a placeholder that needs to be replaced with the id of an actual Post item in your database.

Application layer (graphql-yoga)

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

Database layer (Prisma)

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

Technology stack

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.

Recommended resources

๐Ÿ‡ช๐Ÿ‡บ GraphQL Europe

Get your tickets for GraphQL Europe here. As a special for workshop attendees, you can use this promo code to get a 25% discount on your ticket: amsmjs

amsjs-workshop's People

Contributors

nikolasburk avatar vinaypuppal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.