Reputation: 189
So i just started using graphql recently (last week to be precise). I get the concept of being able to filter queries with the 'where' argument and all but i noticed when i try to get objects from a deep nested query it becomes somewhat impossible. So say i have 'domestic_worker_nextofkin' query that should get fullname, mobile_phone1, and relationship where 'archived' _is_null equals true as given below:
domestic_workers_nextofkin(where: {archived:{_is_null: true}}){
full_name
mobile_phone1
domestic_workers_relationships{
relationship
}
}
}
The query above does it's intended job and gets the full_name, mobile_phone1 and relationship.
But my current problem is that when this query is deeply nested as shown below (the asterisked code):
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
}
}
}
}
It shows the 'where' argument highlighted as red, which possibly means that the 'where' argument shouldnt be placed there which seems rather confusing to me. Can anyone explain why this happens and show me a workaround to pull off the task i'm trying to perform? Thanks.
Upvotes: 3
Views: 6531
Reputation: 84857
From 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
is an object relationship (it returns a single object instead of an array of them), so it cannot be filtered.
Upvotes: 4