Install Steps if running locally on linux not on Dgraph Cloud:
docker pull dgraph/standalone
mkdir -p ~/dgraph
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 \
-p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph \
dgraph/standalone:master
Set your GraphQL Schema:
touch schema.graphql
nano schema.graphql
type Product {
id: ID!
name: String! @id
reviews: [Review] @hasInverse(field: about)
}
type Customer {
username: String! @id
reviews: [Review] @hasInverse(field: by)
}
type Review {
id: ID!
about: Product!
by: Customer!
comment: String @search(by: [fulltext])
rating: Int @search
}
curl -X POST localhost:8080/admin/schema --data-binary '@schema.graphql'
Fire up your favorite GraphQL Client pointed at http://localhost:8080/graphql
and run mutations and queries
mutation {
addProduct(input: [{ name: "Dgraph" }, { name: "Dgraph Cloud" }]) {
product {
id
name
}
}
addCustomer(input: [{ username: "TonyStark" }]) {
customer {
username
}
}
}
mutation {
addReview(
input: [
{
by: { username: "TonyStark" }
about: { name: "Dgraph" }
comment: "Fantastic, easy to install, worked great. Best GraphQL server available"
rating: 10
}
]
) {
review {
id
comment
rating
by {
username
}
about {
id
name
}
}
}
}
query {
queryReview(
filter: { comment: { alloftext: "server easy install" }, rating: { gt: 5 } }
) {
comment
by {
username
reviews(order: { desc: rating }, first: 10) {
about {
name
reviews(order: { asc: rating, first: 5 }) {
by {
username
}
comment
rating
}
}
rating
}
}
about {
name
}
}
}