使用Spring Boot中的GraphQL进行过滤。

huangapple go评论66阅读模式
英文:

Filtering using GraphQL in spring boot

问题

在GraphQL中,是否有办法仅使用GraphQL进行筛选,而不在Spring Boot中进行任何更改?

这个筛选结果是来自Java部分的筛选。我希望使用GraphQL进行筛选,而不是Java,以获得相同的结果。

简单来说,Java将返回完整列表,而GraphQL应该在显示输出之前对其进行筛选。

架构:

type Query {
    userList(filter: String, range: String, sort: String): [User]
}

type User {
    id: ID
    name: String
    userAddressList: [UserAddress]
}

type UserAddress {
    id: ID
    userId: Int
    address: String
    user: User
}

查询:

query {
    userList(
        filter: "[{userAddressList:{address: nanjangud}}]",
    ){
        id
        name
        userAddressList {
            address
        }
    }
}

结果:

"data": {
    "userList": [
        {
            "id": "1",
            "name": "sdfg",
            "userAddressList": [
                {
                    "address": "Nanjangud"
                }
            ]
        }
    ]
}
英文:

Is there any way to filter only using graphQL and not making any changes in spring boot?

This filtered result is coming from the filter which is done in java part. I want the same result with the graphQL doing the filtering and not the java.

In simple words, Java will return the complete list and the graphQL should filter it before displaying the output.

The schema :

` type Query {
userList(filter: String, range: String, sort: String): [User]
}

type User {
id: ID
name: String
userAddressList: [UserAddress]

}

type UserAddress {
id: ID
userId: Int
address: String
user: User

}`

The Query :

` query{
userList(
filter: "[{userAddressList:{address: nanjangud}}]",

){
id
name
userAddressList {
address
}
}
}`

The result :

"data": {
"userList": [
{
"id": "1",
"name": "sdfg",
"userAddressList": [
{
"address": "Nanjangud"
}
]
}
]
}

答案1

得分: 0

I can provide the translation as requested:

不。尽管它的名字是GraphQL,但它并不是一个完整的“查询语言”,它没有排序或过滤的能力。GraphQL本身只指定了响应的“形状”,而不指定包含什么或以什么顺序包含。

英文:

No. Despite its name GraphQL is not a complete "query language" does not have sorting or filtering capabilities. GraphQL by itself only specifies the shape of the response, not what gets included or in what order.

huangapple
  • 本文由 发表于 2023年4月11日 16:44:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983979.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定