A base framework to create an API with GraphQL compatible. The database is based on MongoDB but it could easily replaced to other database of choice.
- Node (> v8.0.0) NOTE: Untested with v10.0.0
- Yarn Package Manager
Once the project cloned into local machine, simply execute yarn
and the package manager will install all necessary dependencies for the project.
The project also incorporated with JWT so make sure to have an jwtSecret
environment variable (either through CLI or .env
file). Please refer to .sampleenv
for example.
When all dependencies are installed and environment variables are setup, execute yarn start
and the server will be up at http://localhost:5000/
.
GraphQL endpoint is available at http://localhost:5000/graphql
. In development environment, the endpoint will expose GraphiQL to allow quick request testing. This will be disable in production
yarn start
: start the development version (with development variables) of the APIyarn start-production
: start the production version of the APIyarn clean
: clean up build folder, use when you want to create a fresh production version of the projectyarn build-server
: build a production version of the projectyarn build
: Combination ofyarn clean
andyarn build-server
Voyager is a great tool to visualize GraphQL schema. The project already implemented it and can be access in /voyager
route.
This provides a brief overview of how the project is structured.
├── README.md # Important information regarding to the project
├── package.json # project's info and dependencies declaration
├── src/
│ ├── config.js # configuration to separate data between dev and production
│ ├── db/
│ │ └── models/ # models for objects(documents) store in data
│ ├── dbLoader/ # hold code to help batching request to database
│ ├── dbinit.js # database initialization script
│ ├── graphql/
│ │ ├── errors.js # GraphQL Errors Response
│ │ ├── index.js
│ │ ├── resolvers/ # GraphQL Resolvers
│ │ │ ├── mutation/
│ │ │ ├── query/
│ │ │ └── typeDefs/
│ │ └── typeDefs/ # GraphQL Type Definitions
│ ├── index.js # Starting point of the project
│ └── plugins/ # Fastify Custom Plugins
│ ├── graphql/
│ └── voyager/