backend
The API and database 🦥
General
Several prerequisites are needed in order to run the backend
package locally. Follow the installation/download instructions for your local operating system.
- install Git
- install Go
- install Insomnia
- install Dgraph
- run
git clone git@github.com:dgraph-io/dgraph.git
in the command line
- run the Install from Source instructions in the link above
These should be the minimum resources needed to get up and running with backend
! 👍
NOTE: the master
branch version of Dgraph is being used to accommodate pre-release features
Packages
custom
custom
intercepts and processes all Dgraph @custom
directive requests. This is to allow the additional preprocessing ahead of the main GraphQL logic and to provide a base for local mocking. No "smarts" will be built into this package and it will only be an intermediary responsible for invoking external APIs (e.g. Auth0) and internal packages (e.g. entities
) to fulfill the required logic. Most or all of the internal packages will be housed in the private internal
repository.
The server can be built in two configurations:
- production:
go build
- mock:
go build -tags mock
In both cases calling ./bin/start_custom
would start the server.
subscription
(tbd)
- intercepts
@withSubscription
directives
- configures/establishes GraphQL subscription link
- calls external APIs/internal packages as needed
- exposes webhook listener configuration endpoints
- manages/stores webhook listeners in database (schema likely requires update)
- emits received GraphQL subscription events on webhook listeners
demo
demo
is responsible for loading demo data into the Dgraph database. Follow the instructions below to get setup and execute all commands in the terminal from the root of the backend
repository.
- run
chmod -R +x ./bin/
- launch Dgraph locally by running
./bin/start_dgraph
- build and run the
demo
package by running ./bin/load_demo
; a progress bar will display as data is loaded into Dgraph and once complete the database may be used
- launch Insomnia and contact the repo maintainer for the requests collection file
- run
./bin/get_token
from the root of the backend
repository and copy the output token value
- in each of your Insomnia requests, under the Headers tab, add a
Key
with the value "X-Auth0-Token
" and a Value
with a value of the copied token and the requests are now authorized to communicate with the Dgraph database
NOTE: the Management API key fetched from Auth0 is sensitive data and should not be shared publicly
NOTE: currently the user JWT issued from the token
package is configured to john.forstmeier@gmail.com
in Auth0
Notes
Ports
These are the ports that are currently configured for use across the backend
package.
- Dgraph Zero:
5080
and 6080
- Dgraph Alpha:
7080
, 8080
, and 9080
- custom server:
4080
Design
Below are a couple of points regarding specific code and design choices.
struct
should be used for all request/response objects - specific struct
objects with appropriate fields and JSON tags should be defined
map
should be used for Dgraph GraphQL mutation variables - a more flexible map[string]interface{}
can be used when processing mutations