Simple Project with CRUD.
The project has been created using Graphback. Run the project using the following steps:
- Start the database
docker-compose up -d
- Inspect your schema in the
model/datamodel.graphql
file. - Start the server
npm run develop
Or, if using yarn
yarn develop
For more on customizing your Graphback application, check out our docs
If your project contains the client application then please follow ./client/README.md
for info regarding running the client-side.
The following tools and technologies have been used to create this template:
-
GraphQL: GraphQL is an open-source data query and manipulation language for APIs which was publically released by Facebook in 2015.
-
Apollo Server: Apollo Server provides a way to simplify building the GraphQL server. It can be used with several popular libraries for Node.js like Express, Koa, Hapi. Here we have used it with Express.
-
Express: Express is a minimal and flexible Node.js web application framework that makes building a Node.js server easier by providing a wide range of features.
-
GraphQL Code Generator: GraphQL Code Generator is a tool that generates code out of your GraphQL schema by analyzing it.
-
MongoDB: MongoDB is a popular open-source document NoSQL database written in C++.
The project contains the following set of source files.
- The
model
folder, which contains a GraphQL schema file defining your business models. This file can be edited to suit your needs. - The
.graphlrc.yml
file defining the configuration like the path to business model declaration, how to perform code generation from the GraphQL types to Typescript types etc. The configuration file is defined using the GraphQL project usinggraphql-config
. - A
docker-compose.yml
file to spin up the database if you do not have a running instance. - A
.env
file that contains different environment variables. - A
src
folder which has:- A
resolvers
folder where you can declare your custom resolvers to suit your use cases. This folder contains an examplesrc/resolvers/noteResolvers.ts
resolver file which can be deleted or modified. See Custom Resolvers guide for more information. - A
schema
folder that contains generated schema file. It's advised to not edit this file manually. See Generating types. - A
generated-types.ts
file, which is also generated as indicated by its name. See Generating types. - A
index.ts
file that configures and starts a Graphback application.. - A
db.ts
file which indicates how to start a database connection.
- A
NOTE: All the files can be edited according to your needs except for those that are generated (no need to edit them as they'll be re-generated anyway).
If you made changes to your business model, it's advised to regenerate the generated-types.ts
which contains TypeScript file of your business entities.
yarn generate
This will update the generated schema.graphql
file and then generate the generated-types.ts
file.
Running yarn generate
executes a script which relies on two things, Graphback CLI and Codegen. It is a two step process which is explained below.
NOTE: You have to run the above commands on each modification of your business model on the server-side. This ensures that the client is kept in sync with changes on the server-side.
A GraphQL schema describes the functionality available to the client applications that connect to it. The Graphback CLI is used to run the graphback generate
command which executes the generation process to create a graphql schema. This schema is stored in the schema.graphql
file.
The next step is to use this schema to create the TypeScript types. Codegen is used in the graphql codegen
command which generates this code from the GraphQL schema in the generated-types.tsx
file. This makes sure that whenever you make changes to your data model you don't have to manually change the file because running yarn generate
does that for you.