{"record":{"id":"83a9b5a875c97146","repo":"dgraph-io/dgraph","slug":"can-t-convert-input-to-map","errorCode":null,"errorMessage":"can't convert input to map","messagePattern":"can't convert input to map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/admin/assign.go","lineNumber":80,"sourceCode":"\t\tendId = json.Number(strconv.FormatUint(resp.GetEndId(), 10))\n\t}\n\n\treturn resolve.DataResult(m,\n\t\tmap[string]interface{}{m.Name(): map[string]interface{}{\n\t\t\t\"response\": map[string]interface{}{\n\t\t\t\t\"startId\":  startId,\n\t\t\t\t\"endId\":    endId,\n\t\t\t\t\"readOnly\": readOnly,\n\t\t\t},\n\t\t}},\n\t\tnil,\n\t), true\n}\n\nfunc getAssignInput(m schema.Mutation) (*assignInput, error) {\n\tinputArg, ok := m.ArgValue(schema.InputArgName).(map[string]interface{})\n\tif !ok {\n\t\treturn nil, inputArgError(errors.Errorf(\"can't convert input to map\"))\n\t}\n\n\tinputRef := &assignInput{}\n\tinputRef.What, ok = inputArg[\"what\"].(string)\n\tif !ok {\n\t\treturn nil, inputArgError(errors.Errorf(\"can't convert input.what to string\"))\n\t}\n\n\tnum, err := parseAsUint64(inputArg[\"num\"])\n\tif err != nil {\n\t\treturn nil, inputArgError(schema.GQLWrapf(err, \"can't convert input.num to uint64\"))\n\t}\n\tinputRef.Num = num\n\n\treturn inputRef, nil\n}\n","sourceCodeStart":62,"sourceCodeEnd":97,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/admin/assign.go#L62-L97","documentation":"getAssignInput extracts the 'input' argument of the assignDgraphMutation (assign UID) mutation and asserts it is a map. If the GraphQL-provided argument value is not a map[string]interface{}, the mutation fails with this wrapped inputArgError.","triggerScenarios":"Calling assignDgraphMutation with an 'input' argument that is not an object (e.g. a JSON array, string, or null) via the /mutation HTTP endpoint or a raw GraphQL mutation.","commonSituations":"Crafting the mutation payload by hand and passing input as a list or scalar; sending the raw JSON body directly to /mutation instead of using typed GraphQL variables; tooling serializing input incorrectly.","solutions":["Send input as a JSON object: {\"what\": \"uids\", \"num\": 100} — not an array or string.","If using GraphQL variables, pass them as an object, not a JSON-encoded string.","Check the resolver wrapping in inputArgError in the response to confirm which field was malformed."],"exampleFix":"// before\n{\"query\":\"mutation { assignDgraphUids(input: \\\"bad\\\") { ... } }\"}\n// after\n{\"query\":\"mutation { assignDgraphUids(input: { what: uids, num: 100 }) { value } }\"}","handlingStrategy":"validation","validationCode":"function validateAssignInput(input) {\n  if (typeof input !== 'object' || input === null || Array.isArray(input))\n    throw new Error(\"assignDgraphUids input must be an object like { what: 'uids', num: 100 }\");\n}","typeGuard":"function isAssignInput(v) { return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof v.what === 'string'; }","tryCatchPattern":"try { await assign(input); } catch (e) { if (String(e).includes(\"can't convert input to map\")) { throw new Error('Malformed assign payload: input must be an object'); } throw e; }","preventionTips":["Build mutation inputs as JSON objects, never JSON-encoded strings","Use GraphQL typed variables instead of string interpolation","Validate payloads with a schema validator before sending"],"tags":["graphql","mutation","input-validation","assign"],"backgroundTag":"invalid-mutation-input","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}