{"record":{"id":"72b91e6115fdba93","repo":"gatsbyjs/gatsby","slug":"expected-non-null-field-value","errorCode":null,"errorMessage":"Expected non-null field value.","messagePattern":"Expected non-null field value\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/schema/schema.js","lineNumber":1367,"sourceCode":"\nconst stringifyArray = arr =>\n  `[${arr.map(item =>\n    Array.isArray(item) ? stringifyArray(item) : item.toString()\n  )}]`\n\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 => {","sourceCodeStart":1349,"sourceCodeEnd":1385,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/schema/schema.js#L1349-L1385","documentation":"validate() recurses a GraphQL type to parse/coerce a runtime value (used for default values and argument literals). When the type is GraphQLNonNull and the value is null/undefined, it throws. It indicates a null reached a field/argument the schema declared as non-null.","triggerScenarios":"Validating a default value or input literal against a non-null type where the supplied value resolves to null; a resolver returning null for a non-null field during default-value materialization.","commonSituations":"Schema customization with non-null fields whose default/resolved value is null; a plugin returning null where the declared type is Type!; fixture/test data missing a required field.","solutions":["Ensure the non-null field always receives a concrete value (fix resolver/source data).","Make the declared type nullable (remove the !) if null is legitimately possible.","Provide an explicit non-null defaultValue in the schema customization."],"exampleFix":"// before: field declared non-null but value resolves to null -> [162]\ntype Product implements Node { price: Float! }\n// after: allow null, or supply a default\ntype Product implements Node { price: Float }\n// or in createResolvers:\nProduct: { price: { resolve: (s) => s.price ?? 0 } }","handlingStrategy":"validation","validationCode":"const { GraphQLNonNull, GraphQLList } = require('graphql')\nfunction assertValidForType(type, value) {\n  if (type instanceof GraphQLNonNull && value == null) {\n    throw new Error(`Refusing to validate null against non-null ${type}`)\n  }\n}","typeGuard":"function isNonNullType(type) { return type instanceof GraphQLNonNull }","tryCatchPattern":null,"preventionTips":["Avoid declaring fields non-null unless the source truly guarantees a value.","Provide explicit defaultValue for non-null arguments in schema customization.","Unit-test resolvers returning data for non-null fields with empty fixtures."],"tags":["schema","graphql","validation","non-null"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}