Skip to content

Instantly share code, notes, and snippets.

@vespertilian
Last active June 4, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vespertilian/20d7c8dcabd419630b29acdedb763780 to your computer and use it in GitHub Desktop.
Save vespertilian/20d7c8dcabd419630b29acdedb763780 to your computer and use it in GitHub Desktop.
DGraph useful search snippets

GraphQL+- ratel

Query

View Schema

schema {
  type
  index
  reverse
  tokenizer
}

Find all by predicate "name"

{
  q(func: has(name)) {
    name
  }
}

Find all by "skill_name: Ruby"

{
  q(func: eq(skill_name, "Ruby")) {
    skill_name
    skill_level
  }
}

Find by anyoftext "skill_name: Test" and return skills reverse edge (i.e a user) and all of there skills

{
  q(func: anyoftext(skillName, "Test ")) {
		skillLevel
    skillName
    ~skills {
      username
      emailAddress
      skills {
        skillName
        skillLevel
      }
    }
  }
}

Mutate

set a node with skill_name: Ruby and skill_level: 5

{
  set {
   _:ruby_mid_level <skill_name> "Ruby" .
   _:ruby_mid_level <skill_level> "5" .
  }
}

Alter

skill_name: string @index(hash) .
skill_level: int @index(int) .

Data types

Type Index Options
int int
float float
bool bool
string exact, hash, term, fulltext, trigram
dateTime year, month, day, hour
geo geo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment