为什么我不能在 graphql 中过滤深层嵌套查询?
Why can't i filter a Deep nested query in graphql?
所以我最近才开始使用 graphql(准确地说是上周)。我得到了能够使用 'where' 参数过滤查询的概念,但我注意到当我尝试从深层嵌套查询中获取对象时,它变得有些不可能。所以说我有 'domestic_worker_nextofkin' 查询应该得到全名,mobile_phone1 和 'archived' _is_null 等于 true 的关系,如下所示:
domestic_workers_nextofkin(where: {archived:{_is_null: true}}){
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
}
}
上面的查询完成了预期的工作并获得了 full_name、mobile_phone1 和关系。
但我目前的问题是,当这个查询深度嵌套时,如下所示(带星号的代码):
query User($userId: Int) {
domestic_workers_news{
title
date_created
summary
url
}
users_user(where: {id: {_eq: $userId}}) {
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
id
password
username
first_name
last_name
email
gender
birth_date
mobile_phone1
mobile_phone2
home_address_street
home_address_town
home_address_lga
home_address_state
home_address_country
home_address_postal_code
job_title
workplace
verified
agreed_terms
date_joined
last_modified
domestic_workers_workers {
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
id
first_name
last_name
other_name
email
mobile_phone1
mobile_phone2
home_town
home_state
service
birth_date
gender
date_created
current_employer_id
domestic_workers_relationships{
id
payment
payment_currency
start_date
relationship
domestic_workers_agent {
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
}
**domestic_workers_nextofkin (where: {archived:{_is_null: true}}) {
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
}
}**
domestic_workers_reviews {
id
score
summary
date_created
users_user {
first_name
last_name
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
}
}
employerRelationships: domestic_workers_relationships(order_by: {id: desc}, limit: 1, where: {relationship: {_eq: "Employer"}}) {
end_date
relationship
}
}
}
}
它显示 'where' 参数突出显示为红色,这可能意味着 'where' 参数不应该放在那里,这让我感到很困惑。任何人都可以解释为什么会发生这种情况并向我展示一种解决方法来完成我正在尝试执行的任务吗?谢谢
来自the docs:
The where argument can be used in array relationships as well to filter the nested objects. Object relationships have only one nested object and hence they do not expose the where argument.
users_user
是一个对象关系(它returns是一个对象而不是它们的数组),所以它不能被过滤。
所以我最近才开始使用 graphql(准确地说是上周)。我得到了能够使用 'where' 参数过滤查询的概念,但我注意到当我尝试从深层嵌套查询中获取对象时,它变得有些不可能。所以说我有 'domestic_worker_nextofkin' 查询应该得到全名,mobile_phone1 和 'archived' _is_null 等于 true 的关系,如下所示:
domestic_workers_nextofkin(where: {archived:{_is_null: true}}){
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
}
}
上面的查询完成了预期的工作并获得了 full_name、mobile_phone1 和关系。
但我目前的问题是,当这个查询深度嵌套时,如下所示(带星号的代码):
query User($userId: Int) {
domestic_workers_news{
title
date_created
summary
url
}
users_user(where: {id: {_eq: $userId}}) {
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
id
password
username
first_name
last_name
email
gender
birth_date
mobile_phone1
mobile_phone2
home_address_street
home_address_town
home_address_lga
home_address_state
home_address_country
home_address_postal_code
job_title
workplace
verified
agreed_terms
date_joined
last_modified
domestic_workers_workers {
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
id
first_name
last_name
other_name
email
mobile_phone1
mobile_phone2
home_town
home_state
service
birth_date
gender
date_created
current_employer_id
domestic_workers_relationships{
id
payment
payment_currency
start_date
relationship
domestic_workers_agent {
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
}
**domestic_workers_nextofkin (where: {archived:{_is_null: true}}) {
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
}
}**
domestic_workers_reviews {
id
score
summary
date_created
users_user {
first_name
last_name
domestic_workers_pictures(order_by: {id: desc}, limit: 1) {
id
}
}
}
employerRelationships: domestic_workers_relationships(order_by: {id: desc}, limit: 1, where: {relationship: {_eq: "Employer"}}) {
end_date
relationship
}
}
}
}
它显示 'where' 参数突出显示为红色,这可能意味着 'where' 参数不应该放在那里,这让我感到很困惑。任何人都可以解释为什么会发生这种情况并向我展示一种解决方法来完成我正在尝试执行的任务吗?谢谢
来自the docs:
The where argument can be used in array relationships as well to filter the nested objects. Object relationships have only one nested object and hence they do not expose the where argument.
users_user
是一个对象关系(它returns是一个对象而不是它们的数组),所以它不能被过滤。