Example of GraphQL implementation in Golang
- run the server
- navigate to:
- Prisma (Preferred) [http://localhost:8080/playground]
- GraphiQL [http://localhost:8080/graphql]
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..."
}
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
Refer to playground generated docs for API documentation. For Golang related documentation:
godoc -http=:6060
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
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
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
- 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