Query - get_all - Multiple Inputs

Hi,

As stated over here link, it query for ‘Alice’ and it results for all the information for ‘Alice’.

What if I have ‘n’ dynamic inputs (size of ‘n’ isn’t fixed) in order to get all information say n=2, ‘Alice’, ‘Bob’

What would be the query? I tried to define variables_1 = {'$b': 'Alice, Bob'} and defining $b: list in query list or array but not working.
I tried with defining list instead of string on the query but not working.

P.S - I am using pydgraph.

The answer in Github was not satisfactory? please elaborate a little more.

You do not necessarily need to use GraphQL Variables. You are using a Dgraph (py) client. So you can do the “templating” of the query and model you as need. GraphQL Variables are more for those who need to fit into GraphQL (my opinion).

Cheers.

Hi @MichelDiz,

I wasn’t able to understand, could you please elaborate.
Appreciate your time.

Thanks.

Alright.

The example that you are using uses “GraphQL Variables” that you can find details here https://docs.dgraph.io/query-language/#graphql-variables

In fact, GraphQL Variables does not expand multiple values in brackets. So what you want to do would not work. However, you could use “anyofterms” instead of “eq”. If indexing is appropriate.

e.g:

{
  data(func: anyofterms(name, "Alice Bob")) {
    name
    rated @facets(r as rating) {
      name
    }
    avg(val(r))
  }
}

which in your case would look like this

query = """query all($a: string) {
  all(func: anyofterms(name, $a))
  {
    name
  }
}"""
variables = {'$a': 'Alice bob'}

As I said earlier, it would be interesting to do our tour before. GraphQL Variables are somewhat specific for some uses. You can do several things without GraphQL Variables.
https://tour.dgraph.io

Another thing you can do instead of using Graphql Variables. You would model the query according to usage. Queries are just “text”. In JavaScript we do things like “Templating” that exists in several languages. I do not know how it would work in Py, but certainly there are.

Template_literals: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

I think that’s it, any doubt just call it.

Cheers.

1 Like

Thanks alot @MichelDiz,
it is showing error for anyofterm
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNKNOWN, : Attribute name is not indexed with type term)>

But its working for anyoftext .

To use anyofterm you have to change the indexing to

name: string @index(exact, term) .

alloftext may be working for you because you may have changed the default (from example ‘name: string @index(exact) .’) to

name: string @index(exact, fulltext) .

I would recommend you use term indexing.

allofterms: https://docs.dgraph.io/query-language/#term-matching

alloftext: https://docs.dgraph.io/query-language/#full-text-search

you can learn more about indexes using our tour: https://tour.dgraph.io/search/1/

Cheers

1 Like

Thanks @MichelDiz for helping me out.

Thanks a ton !!

1 Like