{"record":{"id":"5af27ad3f5e8ae0f","repo":"dgraph-io/dgraph","slug":"value-for-field-s-in-type-s-index-d-must","errorCode":null,"errorMessage":"value for field `%s` in type `%s` index `%d` must have exactly one child, found %d children","messagePattern":"value for field `(.+?)` in type `(.+?)` index `(.+?)` must have exactly one child, found (.+?) children","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation_rewriter.go","lineNumber":2031,"sourceCode":"\treturn ret, retTypes, retErrors\n}\n\nfunc existenceQueriesUnion(\n\tctx context.Context,\n\tparentTyp schema.Type,\n\tsrcField schema.FieldDefinition,\n\tvarGen *VariableGenerator,\n\tobj map[string]interface{},\n\txidMetadata *xidMetadata,\n\tlistIndex int) ([]*dql.GraphQuery, []string, []error) {\n\n\tvar retError []error\n\tif len(obj) != 1 {\n\t\tvar err error\n\t\t// if this was called from rewriteList,\n\t\t// the listIndex will tell which particular item in the list has an error.\n\t\tif listIndex >= 0 {\n\t\t\terr = fmt.Errorf(\n\t\t\t\t\"value for field `%s` in type `%s` index `%d` must have exactly one child, \"+\n\t\t\t\t\t\"found %d children\", srcField.Name(), parentTyp.Name(), listIndex, len(obj))\n\t\t} else {\n\t\t\terr = fmt.Errorf(\n\t\t\t\t\"value for field `%s` in type `%s` must have exactly one child, found %d children\",\n\t\t\t\tsrcField.Name(), parentTyp.Name(), len(obj))\n\t\t}\n\t\tretError = append(retError, err)\n\t\treturn nil, nil, retError\n\t}\n\n\tvar newtyp schema.Type\n\tfor memberRef, memberRefVal := range obj {\n\t\tmemberTypeName := strings.ToUpper(memberRef[:1]) + memberRef[1:len(\n\t\t\tmemberRef)-3]\n\t\tsrcField = srcField.WithMemberType(memberTypeName)\n\t\tnewtyp = srcField.Type()\n\t\tobj = memberRefVal.(map[string]interface{})","sourceCodeStart":2013,"sourceCodeEnd":2049,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation_rewriter.go#L2013-L2049","documentation":"GraphQL list fields of object type must contain objects, and each value for a field must have exactly one child object in the mutation input. When rewriting a list item (identified by listIndex), Dgraph found an object with a number of keys/children other than one, which it cannot interpret as a single node value. The error reports the field, parent type, list index, and child count.","triggerScenarios":"A mutation input where a list-typed field's item at the given index is an object with zero or multiple sibling keys where exactly one nested node value was expected — typically a malformed nested input structure inside rewriteList.","commonSituations":"Hand-written mutation JSON with mismatched braces, generators emitting `{ a: {...}, b: {...} }` where `{ a: {...} }` was intended, or empty objects `{}` appearing in lists.","solutions":["Inspect the list item at the reported index and reshape it so each entry contains exactly one child object.","Remove extraneous sibling keys or split them into separate list items.","Regenerate the payload from typed client code (e.g. graphql-codegen) instead of hand-building JSON.","Replace empty objects {} with a properly identified node (id or @id field)."],"exampleFix":"// before\nposts: [{ title: \"a\", extra: {} }] // 2 children at index 0\n// after\nposts: [{ title: \"a\" }] // exactly one child per list item","handlingStrategy":"validation","validationCode":"function assertSingleChildListItems(list) {\n  list.forEach((item, i) => {\n    if (typeof item !== 'object' || item === null || Object.keys(item).length !== 1) {\n      throw new Error(`list index ${i} must have exactly one child, found ${Object.keys(item || {}).length}`);\n    }\n  });\n}","typeGuard":"function isSingleChildNode(v) {\n  return typeof v === 'object' && v !== null && Object.keys(v).length === 1;\n}","tryCatchPattern":"try {\n  await client.mutate({ mutation: ADD, variables: { input } });\n} catch (e) {\n  if (/must have exactly one child/.test(e.message)) {\n    const m = e.message.match(/index `(\\d+)`/);\n    if (m) console.warn(\"fix list item at index\", m[1]);\n  } else throw e;\n}","preventionTips":["Generate mutation payloads with typed clients instead of hand-built JSON.","Validate nested object shapes (one child per value) before sending.","Never put empty objects {} inside list-typed fields.","Test mutations against a dev Dgraph instance before production."],"tags":["graphql","mutation","malformed-input"],"backgroundTag":"malformed-mutation-input","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}