Typescript date filtering on useQuery or StreamQuery

Hello everyone

I am using the useQuery hook and I am trying to filter by a date range.

const { contracts: historyContracts, loading: loadingContracts } =
        useStreamQueries(
            SomeContract,
            () => {
                return [
                    {
                        customer: party,
                        date: from 1980-01-01 to 2022-01-01
                    }
                ]
            },
            [party,]
        )

How can I use the JSON api query language applied to the hooks (useQuery or useStreamQueries)? Thank you in advance
https://docs.daml.com/json-api/search-query-language.html#comparison-query

useStreamQueries is from the @daml/react library, and from the docs, says it can only accept {field: value}, so really you can only query a specific date, and not a range I think.

If you need to query the range, it seems that you shouldn’t be using the hooks from the daml/react library, but rather explicitly create a GET request from your frontend.

1 Like

I don’t think the code of useStreamQueries adds any restriction, but if you’re using TypeScript it’s possible that the types do. I haven’t looked at the React bindings in a while, but I do remember it was pretty hard to express the full query language in TypeScript.

For the query language itself, though, the syntax for what you want would be:

const { contracts: historyContracts, loading: loadingContracts } =
        useStreamQueries(
            SomeContract,
            () => {
                return [
                    {
                        customer: party,
                        date: { "%gte": "1980-01-01", "%lte": "2022-01-01" }
                    }
                ]
            },
            [party,]
        )
2 Likes

@Gary_Verhaegen 's favorite issue! :troll: Please add support for the comparison language to the Typescript libraries. · Issue #7656 · digital-asset/daml · GitHub