Dgraph Example Queries
source link: https://kenanbek.github.io/dgraph-example-queries-json
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Dgraph Example Queries
Published: Apr 27, 2020 / Last modified: May 3, 2020
Dgraph Example Queries (JSON)
Hello, coders! In this page I’ve gather different Dgraph example queries.
Most of the examples are taken or extended version of examples from https://tour.dgraph.io/.
Follow this and this to create a schema and load an example data.
For more information on Dgraph.io and it’s usage with Go check my another article called “Dgraph Graph Database: How to Install and Use With Go?”.
Query #1: find by name
{
find_michael(func: eq(name@., "Michael")) {
uid
name@.
age
}
}
Query #2: get by name and show related edges
{
michaels_friends(func: eq(name, "Michael")) {
name
age
owns_pet {
name@.
}
friend {
name@.
}
}
}
Query #3: get schema information
schema(pred: [name, age, friend, owns_pet]) {
type
index
}
By adding type
and index
in body we request to include type and index information about the scheme in the response.
Query #4: get by annotated language tag
{
language_support(func: allofterms(name@hi, "अमित")) {
name@bn:hi:en
age
friend {
name@ko:ru
age
}
}
}
Syntax name@bn:hi:en
specifies an order preference in which name field must be returned. More information here.
Query #5: get all nodes count by a specific field name
{
nodeCount(func: has(<message>)) {
nodeCount: count(uid)
}
}
Query #6: get all nodes related to a specific type
{
q(func: type(Log)) {
uid
created
message
}
}
Query #7: query and filter by field’s type
{
q(func: has(parent)) {
uid
parent @filter(type(Person)) {
uid
name
}
}
}
Check source for more information.
[ Tags ]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK