Repository navigation
Description
Package
@storyblok/api-client, @storyblok/management-api-client
Bug Description
The types of the multi-value filter_query operators (in_array, all_in_array, and any_in_array once #965 lands) accept Array<string> | string. An array type-checks, but the client sends it as repeated keys (…[in_array]=red&…[in_array]=blue). The Content Delivery API reads these operators as a single comma-separated string and keeps only the last repeated key, so the filter silently uses the last value only. No error is raised.
The filter query docs only describe the comma-separated form: "Separate the values by a comma to filter by multiple values."
@storyblok/management-api-client uses the same query serializer. Its types only accept string for these operators, so it is only affected when an array is passed with a cast.
Steps to Reproduce
- In a space, create four stories with a string-array field
colors: a["red"], b["blue"], c["red", "blue"], d["green"]. - Query them with the array form and the string form:
import { createApiClient } from "@storyblok/api-client";
const client = createApiClient({ accessToken: "<preview token>" });
// Returns b, c
await client.stories.list({
query: { version: "draft", filter_query: { colors: { in_array: ["red", "blue"] } } },
});
// Returns a, b, c
await client.stories.list({
query: { version: "draft", filter_query: { colors: { in_array: "red,blue" } } },
});Reproduction URL
No response
Expected Behavior
Either the array form returns the same stories as the comma-separated string, or the types reject an array.
Actual Behavior
The array form filters on its last value only. Filtering on red and blue against the Content Delivery API:
| How the values are sent | any_in_array |
in_array |
all_in_array |
|---|---|---|---|
=red,blue |
a, b, c ✅ | a, b, c ✅ | c ✅ |
=red&…=blue (what the client sends) |
b, c ❌ | b, c ❌ | b, c ❌ |
[]=red&…[]=blue |
400: must be a string of comma separated values | same | same |
Environment
Node: 24.18.0
@storyblok/api-client: 0.14.0
@storyblok/management-api-client: 0.14.0Error Logs
None. The request succeeds and returns the wrong stories.Additional Context
- Not a regression: arrays have been typed and sent this way since
@storyblok/api-client0.10.0. Thefilter_querytype comes from the Content Delivery API OpenAPI spec, which declares these operators asoneOf: [array of strings, string]. - Found during review of fix(capi-client): accept any_in_array in stories filter_query #965: fix(capi-client): accept any_in_array in stories filter_query #965 (comment)
- Proposed fix: type these operators as
stringonly, matching the docs (fix(capi-client): type multi-value filter_query operators as strings #967). Joining arrays with commas in the serializer was considered and dropped, because it would add afilter_queryspecial case to the serializer.
Activity
fix(capi-client): type multi-value filter_query operators as strings
[-][Bug]: array values in filter_query silently filter on the last value only[/-][+]Blocked:[Bug]: array values in filter_query silently filter on the last value only[/+][-]Blocked:[Bug]: array values in filter_query silently filter on the last value only[/-][+][Bug]: array values in filter_query silently filter on the last value only[/+]