0
votes

I am using a graphql query where the user inputs a name in a text field, which is then splitted into firstName and lastName and then passed into a query.

The where query generally works correctly with one variable but in this case, I keep getting an error that value of $where has a wrong structure

This query runs perfectly on my playground: ^

query{
  users(where: { firstName:"Myname", AND: {lastName:"Hello"}}){
    nodes{
      firstName,lastName,id, email, phoneNumber, userRelations{id,userId,type,relatedUserId}
    }
  }
}

And this is what I am doing in my code:

  const handleSubmit = React.useCallback(() => {
    let bothNames = name.split(" ");
    setFirstName(bothNames[0]);
    setLastName(bothNames[1]);
    console.log('Submitted');
    loadUsers({
      variables: {
        where: { firstName: firsttName, AND: {lastName:lasttName}},
      },
    });
    setName('');
  }, [loadUsers, name, firsttName, lasttName]);

Something like this works:

 where: { phoneNumber: phoneNumber },

What am I doing wrong?

1
check playground using variables - xadm
please place these brackets after AND like these AND: [ {} ] - Glory Raj
usually BOTH arguments are below in structure of logical operator - xadm
Below as in? @xadm - user13101751
The brackets worked! @EnigmaState - user13101751

1 Answers

1
votes

Fields at the top level are combined with an SQL AND. You will have to use like in the following way:

query{
  users(where: { 
      firstName: {_in: ["Myname"]},
      lastName: {_in: ["Hello"]}
   }){
    nodes{
      firstName,lastName,id, email, phoneNumber, userRelations{id,userId,type,relatedUserId}
    }
  }
}