{"record":{"id":"bdfe4a79cad6b597","repo":"dgraph-io/dgraph","slug":"value-for-field-s-in-type-s-must-have-exactl","errorCode":null,"errorMessage":"value for field `%s` in type `%s` must have exactly one child, found %d children","messagePattern":"value for field `(.+?)` in type `(.+?)` must have exactly one child, found (.+?) children","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation_rewriter.go","lineNumber":2035,"sourceCode":"\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{})\n\t}\n\treturn existenceQueries(ctx, newtyp, srcField, varGen, obj, xidMetadata)\n}\n","sourceCodeStart":2017,"sourceCodeEnd":2053,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation_rewriter.go#L2017-L2053","documentation":"Same condition as the indexed variant: a value for a field must have exactly one child, but Dgraph found a different number. This variant is used when the offending value is not inside a list context (listIndex < 0), so no index is reported. The field name, parent type, and actual child count are included.","triggerScenarios":"A nested object in an add/update mutation where a field's value is an object containing zero or more than one child key when exactly one nested node was expected — outside of list rewriting.","commonSituations":"Copy-paste errors in nested mutation payloads, code generators emitting wrapper objects with extra metadata keys, or clients sending `{}` for a required nested node.","solutions":["Reshape the field value so it contains exactly one child object (one node with its fields).","Remove unexpected sibling keys from the nested object.","Ensure a nested node object is non-empty and identified via id or @id fields.","Use a typed GraphQL client to construct the payload and catch structural mistakes at build time."],"exampleFix":"// before\nauthor: { name: \"A\", username: \"x\", extra: 1 } // 3 children\n// after\nauthor: { name: \"A\", username: \"x\" } // valid single node value","handlingStrategy":"validation","validationCode":"function assertSingleChild(value, field) {\n  if (typeof value === 'object' && value !== null && Object.keys(value).length !== 1) {\n    throw new Error(`field ${field} must have exactly one child, found ${Object.keys(value).length}`);\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 f = e.message.match(/field `(\\w+)`/)[1];\n    console.warn(\"reshape nested value for field\", f);\n  } else throw e;\n}","preventionTips":["Keep nested node values as plain single objects with only node fields.","Strip metadata/wrapper keys from generated nested objects.","Use GraphQL codegen/typed SDKs to catch structure errors at compile time.","Review payloads in a network inspector when debugging mutation errors."],"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"}