Improve param, Inequality and Value Variables syntax - Under Construction (draft)

Comma: "And"
Single Pipe: "OR"
Double pipe: "if/else" eg: `uid(0x1, 0x2 || val(a), 0xe)`
Cond: "first operand must be a boolean" eg:`uid(cond(val(x), val(Y), 0xe)))`

We can find cond param in Get started with Dgraph

This would result in less typing and better logic treatment with params.

BTW, in some cases would be nice to extract the params to a custom block so we can have an organized call, and also the params could be used in other blocks or nested blocks.

Examples:

Original usage with Sorting

This example shows that we would have a lot of typing adding more and more orderasc. Imagine if we have 3 orderasc and 3 orderdesc. The typing would be bad.

{
    me(func: uid(0x1, 0x2), orderasc: name, orderasc: age, first: 6, offset: 1) {
		 	name
		 	age
	 	}
	 }
  • q(func: ..., orderasc: predicate)
  • q(func: ..., orderdesc: val(varName))
  • q(func: ..., orderdesc: val(varName|varName2|AnotherVar))
  • predicate (orderdesc: predicate) { ... }
  • predicate @filter(...) (orderasc: N) { ... }
  • q(func: ..., orderasc: (predicate1|predicate2) )

instead of (Get started with Dgraph)

  • q(func: ..., orderasc: predicate)
  • q(func: ..., orderdesc: val(varName))
  • predicate (orderdesc: predicate) { ... }
  • predicate @filter(...) (orderasc: N) { ... }
  • q(func: ..., orderasc: predicate1, orderdesc: predicate2)

example 1

{
    me(func: uid(0x1, 0x2), orderasc: (name|age) first: 6, offset: 1) {
		 	name
		 	age
	 	}
	 }

If we have name we order by name, and if we found nodes with age, then we keep ordering by age.

example 2

{
    me(func: uid(0x1, 0x2), orderasc: (name,age) first: 6, offset: 1) {
		 	name
		 	age
	 	}
	 }

Well, this would be the same as example 1, cuz there’s no meaning add a constraint here.

Original usage with Value Variables

Syntax Examples:

  • val(var-name)
  • val(var-name|var-name2|var-name3) “Could also use comma”
  • val(var-name,var-name2 || var-name3,var-name4)
    "if the first two variables are false, return the second “var-name3,var-name4”.

Value variables are used by extracting the values with val(var-name) , or by extracting the UIDs with uid(var-name) .

Original usage with Inequality

Syntax Examples:

  • eq(predicate, value)
  • eq(val(varName), value)
  • eq(val(varName|varName2|varName3), value)
  • eq(predicate, val(varName))
  • eq(predicate, val(varName|varName2|varName3))
  • eq(count(predicate), value)
  • eq(predicate, [val1, val2, ..., val(N]))
  • eq(predicate, [val1, val2, ..., val(N|N2|N3))
  • eq(predicate, [$var1, "value", ..., val(N|N2|N3)])

less than, less than or equal to, greater than and greater than or equal to

Syntax Examples: for inequality IE

  • IE(predicate, value)
  • IE(val(varName), value)
  • IE(val(varName|varName2|varName3), value)
  • IE(predicate, val(varName))
  • IE(predicate, val(varName|varName2|varName3))
  • IE(count(predicate), value)