Skip to content

Commit 48de3b1

Browse files
authored
Merge pull request graphql#1058 from verneleem/patch-1
Create dgraph.md
2 parents a9dc796 + ad3f180 commit 48de3b1

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

src/content/code/services/dgraph.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
name: Dgraph
3+
description: Dgraph is a native GraphQL database with a graph backend. This means Dgraph is not an interface on top of an existing database like Postgres but is actually designed from the ground-up for GraphQL. It is optimized for speed and performance, depending on multiple computer science breakthroughs to get the best result. Dgraph Cloud is a fully managed GraphQL backend service that lets you iterate faster, without worrying about your infrastructure.
4+
url: https://dgraph.io/graphql
5+
github: dgraph-io/dgraph
6+
---
7+
8+
Install Steps if running locally on linux not on Dgraph Cloud:
9+
10+
```bash
11+
docker pull dgraph/standalone
12+
mkdir -p ~/dgraph
13+
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 \
14+
-p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph \
15+
dgraph/standalone:master
16+
```
17+
18+
Set your GraphQL Schema:
19+
20+
```bash
21+
touch schema.graphql
22+
nano schema.graphql
23+
```
24+
25+
```graphql
26+
type Product {
27+
id: ID!
28+
name: String! @id
29+
reviews: [Review] @hasInverse(field: about)
30+
}
31+
32+
type Customer {
33+
username: String! @id
34+
reviews: [Review] @hasInverse(field: by)
35+
}
36+
37+
type Review {
38+
id: ID!
39+
about: Product!
40+
by: Customer!
41+
comment: String @search(by: [fulltext])
42+
rating: Int @search
43+
}
44+
```
45+
46+
```bash
47+
curl -X POST localhost:8080/admin/schema --data-binary '@schema.graphql'
48+
```
49+
50+
Fire up your favorite GraphQL Client pointed at `http://localhost:8080/graphql` and run mutations and queries
51+
52+
```graphql
53+
mutation {
54+
addProduct(input: [
55+
{ name: "Dgraph"},
56+
{ name: "Dgraph Cloud"}
57+
]) {
58+
product {
59+
id
60+
name
61+
}
62+
}
63+
addCustomer(input: [{ username: "TonyStark"}]) {
64+
customer {
65+
username
66+
}
67+
}
68+
}
69+
```
70+
71+
```graphql
72+
mutation {
73+
addReview(input: [{
74+
by: { username: "TonyStark" },
75+
about: { name: "Dgraph" },
76+
comment: "Fantastic, easy to install, worked great. Best GraphQL server available",
77+
rating: 10
78+
}]) {
79+
review {
80+
id
81+
comment
82+
rating
83+
by { username }
84+
about { id name }
85+
}
86+
}
87+
}
88+
```
89+
90+
```
91+
query {
92+
queryReview(filter: { comment: { alloftext: "server easy install" }, rating: { gt: 5 } }) {
93+
comment
94+
by {
95+
username
96+
reviews(order: { desc: rating }, first: 10) {
97+
about {
98+
name
99+
reviews(order: { asc: rating, first: 5 }) {
100+
by { username }
101+
comment
102+
rating
103+
}
104+
}
105+
rating
106+
}
107+
}
108+
about {
109+
name
110+
}
111+
}
112+
}
113+
```
114+

0 commit comments

Comments
 (0)