Skip to main content

Filtering by date is not working for me

  • September 20, 2023
  • 5 replies
  • 619 views

Hi,

I am building a query that I want to use for fetching items from a board with two conditions. The problem is that API rejects my query when I want to use operator between for date column type.

Initially I wanted to make a query that would basically say: “Give me all items that have checkbox checked and that have start date greater than some_date”.
But I couldn’t make it work so I decided to ask it in the way: “Give me all items that have checkbox checked and that have start date between date_1 - date_2”.

This works great when I write dates directly but doesn’t work when I use variables.

query AllItemsFiltered(
$boardId: ID!,
$checkboxColumnId: ID!,
$startDateColumnId: ID!,
$limit: Int!,
$columnValuesIds: [String!]!) {

    boards(ids: [$boardId]) {
        ...BoardItem
        items_page (limit: $limit, query_params: {
            rules: [
                {
                    column_id: $checkboxColumnId,
                    compare_value: [null],
                    operator: is_not_empty
                
                },
                {
                    column_id: $startDateColumnId,
                    compare_value: ["2023-03-04", "2024-02-02"], **# THIS WORKS**
                    operator: between
                },
            ],
            operator: and
            }) {
            cursor
            items {
                ...ItemFragment
                column_values(ids: $columnValuesIds) {
                    ...ColumnValueItem
                }
            }
        }
    }
}

On the other hand when I pass start and end dates as variables then I am getting API error saying: “List dimension mismatch on variable $startDate1 and argument compare_value ([CompareValue!]! / CompareValue!)

query AllItemsFiltered(
$boardId: ID!,
$checkboxColumnId: ID!,
$startDateColumnId: ID!,
$startDate1: CompareValue!,
$startDate2: CompareValue!,
$limit: Int!,
$columnValuesIds: [String!]!) {

    boards(ids: [$boardId]) {
        ...BoardItem
        items_page (limit: $limit, query_params: {
            rules: [
                {
                    column_id: $checkboxColumnId,
                    compare_value: [null],
                    operator: is_not_empty
                
                },
                {
                    column_id: $startDateColumnId,
                    compare_value: [$startDate1, $startDate2], **# THIS DOESN'T WORK**
                    operator: between
                },
            ],
            operator: and
            }) {
            cursor
            items {
                ...ItemFragment
                column_values(ids: $columnValuesIds) {
                    ...ColumnValueItem
                }
            }
        }
    }
}

I would appreciate any help with this one. Btw. I am using v2023-10 API.

5 replies

Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • September 21, 2023

Hello there @josipbernat,

You can pass the dates as this:

$datesBetween: CompareValue!

And then add the dates as an array in the variables: "datesBetween" : ["2022-03-04", "2023-08-21"]

Then inside items_page: compare_value: $datesBetween

I hope that helps!

Cheers,
Matias


  • Author
  • Participating Frequently
  • September 21, 2023

Looks like it’s working this way, thanks! It would be awesome if you could update docs with more examples like this.

Best,
Josip


  • Author
  • Participating Frequently
  • September 22, 2023

Well not so fast!

It turns out that CompareValue type is SCALAR but the solution you provided works with Array of Strings.
Below is a code snippet of variables from Postman and I don’t know why Postman allows that $datesBetween is Array when it must be Scalar and array isn’t Scalar.
I checked GraphQL schema and there is no part that would define Array as new custom scalar.

{
    "boardId":"some_board_id",
    "columnValuesIds":["name","checkbox7","date4"],
    "datesBetween":["2023-09-08", "2026-09-22"],
    "limit":100,
    "checkboxColumnId":"checkbox7",
    "startDateColumnId":"date4"
}

When I use Monday.com API Playground I am getting underlined variable with warning saying: “Expected value of type CompareValue”. But it in the end allows me to make the request.

On the other hand, the Apollo iOS client won’t accept Array as $datesBetween because CompareValue is String in the end. And Apollo generated this by consuming GraphQL schema. So it’s not something that I came up with.

typealias CompareValue = String

Schema that I used for generating Apollo support states following for CompareValue:

{
  "kind": "SCALAR",
  "name": "CompareValue",
  "description": null,
  "fields": null,
  "inputFields": null,
  "interfaces": null,
  "enumValues": null,
  "possibleTypes": null
},

Do you know how can I overcome this?


  • Author
  • Participating Frequently
  • September 27, 2023

Can anybody help me with this, please?


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • September 28, 2023

Hello there @josipbernat,

Sorry for the late reply!

We will need you to please send us an email to appsupport@monday.com with all this information so that we can take this as a ticket and look into this to find a solution for you.

Looking forward to hearing from you via email!

Cheers,
Matias