getList with id filter

in the How to use relationships in GraphQL | Fauna Documentation example on number 5 ** Query the list for related todos the way the example queried todos on a list is through:

query FindAListByID {
  findListByID(id: "234458015536775681") {
    title
    todos {
      data {
        title
      	completed
      }
    }
  }
}

I can’t find an example like

query todosByList ($listId: ID!) {
  todos (listId: $listId) {
    _id
    title
  }
}

Do we have to manually create this query with a custom resolver?

You would have to create a custom resolver for this.

In my opinion, the more canonical GraphQL-way to do such a query is to first search for the List document, then perform a subselection for the todos. If you use a GraphQL client library that has caching built in (such as Apollo) it will make more sense why this is a better pattern for caching too. Basically, it makes sure that your client can understand and update the graph when you make new requests. When your results skip over relationships, you have to manually patch the relationships together in your client application. WIth the nested result, the relationships are already spelled out and you client application can understand the relationship without additional effort.

AHA! thanks for explaining that, now I am enlightened about why this is, however, you did not mention pagination.

Pagination comes by default if you use the built in API, rather than create a new, custom resolver. In my opinion, this is another good reason to use the find-one+subselection pattern. That said, you can of course use the pagination: true argument for the @resolver directive and provide the pagination functionality yourself – it’s just more work for the developer.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.