DgraphQL: Build a GraphQL service from a schema
Introduction
Dgraph is a distributed, highly available graph database that uses a language similar to GraphQL to query and mutate data. Unlike GraphQL, Dgraph only defines schema for predicates (properties) within the graph; there is no concept of complex types or groups of properties. Because of this it is straight forward to store any GraphQL schema in Dgraph provided a few restrictions are met.
Given a GraphQL schema, DgraphQL can do four things:
- Generate a GraphQL-JS schema that maps GraphQL queries to Dgraph queries
- Transform Dgraph responses into GraphQL responses (including support for the relay connection specification)
- Generate defaults for create/update/delete/query operations (with filtering, ordering and nested create/update mutations)
- Configure Dgraph's schema with types and indexes each property.
Check out the complete documentation for more.
Getting Started
The example describes basic usage. First, install dependencies:
yarn install
The example and test suite expect a Dgraph instance that you don't mind filling with junk running at http://localhost:8080. You can either install Dgraph or, better yet, run it in Docker:
yarn run dgraph:start
Run the example:
yarn start
Or run the test suite:
yarn test
To stop the containers:
yarn run dgraph:stop
Using DgraphQL
Install DgraphQL from npm
With yarn:
yarn add dgraphql
The entry point to the library is Client
const schema = `type Person { id: ID! name: String @filter(types: [EQUALITY]) children: [Person!]! @reverse(name: "parents") parents: [Person!]! @reverse(name: "children")}` const mutation = `mutation { createPerson(input: { name: "David" }) { person { id name } }}` const client = debug: false client