英文:
I can't send graphql query with where condition on hasura
问题
我必须使用golang和Hasura发送graphql查询。但是我无法实现,因为我使用的查询不接受where条件。原因是我想将where作为一种类型发送。例如;
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)
如上所示,我有一个查询和where条件。但是当我发送查询时,我收到以下错误;
graphql: expected an object for type 'popular_streamers_bool_exp', but found a string
如何解决这个错误?谢谢你的帮助。
英文:
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.
答案1
得分: 1
在查询中,where
应该是一个对象。你没有正确编写where
子句。
你想查询"popular_streamers",所以你正在访问数据库以根据条件获取一些数据,并且你使用where
来指定这个条件。
query MyQuery($where: popular_streamers_bool_exp!) {
// specificProperty是你想要写条件的表中的列之一
// 获取所有specificProperty等于变量$where的popular_streamers
popular_streamers(where: {specificProperty: {_eq: $where}}) {
first_name
last_name
}
}
英文:
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
}
}
答案2
得分: 0
在代码块中,查询使用了变量进行搜索。
查询
query($query: String!) {
popular_streamers(where: {
popular_streamers_bool_exp: $query
}) {
first_name
last_name
}
}
GraphQL 变量
{
"query" : "Male"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论