Filtering in autogenerated GraphQL queries

Fauna relies on your feedback to educate our product development process. To help us prioritize this feature in our product roadmap, please vote for this topic and complete our 2020 GraphQL Roadmap Survey. Additionally, please reply to this post to share your use case/s for this feature, and your experiences (good or bad) using it in other products.

Proposal

This would likely follow the autogenerated API defined by the OpenCRUD spec. See OpenCRUD: Query filters

Workaround example

While you wait for this new feature to be released, here is one way to work around it. If you have implemented your own solutions that you think could help other users, please share them as replies to this topic and/or make a gist and link to it from the awesome-faunadb list.

1. Import schema:

type Todo {
  title: String
  done: Boolean
}

type Query {
  findTodos(title: String, done: Boolean): [Todo!]! @resolver(name: "findTodos", paginated: true)
}

2. Update UDF:

Update(
  Function("findTodos"),
  {
    "body": Query (
      Lambda(["title", "done", "size", "after", "before"],
        Let(
          {
            match:
              Filter(
                Match(Index("allTodos")), ref => 
                  Let(
                    {
                      "todo": Get(ref)
                    },
                    And(
                      If(
                        IsNull(Var("title")),
                        true,
                        ContainsStr(Select(["data", "title"], Var("todo")), Var("title"))
                      ),
                      If(
                        IsNull(Var("done")),
                        true,
                        Equals(Select(["data", "done"], Var("todo")), Var("done"))
                      )
                    )
                  )   
                
              ),
            page: If(
              Equals(Var("before"), null),
              If(
                Equals(Var("after"), null),
                  Paginate(Var("match"), { size: Var("size") }),
                  Paginate(Var("match"), { size: Var("size"), after: Var("after") })
              ),
              Paginate(Var("match"), { size: Var("size"), before: Var("before") }),
            )
          },
          Map(Var("page"), Lambda("ref", Get(Var("ref"))))
        )
      )
    )
  }
);