gatsbyjs/gatsby · error · Error
The argument to the `in` predicate should be an array
Error message
The argument to the `in` predicate should be an array
What it means
When the LMDB query planner turns a filter into an index range, the `in` predicate must have an Array value to produce a multi-range scan. A non-array `in` value is rejected at plan time (the in-memory runner has a parallel check) before any range is built.
Source
Thrown at packages/gatsby/src/datastore/lmdb/query/filter-using-index.ts:505
}
function resolveIndexFieldRanges(
context: IFilterContext,
query: DbQuery,
[field, sortDirection]: [fieldName: string, sortDirection: number]
): {
rangeStarts: RangeBoundary
rangeEndings: RangeBoundary
} {
// Tracking starts and ends separately instead of doing Array<[start, end]>
// to simplify cartesian product creation later
const rangeStarts: RangeBoundary = []
const rangeEndings: RangeBoundary = []
const filter = getFilterStatement(query)
if (filter.comparator === DbComparator.IN && !Array.isArray(filter.value)) {
throw new Error("The argument to the `in` predicate should be an array")
}
context.usedQueries.add(query)
switch (filter.comparator) {
case DbComparator.EQ:
case DbComparator.IN: {
const arr = Array.isArray(filter.value)
? [...filter.value]
: [filter.value]
// Sort ranges by index sort direction
arr.sort((a: any, b: any): number => {
if (a === b) return 0
if (sortDirection === 1) return a > b ? 1 : -1
return a < b ? 1 : -1
})
View on GitHub (pinned to 8b06340921)
Solutions
- Make the `in` value an array.
- Type the GraphQL variable as a list.
- If a single match is intended, use `eq` instead of `in`.
Example fix
// before
filter: { slug: { in: "about" } }
// after
filter: { slug: { in: ["about"] } } Defensive patterns
Strategy: type-guard
Validate before calling
function asArray<T>(v: T | T[]): T[] { return Array.isArray(v) ? v : [v] }
// filter: { slug: { in: asArray(slugs) } }
Type guard
function isInPredicateValue(v: unknown): v is unknown[] { return Array.isArray(v) }
Prevention
- Type `in` variables as lists in the GraphQL operation.
- Normalise at the caller so `in` always receives an array.
When it happens
Trigger: A query using an index whose `in` filter value is a scalar; a GraphQL variable mis-typed as `ID` instead of `[ID]`.
Common situations: Same misuse as the in-memory `$in` check, but surfaced when the field has an index that the planner chooses.
Related errors
- ${filter.comparator} value must not be an array
- Range filter ${predicate} should not have array value
- Range filter ${predicate} should not have value of type ${ty
- Bad filter value for predicate ${filter.comparator}: ${inspe
- The $regex comparator is expecting the regex as a string, no
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/42ef1b289700de6f.
Report an issue: GitHub.