英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论