I’m starting to use filtering and sorting more now, and the some/every/none and being able to filter multiple levels of the query is awesome. It would be insane to express these as SQL statements.
Also, I’m getting used to passing dynamic filters, and making my components more generic in what they display. Here’s filtering multiple levels (groups and items):
const GET_FOOS = gql`
query BarsList {
barsList(filter: {
foos: {
some: {
person: {
email: {
equals: "someone@somewhere.com"
}
}
}
}
},sort: {
sortOrder: ASC
}) {
items {
id
title
foos(filter: {
person: {
email: {
equals: "someone@somewhere.com"
}
}
}) {
items {
...foo
}
}
}
}
}
${fragments.foo}
`
Dynamic filter:
const GET_COMMENTS = gql`
query GetComments($filter: CommentFilter!) {
commentsList(filter: $filter) {
items {
id
postedDate
content
foo {
fooId
title
}
replies {
items {
id
postedDate
commenter {
id
firstName
lastName
avatar {
downloadUrl
}
}
content
}
}
commenter {
id
firstName
lastName
avatar {
downloadUrl
}
}
}
}
}
`
And my Comments component taking a filter:
const Comments = ({ filter }) => {
const { loading, error, data } = useQuery(GET_COMMENTS, {
variables: { filter }
})
...