{"record":{"id":"5b26724b5c56bf0b","repo":"gatsbyjs/gatsby","slug":"expected-array-field-value","errorCode":null,"errorMessage":"Expected array field value.","messagePattern":"Expected array field value\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/schema/schema.js","lineNumber":1372,"sourceCode":"\n// TODO: Import this directly from graphql-compose once we update to v7\nconst isNamedTypeComposer = type =>\n  type instanceof ObjectTypeComposer ||\n  type instanceof InputTypeComposer ||\n  type instanceof ScalarTypeComposer ||\n  type instanceof EnumTypeComposer ||\n  type instanceof InterfaceTypeComposer ||\n  type instanceof UnionTypeComposer\n\nconst validate = (type, value) => {\n  if (type instanceof GraphQLNonNull) {\n    if (value == null) {\n      throw new Error(`Expected non-null field value.`)\n    }\n    return validate(type.ofType, value)\n  } else if (type instanceof GraphQLList) {\n    if (!Array.isArray(value)) {\n      throw new Error(`Expected array field value.`)\n    }\n    return value.map(v => validate(type.ofType, v))\n  } else {\n    return type.parseValue(value)\n  }\n}\n\nconst isNodeInterface = interfaceTypeComposer =>\n  interfaceTypeComposer.hasInterface(`Node`)\n\nconst checkQueryableInterfaces = ({ schemaComposer }) => {\n  const queryableInterfaces = new Set()\n  schemaComposer.forEach(type => {\n    if (type instanceof InterfaceTypeComposer && isNodeInterface(type)) {\n      queryableInterfaces.add(type.getTypeName())\n    }\n  })\n  const incorrectTypes = new Set()","sourceCodeStart":1354,"sourceCodeEnd":1390,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/schema/schema.js#L1354-L1390","documentation":"validate() expects an Array when the type is GraphQLList. It throws when a list-typed field/argument is given a non-array value during default-value or literal validation.","triggerScenarios":"A field/argument declared [Type!] receiving a single scalar/object instead of an array during validate (default values, input coercion, directive args).","commonSituations":"Source data providing one value where the schema expects a list; schema customization type mismatch (declared list, returned scalar); incorrect default values in directives.","solutions":["Wrap the value in an array at the source/resolver level.","Correct the declared type (use scalar instead of [scalar]) if a single value is intended.","Transform data in sourceNodes so list fields always yield arrays."],"exampleFix":"// before: tags declared [String!] but node has tags: \"a,b\"\ntype Post implements Node { tags: [String!]! }\n// after: normalize to an array in sourceNodes\nactions.createNode({ ...node, tags: typeof node.tags === 'string' ? node.tags.split(',') : node.tags ?? [] })","handlingStrategy":"validation","validationCode":"const { GraphQLList } = require('graphql')\nfunction ensureArrayForListType(type, value) {\n  if (type instanceof GraphQLList && !Array.isArray(value)) {\n    return Array.isArray(value) ? value : (value == null ? [] : [value])\n  }\n  return value\n}","typeGuard":"function isListType(type) { return type instanceof GraphQLList }","tryCatchPattern":null,"preventionTips":["Normalize source data so list-typed fields always yield arrays in sourceNodes.","Double-check declared list vs scalar types in createTypes against actual data.","Add fixtures exercising single-value list fields in plugin tests."],"tags":["schema","graphql","validation","list"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}