This is a basic implementation for the study proposal, of a COVID-19 report service using GraphQL and Golang.
The package /cmd
covers a main entrypoint:
- The basic form of an executable command and entry point.
- Importing packages (from the standard library and the remote repository)
- Using the GraphQL Go handler as request middleware (graphql-go/handler)
- Listen and serve command, to listen on the TCP network requests on :4567 port.
The package /pkg
covers models
, schema
, services
and utils
:
pkg/models
covers struct type for data representation.pkg/schema
covers GraphQL Schema definitions (Eg. Query, Types, etc).pkg/services
covers external services to retrieve COVID-19 data from the Rapid API service (COVID-19 data).pkg/utils
covers program helpers utility.
The package /test
covers only testutil
test/testutil
covers an HTTP Server to mock request data, avoiding real work requests.
The package /bin
covers a build binary for main executable.
This project raise a new HTTP Server and listen to request on port :4567.
This project was build using go mod
. Then to install project dependencies, run:
go mod download
To execute this project in developer mode, clone this repository and just run:
go run cmd/main.go
To execute this project as binary production mode, run:
go build cmd/main.go && ./main
To execute this project as test mode, just go to a covered package (including _test.go
files) and run:
go test -v
Optionally, you can use cover profile go test ./pkg/ -coverprofile=coverage.out -v
and go tool cover -html coverage.out
to open a package coverage browser version.
This project is running at Heroku. Check it out! (Playground enabled) COVID-19 GraphQL Service on Heroku
This project uses .env
to load environment variables. You'll need to create a new file on the root directory called .env
before run. Fill this file with these values:
COVID_SERVICE_ENDPOINT=https://covid-19-data.p.rapidapi.com
COVID_SERVICE_API_KEY=get-your-rapid-api-key
GRAPHQL_PLAYGROUND=true
PORT=4567
Optionally, you can use GraphQL Playground setting the enviroment variable GRAPHQL_PLAYGROUND
as true
.
©bsilva0x87, 2021.