graphql-example-go

command module
v0.0.0-...-efccb87 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2020 License: MIT Imports: 15 Imported by: 0

README

graphql-example-go

Example of GraphQL implementation in Golang

Playground

Authorization

Make the following GraphQL query

query {
  getToken(email: "test@mail.com", password: "test")
}

Then insert the resulting token in the HTTP Headers of each API call e.g.

{
  "authorization": "paste resulting token here..."
}

Database Setup

docker pull postgres
docker run -p 5432:5432 --name postgres-container -e POSTGRES_PASSWORD=password -e POSTGRES_USER=user -e POSTGRES_DB=test_db -d postgres

Documentation

Refer to playground generated docs for API documentation. For Golang related documentation:

godoc -http=:6060

Configuration

Found in ./config/config.yml

  • server - Server related configuration
    • port - HTTP port to host the server on
    • timeout - Cool down before exiting the server, after receiving termination command, in seconds
  • database - PostgreSQL DB details
    • user - username
    • host - host address e.g. 'localhost'
    • port - host port e.g. '5432'
    • name - name of the database to connect to
    • password - password associated with user name
    • ssl - SSL mode used during the database connection
  • jwt -
    • key - Key used to encrypt JWT tokens with
    • expiration - After how many hours the token should expire

Testing

Test cases found in ./test Startup the server then run:

cd test
go test

or alternatively for a specific test case

go test -run TestGetToken

Environment Variables

These are optional, see configuration file for defaults. Passwords should always be set in the environment variables however for this example defaults are provided in the configuration file to make set up easier.

POSTGRES_PASSWORD - Database.Password
POSTGRES_USER - Database.User
POSTGRES_DB - Database.Name
JWT_KEY - JWT.Key

Improvements that can be done

  • Display user email on movie queries instead of ID
  • Move DB creation string to file
  • Subscriptions
  • Code Coverage
  • Performance Testing
  • API Analytics
  • Packaging
  • Workers
  • heroku app hosting
  • Update readme with godoc reference, build status, coverage etc. tags

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
config
graphql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL