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.

UPDATE (April 2023): I replied again with a link to an example in documentation of creating a pagination UDF.

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

There is an example in the docs of how to create a UDF that accepts size, before and after arguments for pagination. This is often required for GraphQL custom resolvers, but the technique is not exclusive to that.