Skip to content

A graphql/express server with dockerized postgres

Notifications You must be signed in to change notification settings

d0ruk/graphql-demo

Repository files navigation

"dependencies": {
  "apollo-server": "^2.0.5",
  "apollo-server-express": "^2.0.4",
  "bcrypt": "^5.0.0",
  "express": "^4.16.3",
  "graphql": "^15.3.0",
  "graphql-iso-date": "^3.6.1",
  "jsonwebtoken": "^8.3.0",
  "pg": "^8.2.2",
  "sequelize": "^6.3.0"
}

usage

  • edit .env
  • docker-compose up -d
  • npm run seed
  • npm start

adminer is at localhost:8080

graphiql is at localhost:8000/gql


query User

fragment info on User {
  username,
  fullname,
  events {
    name,
    country,
    date
  }
}

query {
  user(username: "someuser") {
    ...info
    events {
      owner { ...info }
    }
  }
  users(limit: 10) { username }
  me { ...info }
}

query Event

fragment userInfo on User {
  username,
  fullname,
  email,
}

fragment eventInfo on Event {
  id,
  name,
  date,
  createdAt,
  going { ...userInfo }
  owner { ...userInfo }
}

query {
  event(id: 42) { ...eventInfo }
  events(cursor:"2018-12-04T02:07:37.480Z", limit: 3) {
    events { ...eventInfo }
    meta { hasNextPage }
  }
}

mutate User

mutation {
  signUp(
    username: "test",
    email: "asd@asd.xyz",
    password: "somepass"
  ) { token }
  signIn(username: "adm1n", password:"imgroot") { token }
  deleteUser(username: "someuser") # 1
}

mutate Event

mutation {
  createEvent(name: "bigcrowd",  date: "2017-01-20") { # 1
    id,
    name,
    date,
    owner { username }
  }
  deleteEvent(id: 101) # 1
}

subscribe to Event

subscription {
  newEvent {
    id
    name
    createdAt
    owner {
      username
    }
  }
}
  1. You need to set the appropriate x-token header for this mutation to work.