How to find nodes with a scalar predicate having values found during traversal

I am referring to this piece of code in implementation if eq() function -

// eq(score,val(myscore)), we disallow vars in facets filter so we don't need to worry about
// that as of now.
func (sg *SubGraph) replaceVarInFunc() error {
	if sg.SrcFunc == nil {
		return nil
	}
	var args []gql.Arg
	// Iterate over the args and replace value args with their values
	for _, arg := range sg.SrcFunc.Args {
		if !arg.IsValueVar {
			args = append(args, arg)
			continue
		}
		if len(sg.Params.uidToVal) == 0 {
			return x.Errorf("No value found for value variable %q", arg.Value)
		}
		// We don't care about uids, just take all the values and put as args.
		// There would be only one value var per subgraph as per current assumptions.
		seenArgs := make(map[string]struct{})
		for _, v := range sg.Params.uidToVal {
			data := types.ValueForType(types.StringID)
			if err := types.Marshal(v, &data); err != nil {
				return err
			}
			if _, ok := seenArgs[data.Value.(string)]; ok {
				continue
			}
			args = append(args, gql.Arg{Value: data.Value.(string)})
		}
	}
	sg.SrcFunc.Args = args
	return nil
}
if len(sg.Params.uidToVal) == 0 {
  return x.Errorf("No value found for value variable %q", arg.Value)
}

@MichelDiz
Just pinging to get attention on this thread. How do I handle situation when a value variable is empty.

hmm,

I think I get everything wrong. I was assuming the value var was right/real.
I din’t saw that you’re provoking the error by setting “Stesven” I though it was a test of yours. And I assumed
other thing in my head. I’m sorry for taking this conversation to long.

One detail that made me assume is that you should handle the errors by default. Cuz you receive an error response from the client. So I assume that everyone knows what to do in that situation.

So the answear is. Create a simple error handling, tho. I understand that one block with error can block the others blocks to execute. But a Query should be created with a context/propose. If one of the blocks has error. Is natural we invalidate the whole thing.

After seeing this query below that I realized that I was misleading everything:

{
  var(func: eq(name@en,"Minority Report")) {
    d as initial_release_date
  }

  me(func: eq(name@en, "Steven Spielberg")) {
    name@en
    director.film @filter(ge(initial_release_date, val(d))) {
      initial_release_date
      name@en
      val(d)
    }
  }
}

This could be a deal breaker for me. I was trying to emulate choose step from gremlin. And this can happen somewhere in the middle of deep traversal.

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