lucasbesen / graphql-server

First project with Node.js and GraphQL - 2018

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Entria Full Stack Challenge - Server

For client side, check

Queries

query AllStudentsQuery{
  allStudents {
    _id
    name
    description
  }
}

query GetStudentQuery($studentId: String!) {
  getStudent(_id: $studentId) {
    _id
    name
    description
  }
}

Mutation

mutation {
  RegisterStudent(input: {
    _id: "5aa1e8a457ec8218cab9b0b1",
    name: "Adalberto Garcia",
    description: "Computer Science",
  }) {
    newStudent {
      name
      description
    }
  }
}

CircleCI codecov

Very simple boilerplate using GraphQL and DataLoader

Blog Posts

Directory Structure

├── /data/                   # GraphQL generated schema
├── /repl/                   # Read-Eval-Print-Loop (REPL) configuration
├── /scripts/                # Generate GraphQL schema script
├── /src/                    # Source code of GraphQL Server
│   ├── /connection/         # Connections types (Relay)
│   ├── /interface/          # NodeInterface (Relay)
│   ├── /loader/             # Loaders of the models using DataLoader
│   ├── /model/              # Models definition (Mongoose, SQL, Google DataStore)
│   ├── /mutation/           # Mutations definition
├── /test/                   # Test helpers

Create-GraphQL

If you want to move faster you should use create-graphql to simplify the creation of a GraphQL Server

Command

Setup

npm install

Note: If you do not have mongodb installed, please install it:

brew install mongodb

Develop

npm run watch

Test

npm test

Or

npm run test:watch

Docker and docker-compose

No needs for installing dependencies or running mongod in another terminal window

docker-compose build && docker-compose up

Test

docker-compose -f docker-compose.test.yml build && docker-compose -f docker-compose.test.yml up

Production

# first compile the code
npm run build

# run graphql compiled server
npm start

Flow

npm run flow

Or

flow

REPL server

npm run repl

awesome > const user = await M.User.find()

Yep, await syntax works on the repl, it is awesome, tks @princejwesley (https://gist.github.com/princejwesley/a66d514d86ea174270210561c44b71ba)

Schema

Update your schema

npm run update-schema

Take a look on the Schema

About

First project with Node.js and GraphQL - 2018


Languages

Language:JavaScript 100.0%