I am trying to fetch a collection filtered by timestamp using a gql resolver.
Therefore I created an index, which maps timestamp to ref(TransactionEvent)
export default {
name: "all_transaction_events_by_ts",
source: Collection("TransactionEvent"),
values: [{ field: ["data", "timestamp"] }, { field: ["ref"] }],
}
Afterwards I tried to create and udf, which runs, but does not return any data.
export default {
name: "allTransactionEventsByTs",
body: Query(
Lambda(
["timestamp", "size", "after", "before"],
Let(
{
match: Range(
Match(Index("all_transaction_events_by_ts")),
Var("timestamp"),
Now()
),
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(Select("data", Var("page")), Lambda(["ts", "ref"], Get(Var("ref"))))
)
)
),
}
However, running the query in fauna shell works:
Let(
{
match: Range(Match(Index("all_transaction_events_by_ts")), 0, Now()),
page: Paginate(Var("match"), { size: 2 }),
},
Map(Select("data", Var("page")), Lambda(["ts", "ref"], Get(Var("ref"))))
)
returns
[
{
ref: Ref(Collection("TransactionEvent"), "336715287670819008"),
ts: 1657375571990000,
data: {
timestamp: 1654735525113,
transactionRevenue: 6,
sessionCount: 3,
customer: Ref(Collection("Customer"), "336715287580639424"),
utmTerm: "67dc5354-8f0b-46b7-afcc-f375b5beebcb",
offline: false,
transactionId: "19021526"
}
},
{
ref: Ref(Collection("TransactionEvent"), "336715288339808455"),
ts: 1657375572610000,
data: {
timestamp: 1654735525113,
transactionRevenue: 6,
sessionCount: 3,
customer: Ref(Collection("Customer"), "336715288252776647"),
utmTerm: "67dc5354-8f0b-46b7-afcc-f375b5beebcb",
offline: false,
transactionId: "79042313"
}
}
]
Here is the schema.gql entry
type Query {
allTransactionEventsByTs(timestamp: Long!): [TransactionEvent!]
@resolver(name: "allTransactionEventsByTs", paginated: true)
}
I’d highly appreciate any kind of help, since I am working on this for 2 days now.
PS: Using this line at the end of the UDF as written in the docs
Map(Var("page"), Lambda("ref", Get(Var("ref"))))
results in the following error
{
"errors": [
{
"message": "Ref or Set expected, Array provided.\n",
"extensions": {
"code": "invalid argument"
}
}
]
}