Skip to content

thegeorgenikhil/hackernews-go-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HackerNews Clone

This is a HackerNews clone built with GraphQL(gglgen), Go and MySQL.

Frontend

It is based on the How to GraphQL Tutorial.

Running the app

  1. Clone the repo
git clone https://github.com/thegeorgenikhil/hackernews-go-graphql
  1. Install dependencies
go mod download
  1. Start a MySQL Docker container using the following command:
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=dbpass -e MYSQL_DATABASE=hackernews -d mysql:latest
  1. Run the app
go run server.go
  1. Open http://localhost:8080 to view the GraphQL Playground it in the browser.

  2. Use http://localhost:8080/graphql to query the GraphQL API.

GraphQL Queries and Mutations

Queries

  • Get all links
query GetLinks {
  links {
    title
    address
    id
    user {
      id
      name
    }
  }
}

Response:

{
  "data": {
    "links": [
      {
        "title": "GraphQL",
        "address": "https://graphql.org/",
        "id": "1",
        "user": {
          "id": "1",
          "name": "thegeorgenikhil"
        }
      },
      {
        "title": "How to GraphQL",
        "address": "https://www.howtographql.com/",
        "id": "2",
        "user": {
          "id": "1",
          "name": "thegeorgenikhil"
        }
      }
    ]
  }
}

Mutations

  • Post a new link
mutation CreateLink($input: NewLink!) {
  createLink(input: $input) {
    id
    title
    address
    user {
      id
      name
    }
  }
}

Variables:

{
  "input": {
    "title": "GraphQL",
    "address": "https://graphql.org/"
  }
}

Headers:

{
  "Authorization": "<user-token-here>"
}

Response:

{
  "data": {
    "createLink": {
      "id": "1",
      "title": "GraphQL",
      "address": "https://graphql.org/",
      "user": {
        "id": "1",
        "name": "thegeorgenikhil"
      }
    }
  }
}
  • Create a new user
mutation CreateUser($input: NewUser!) {
  createUser(input: $input)
}

Variables:

{
  "input": {
    "username": "user",
    "password": "password"
  }
}

Response:

{
  "data": {
    "createUser": "<user-token-here>"
  }
}

  • Login a user
mutation LoginUser($input: Login!) {
  login(input: $input)
}

Variables:

{
  "input": {
    "username": "user",
    "password": "password"
  }
}

Response:

{
  "data": {
    "login": "<user-token-here>"
  }
}

  • Refresh a user token
mutation RefereshToken($input: RefreshTokenInput!) {
  refreshToken(input: $input)
}

Variables:

{
  "input": {
    "token": "<expired-token-here>"
  }
}

Response:

{
  "data": {
    "refreshToken": "<new-user-token-here>"
  }
}

About

HackerNews clone built with GraphQL(gqlen), Go and MySQL.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages