instantdb/instant

React Native library Queries with `where X in <empty list>` fail with error "Validation failed for coerced-query"

Closed this issue · 2 comments

I have a simple use case for querying for all entities that the user just created:

const recentlyCreatedIds: string[] = []

// ... other code

function AView() {
    const { isLoading, error, data } = db.useQuery({
        "entities": {
            "$": {
                "limit": 5,
                "where": {
                    "id": {
                        "in": recentlyCreatedIds
                    }
                }
            }
        }
    })

    console.log(error?.message) // when recentlyCreatedIds is empty, this results in "Validation failed for coerced-query"
}

Expected:

The query returns an empty list of entities

Actual:

The query errors out with "Validation failed for coerced-query"

Additional maybe useful context:

Engine version: "@instantdb/react-native": "^0.12.11"

App ID: 26bb8d1e-9023-418e-8438-7d791260964d

Query that errors:

    const { isLoading, error, data } = db.useQuery({
        "activities": {
            "$": {
                "where": {
                    "id": {
                        "in": []
                    }
                }
            }
        }
    })

Note that In the dashboard explorer this query does NOT error

Query that succeeds, adding an empty string for the "in" clause match:

    const { isLoading, error, data } = db.useQuery({
        "activities": {
            "$": {
                "where": {
                    "id": {
                        "in": ['']
                    }
                }
            }
        }
    })

Fixed by eb68b58

Thanks for the report!