登录
首页 >  Golang >  Go问答

我在 hasura 上无法使用带有 where 条件的 graphql 查询

来源:stackoverflow

时间:2024-02-06 20:38:14 263浏览 收藏

今天golang学习网给大家带来了《我在 hasura 上无法使用带有 where 条件的 graphql 查询》,其中涉及到的知识点包括等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~

问题内容

我必须使用 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

如何解决这个错误?感谢您的帮助。


正确答案


,其中查询中的 应该是一个对象。您没有正确编写 where 子句

您想要查询“popular_streamers。因此您正在访问数据库以根据条件获取一些数据,并使用 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
    }
}

理论要掌握,实操不能落!以上关于《我在 hasura 上无法使用带有 where 条件的 graphql 查询》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>