Skip to content

AndriyKalashnykov/graphql-golang

 
 

Repository files navigation

CI Hits Renovate enabled

GraphQL Server (schema-first) With Golang

Table Of Contents

How to Run The Project

First start mysql server with docker:

docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=dbpass -e MYSQL_DATABASE=hackernews -d mysql:latest

Then create a Table names hackernews for our app:

docker exec -it mysql bash
mysql -u root -p
CREATE DATABASE hackernews;

Run the server:

make run

Navigate to https://localhost:8080 you can see graphiql playground and query the graphql server.

xdg-open http://localhost:8080/

createUser

Execute createUser mutation

mutation createUser {
  createUser(input: {username: "usr2", password: "pwd"})
}

Expected JSON result:

{
  "data": {
    "createUser": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjI3MzgyNDQsInVzZXJuYW1lIjoidXNyMiJ9.z0yrV6ajZO8IqFBlEuTwAnKRP-C15MuL1REmjJ5YYU8"
  }
}

loginUser

Execute loginUser mutation

mutation loginUser {
  login(input: {username: "usr2", password: "pwd"})
}

Expected JSON result:

{
  "data": {
    "login": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjI3MzgyNDQsInVzZXJuYW1lIjoidXNyMiJ9.z0yrV6ajZO8IqFBlEuTwAnKRP-C15MuL1REmjJ5YYU8"
  }
}

createLink

Set Authorization Header, use token from loginUser

{
  "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjI3MzgyNDQsInVzZXJuYW1lIjoidXNyMiJ9.z0yrV6ajZO8IqFBlEuTwAnKRP-C15MuL1REmjJ5YYU8"
}

Execute createLink mutation

mutation createLink {
  createLink(input: {title: "real link!", address: "www.graphql.org"}) {
    user {
      name
    }
  }
}

Expected JSON result:

{
  "data": {
    "createLink": {
      "user": {
        "name": "usr2"
      }
    }
  }
}

findLinks

Execute findLinks query

query findLinks {
  links {
    title
    address
    id
  }
}

Expected JSON result:

{
  "data": {
    "links": [
      {
        "title": "real link!",
        "address": "www.graphql.org",
        "id": "1"
      },
      {
        "title": "real link!",
        "address": "www.graphql.org",
        "id": "2"
      }
    ]
  }
}

refreshToken

Execute refreshToken mutation, provide current token as an input

mutation refreshToken{
  refreshToken(input: {
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjI3MzgyNDQsInVzZXJuYW1lIjoidXNyMiJ9.z0yrV6ajZO8IqFBlEuTwAnKRP-C15MuL1REmjJ5YYU8"
  })
}

Expected JSON result:

{
  "data": {
    "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjI3Mzg5NjYsInVzZXJuYW1lIjoidXNyMiJ9.fKK07Zv6iuq6ep9FtV3CE7z_KDm7ljnZqRvePokSOEs"
  }
}

Tutorial

to see the tutorial visit https://www.howtographql.com/graphql-go/0-introduction/

About

GraphQL Server (schema-first) With Golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 85.0%
  • Makefile 8.8%
  • Dockerfile 6.2%