'How do I create a lambda function for basic GraphQL filtering on FaunaDB?

I have a Query to filter my Premises by a query called premiseBySelectedFlag Like this.

 premiseBySelectedFlag(selected: Boolean!): [Premise!]!
    @resolver(name: "listAllSelectedPremises", paginated: true)

How do I create a function for this?

Currently, I have a basic function I use for my queries, like this

Query(
  Lambda(
    ["size", "after", "before"],
    Let(
      {
        match: Match(Index("latestSelectedPremises")),
        page: If(
          Equals(Var("before"), null),
          If(
            Equals(Var("after"), null),
            Paginate(Var("match"), { size: Var("size") }),
            Paginate(Var("match"), { after: Var("after"), size: Var("size") })
          ),
          Paginate(Var("match"), { before: Var("before"), size: Var("size") })
        )
      },
      Map(Var("page"), Lambda(["_", "ref"], Get(Var("ref"))))
    )
  )
)

But When i do this in my GraphQL playground

query{
  premiseBySelectedFlag(selected: true){
    data{
      _id
      content
      selected
    }
  }
}

I get this error in my GraphQL

{
  "errors": [
    {
      "message": "Lambda expects an array with 3 elements. Array contains 4.\n",
      "extensions": {
        "code": "invalid argument"
      }
    }
  ]
}

What is the correct way to create this function?

PS. I created the index latestSelectedPremises

enter image description here Is this correct?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source