{"record":{"id":"42ef1b289700de6f","repo":"gatsbyjs/gatsby","slug":"the-argument-to-the-in-predicate-should-be-an-ar","errorCode":null,"errorMessage":"The argument to the `in` predicate should be an array","messagePattern":"The argument to the `in` predicate should be an array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/datastore/lmdb/query/filter-using-index.ts","lineNumber":505,"sourceCode":"}\n\nfunction resolveIndexFieldRanges(\n  context: IFilterContext,\n  query: DbQuery,\n  [field, sortDirection]: [fieldName: string, sortDirection: number]\n): {\n  rangeStarts: RangeBoundary\n  rangeEndings: RangeBoundary\n} {\n  // Tracking starts and ends separately instead of doing Array<[start, end]>\n  //  to simplify cartesian product creation later\n  const rangeStarts: RangeBoundary = []\n  const rangeEndings: RangeBoundary = []\n\n  const filter = getFilterStatement(query)\n\n  if (filter.comparator === DbComparator.IN && !Array.isArray(filter.value)) {\n    throw new Error(\"The argument to the `in` predicate should be an array\")\n  }\n\n  context.usedQueries.add(query)\n\n  switch (filter.comparator) {\n    case DbComparator.EQ:\n    case DbComparator.IN: {\n      const arr = Array.isArray(filter.value)\n        ? [...filter.value]\n        : [filter.value]\n\n      // Sort ranges by index sort direction\n      arr.sort((a: any, b: any): number => {\n        if (a === b) return 0\n        if (sortDirection === 1) return a > b ? 1 : -1\n        return a < b ? 1 : -1\n      })\n","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/datastore/lmdb/query/filter-using-index.ts#L487-L523","documentation":"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.","triggerScenarios":"A query using an index whose `in` filter value is a scalar; a GraphQL variable mis-typed as `ID` instead of `[ID]`.","commonSituations":"Same misuse as the in-memory `$in` check, but surfaced when the field has an index that the planner chooses.","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`."],"exampleFix":"// before\nfilter: { slug: { in: \"about\" } }\n// after\nfilter: { slug: { in: [\"about\"] } }","handlingStrategy":"type-guard","validationCode":"function asArray<T>(v: T | T[]): T[] { return Array.isArray(v) ? v : [v] }\n// filter: { slug: { in: asArray(slugs) } }\n","typeGuard":"function isInPredicateValue(v: unknown): v is unknown[] { return Array.isArray(v) }\n","tryCatchPattern":null,"preventionTips":["Type `in` variables as lists in the GraphQL operation.","Normalise at the caller so `in` always receives an array."],"tags":["graphql","query","filter","lmdb","indexing","datastore"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}