Sure,
GET_TASKS = gql`
subscription ($username: String!) {
queryTask {
id
title
completed
user(filter: { username: { eq: $username } }) {
username
}
}
}
`
But there is a caveat here. If you run this, you will probably end up with errors that the field user is required to have a value but it returns null. That happens because the query returns all of the task nodes whether they have the specified user or not. The filter on the user edge, does not filter the tasks, but rather the users that are returned. So how to filter the tasks to only the specific users? Well, the best and most efficient way to do it is to run the query I sent you that roots with the getUser and then traverses to the tasks. But if you have to root at queryTask for whatever reason, there is a way to do that: use the @cascade directive.
subscription ($username: String!) {
queryTask @cascade {
id
title
completed
user(filter: { username: { eq: $username } }) {
username
}
}
}
There will work with another caveat. (Not in your specific case though) If any field your queried results in null, then that task will be removed from the final list of tasks returned. In your case, all of the fields are required, so you shouldn’t run into a case where a title does not have a title or completed field. However, your User could have a nullable name field. So if you query this field using cascade and even though the username matches, the task would still be removed from the returned list due to a null user.name field. The way around this is to use cascade with parameters to list the fields that should be required. You can refer to the docs for that use case.
I would personally limit uses of cascade as much as possible and instead rearrange queries to put the filtered edge on the root as much as possible for best performance.