Passing paging parameters to a Function

Hi,

I have an index and I’m using it from within a UDF. I’d like to allow the user to pass size/before/after parameters to the function and to use them inside when calling to the index.

Here’s what I tried, but it doesn’t work:

Query(
  Lambda(
    [
      "paramA",
      "paramB",
      "size",
      "cursorBefore",
      "cursorAfter"
    ],
    Let(
      {
        paging: If(
          Not(IsNull(Var("cursorAfter"))),
          { size: Var("size"), after: Var("cursorAfter") },
          If(
            Not(IsNull(Var("cursorBefore"))),
            { size: Var("size"), before: Var("cursorBefore") },
            { size: Var("size") }
          )
        )
      },
      Map(
        Paginate(
            Match(Index("my_index"), [
              Var("paramA"),
              Var("paramB")
            ])
          ),
          Var("paging") /*couldn't get anything here that works*/
        ),
        Lambda(
          ["ref"],
          Get(Var("ref"))
        )
      )
    )
  )
)

The above definition of paging is very verbose and I got to it after a lot of trial and error that didn’t work. It seems that Paginate only accepts static paging definition.

Any idea?
Thanks!

This is right. Though it is unfortunate. There might already be a ticket out to fix that, but I certainly don’t know where it is.

You’ll have to put the Pagination function in each branch of If functions. I like to use a helper function in js to make defining these kind of UDFs easier.

The following is part time of a topic on GraphQl, but this bit is as every bit of relevant for plain FQL.

Hi @ptpaterson, thanks for the quick reply.
I will try that later today