Filtering related docs via graphql

I’d like to create a GraphQL query that can return a filtered view of related docs. I’ve implemented the resolver which overwrites the items with the filtered result set and it seems to work via FQL but always returns all items when called via the graphql interface. Curious if this is possible or I’m breaking a rule. :slight_smile:

Here’s part of my schema and the function for reference.

type List @collection(name: "lists") {
  owner: User! @relation
  title: String
  created: Int
  updated: Int
  favorite: Boolean
  archive: Boolean
  items: [Item!] @relation
}

type Item @collection(name: "items") {
  list: List! @relation
  title: String
  archive: Boolean
}

type Query {
  userLists(args: UserListsInput!): [List!]! @resolver(paginated: true)
}
  CreateFunction({
    name: "listItems",
    body: Query(
      Lambda(
        ["args", "size", "after", "before"],
        Map(
          Paginate(
            Match(Index("items_by_list_archive"), [
              Ref(Collection("lists"), Select("list", Var("args"))),
              Select("archive", Var("args"), false)
            ]),
            { size: Var("size") }
          ),
          Lambda("item", Get(Var("item")))
        )
      )
    )
  }),
  CreateFunction({
    name: "userLists",
    body: Query(
      Lambda(
        ["args", "size", "after", "before"],
        Map(
          Paginate(
            If(
              Select("archive", Var("args"), false),
              Match(Index("list_owner_by_user"), [
                Ref(Collection("users"), Select("user", Var("args")))
              ]),
              Match(Index("list_by_owner_archive"), [
                Ref(Collection("users"), Select("user", Var("args"))),
                Select("archive", Var("args"), false)
              ])
            ),
            { size: Var("size") }
          ),
          Lambda(
            "list",
            Call(Function("addToData"), [
              Get(Var("list")),
              If(
                Select("items", Var("args"), false),
                {
                  items: Call(Function("listItems"), [
                    { list: Select("id", Var("list")) },
                    10,
                    "",
                    ""
                  ])
                },
                {}
              )
            ])
          )
        )
      )
    )
  })

Is your problem solved? This should definitely be possible but it’s hard to determine what goes wrong without setting up the exact same data model. Before I do so I quickly wanted to check whether you are still having this issue?

@databrecht This still reproduces for me. When using the GraphQL endpoint, if I request items in the response, it will fetch them automatically from the data model irrespective of the archive data element.

query userLists($user: ID!) {
  userLists(args: {
    user: $user,
    archive: false
  }) {
    data {
      _id
      title,
      items {
        data {
          title
          archive
        }
      }
    }
  }
}

The bug, imo, is that if I add the items arg, it should respect my provided response but doesn’t. Instead it appears to discard the data I gave it and fetch the same data as above.

query userLists($user: ID!) {
  userLists(args: {
    user: $user,
    archive: false,
    items: true
  }) {
    data {
      _id
      title,
      items {
        data {
          title
          archive
        }
      }
    }
  }
}

I can try to reproduce and determine whether this is a bug or not. However, could you make it easier for me and provide me with a schema that can stand on its own so that I can import it and test your queries?