Equivalent of COALESCE for predicates?

Newbie struggling with GraphQL+ queries here :slight_smile:

Is there a way to return a “default” if a requested predicate does not exist? For example, if my query is:
{
ret(func:uid(0x11d794)) {
uid
name
hasPoint@filter(allofterms(tags,“air fan supply sensor”) ){
point_name: name
}
}

Is there a way to get a “default” value for point_name in the event that no hasPoint matching my criteria is found?

Is it possible for you to assign default values for hasPoint predicate while uploading the data? I can’t think of any easy way to override node’s attributes during a query. Let me search some more in the meanwhile.

It’s not so much overriding a node’s attribute, but if a filter for a predicate fails to produce a match, provide a default match as a alternative.

Apologies but I am confused.

{
 ret(func:uid(0x11d794)) {
 uid
 name
 hasPoint@filter(allofterms(tags,“air fan supply sensor”) ){
  point_name: name
 }
}

You mean the above query should return:

0x11d794
nameA
hasPoint{ point_name: DefaultName }

since it didn’t find any point which satisfied the filter?

Something along those lines. We could construct the query differently, if necessary, but that is essentially the kind of result we’d want. And since we can’t predict which point(s) will match the terms, we can’t solve the problem by creating a node with name: DefaultName in advance.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.