hasura / hasura/graphql-engine

Request transform query_params string doesn't support Kriti range/concat for arrays with empty values

Open
#10,847 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

**Problem Statement:**
When using `query_params` as a string with Kriti templates to convert an array into repeated query parameters (e.g., `?properties=WANT&properties=OWN`), the template works for arrays with 1+ elements but fails with empty arrays (`[]`).

**Current Behavior:**
```yaml
# This template (from #7911):
query_params: '{{ concat([concat({{ range _, x := $body.input.data.properties }} "properties={{x}}&" {{ end }}), "profile_id={{$body.input.data.profile_id}}"]) }}'
```

- ✅ `[WANT, OWN]` → `?properties=WANT&properties=OWN&profile_id=prof1`
- ✅ `[OWN]` → `?properties=OWN&profile_id=prof1`
- ❌ `[]` → `Error: parsing Nested Object failed, expected Object, but encountered Array`

**Expected Behavior:**
When the array is empty (or the field is optional/not provided), the `properties` params should be omitted from the query string. The `concat` function with an empty array returns `[]` instead of an empty string, which breaks the query string construction.

**Related Issues:**
- #7911 - Added support for array transforms with `concat`/`range`, but doesn't handle empty arrays
- #9130 - Optional chaining `?.` in query params throws "Invalid Lexeme" error

**Alternative approaches tried:**
1. `query_params` as object → Can't have duplicate keys (can't send `properties=` twice)
2. `query_params` as string with `$body.input.data.properties[0]` → Only gets first element, loses second value for `[WANT, OWN]`
3. Optional chaining `?.` in query params → Throws "Invalid Lexeme" error (see #9130)
4. `{{$body.input.data?.properties ?? []}}` → Also fails with the same error

**Version:** Hasura v2.46.0

Contributor guide

Open the contributing guide

Research direction

Start by locating the query_params string parsing and Kriti template handling for concat and range, then reproduce the examples with non-empty and empty properties arrays. Done means empty or missing arrays omit the properties parameters without breaking the query string, while existing repeated parameters still work.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.