Skip to content

Predicate name support in DQL variables #5031

@llonchj

Description

@llonchj

Given I have a node:

<_:1> <type:emailAccount> "" .
<_:1> <name> "test@example.com" .

I want to be able to retrieve the uid given the name and has(<type:emailAccount>).

I am trying to build the query using QueryWithVars and the golang api.

The query works with a hardcoded $type variable.

        variables := map[string]string{
    		"$name": Name,
    		// "$type": Type,
    	}
    
    	q := `
    	query uid($name: string)
    	{
    		uid(func:eq(name, $name)) @filter(has(<type:emailAccount>)) {
    		  uid
    		}
    	  }
    	`
    	resp, err := txn.QueryWithVars(ctx, q, variables)
    	if err != nil {
    		return "", err
    	}

If i try to use $type as variable, returns the error: rpc error: code = Unknown desc = Got empty attr for function: [has].

    	q := `
    	query uid($name: string)
    	{
    		uid(func:eq(name, $name)) @filter(has($type)) {
    		  uid
    		}
    	  }
    	`

What should be the query in order to work using $type to call has($type)?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalearea/querylang/varsIssues related to queries with GraphQL variableskind/featureSomething completely new we should consider.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions