DEV Community

loading...

Database just from GraphQL! Dgraph Backend template

aexol profile image Artur Czemiel ・2 min read

GraphQL Editor Team - Dgraph Backend template

This template is worth 2020 ✨.

Brought by GraphQL Editor Team

Why?

You get database with GraphQL interface for storing your data just from GraphQL Schema.

How it works

Like that, and it is only from GraphQL Schema!! :

Dependencies

Docker

jq

These 2 are needed to run this

npm

Quick Start

Clone this repo

git clone https://github.com/graphql-editor/graphql-backend-template-dgraph
Enter fullscreen mode Exit fullscreen mode
npm install
Enter fullscreen mode Exit fullscreen mode

To start with this template you will need GraphQL Schema. Create one with GraphQL Editor and copy its contents to schema.graphql file.
Example schema can look like this Schema
Remember when using Dgraph you need only Types, Interfaces and Enums. Also there is a small bug in Dgraph which doesnt allow comments in schema files.

Or if you are lazy:

Forget about the schema and use one inside repo. Do nothing and proceed.

Run this command in one terminal

npm run dgraph
Enter fullscreen mode Exit fullscreen mode

And run this command in the other one

npm run inject-dgraph-schema
Enter fullscreen mode Exit fullscreen mode

Voila. Your GraphQL native database is ready to use. Run queries in a tool like Firecamp, so Insomnia, GraphiQL etc.

Generate Client libraries

When the server is running you can generate the actual dgraph generated schema file and autcomplete library for Javascript or TypeScript Frontend

Browser / React Native

TypeScript

npm run generate-nodets
Enter fullscreen mode Exit fullscreen mode

Javascript

npm run generate-nodejs
Enter fullscreen mode Exit fullscreen mode

Node

TypeScript

npm run generate-ts
Enter fullscreen mode Exit fullscreen mode

Javascript

npm run generate-js
Enter fullscreen mode Exit fullscreen mode

Author

Twitter - follow me for latest news with this boilerplate

Github - follow me for the latest news with this boilerplate

Under the hood

Dgraph

Zeus

Additional resources

Dgraph Definitions
Dgraph tutorial

Discussion

pic
Editor guide