umutaktepe
umutaktepe

Reputation: 50

I can't send graphql query with where condition on hasura

I have to send graphql query with using golang and Hasura. But I can't achieve that because the query I used doesn't accept where condition. The reason is that I want to send the where as a type. For example;

query MyQuery($where: popular_streamers_bool_exp!) {
    popular_streamers(where: $where) {
        first_name
        last_name
    }
}
type conditions struct {
    FollowersCount struct {
        Gte int `json:"_gte"`
    } `json:"followers_count"`
    Gender struct {
        Eq string `json:"_eq,omitempty"`
    } `json:"gender,omitempty"`
}
condition := conditions{}
condition.FollowersCount.Gte = 1
condition.Gender.Eq = "Male"

data, _ := json.Marshal(condition)

As you see above I have a query and where condition. But when I send the query I get an error like this;

graphql: expected an object for type 'popular_streamers_bool_exp', but found a string

How can solve this error? Thanks for your help.

Upvotes: 1

Views: 670

Answers (2)

Surya R Praveen
Surya R Praveen

Reputation: 3745

In the code block query does search with variables.

QUERY

query($query: String!) {
  popular_streamers(where: {
    popular_streamers_bool_exp: $query
  }) {
    first_name
    last_name
  }
}

GRAPHQL VARIABLES

{
    "query" : "Male"    
}

enter image description here

Upvotes: 0

Yilmaz
Yilmaz

Reputation: 49321

where in the query should be an object. You did not write where clause properly

You want to query "popular_streamers. so you are visiting the database to get some data based on a condition and you specify this condition with where`.

query MyQuery($where: popular_streamers_bool_exp!) {
    // specificProperty one of the columns in the table where you want to write condition
    // get me all popular_streamers where specificProperty is equal to variable $where
    popular_streamers(where: {specificProperty:{_eq:$where}) {
        first_name
        last_name
    }
}

Upvotes: 1

Related Questions