{"record":{"id":"02768fc344a71c15","repo":"dgraph-io/dgraph","slug":"encountered-an-xid-s-with-s-that-isn-t-a-int-but","errorCode":null,"errorMessage":"encountered an XID %s with %s that isn't a Int but data type in schema is Int","messagePattern":"encountered an XID (.+?) with (.+?) that isn't a Int but data type in schema is Int","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation_rewriter.go","lineNumber":2455,"sourceCode":"\tfor name, typ := range from {\n\t\tto[name] = typ\n\t}\n}\n\nfunc extractVal(xidVal interface{}, xidName, typeName string) (string, error) {\n\tswitch typeName {\n\tcase \"Int\":\n\t\tswitch xVal := xidVal.(type) {\n\t\tcase json.Number:\n\t\t\tval, err := xVal.Int64()\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\treturn strconv.FormatInt(val, 10), nil\n\t\tcase int64:\n\t\t\treturn strconv.FormatInt(xVal, 10), nil\n\t\tdefault:\n\t\t\treturn \"\", fmt.Errorf(\"encountered an XID %s with %s that isn't \"+\n\t\t\t\t\"a Int but data type in schema is Int\", xidName, typeName)\n\t\t}\n\tcase \"Int64\":\n\t\tswitch xVal := xidVal.(type) {\n\t\tcase json.Number:\n\t\t\tval, err := xVal.Int64()\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\treturn strconv.FormatInt(val, 10), nil\n\t\tcase int64:\n\t\t\treturn strconv.FormatInt(xVal, 10), nil\n\t\t// If the xid field is of type Int64, both String and Int forms are allowed.\n\t\tcase string:\n\t\t\treturn xVal, nil\n\t\tdefault:\n\t\t\treturn \"\", fmt.Errorf(\"encountered an XID %s with %s that isn't \"+\n\t\t\t\t\"a Int64 but data type in schema is Int64\", xidName, typeName)","sourceCodeStart":2437,"sourceCodeEnd":2473,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation_rewriter.go#L2437-L2473","documentation":"While extracting an @id (XID) value declared as Int in the schema, Dgraph received a value of an unexpected runtime type (not json.Number nor int64). The schema says the XID is Int, but the supplied value cannot be converted, so it fails naming the XID field and schema type.","triggerScenarios":"An add/update mutation supplying a value for an @id field of schema type Int where the variable carries a string, float, or other non-numeric JSON type that the type switch in extractVal's \"Int\" case cannot handle.","commonSituations":"GraphQL variables passed as strings (\"123\" instead of 123), floats with decimal parts (123.0) not representable as Int, or clients serializing IDs as strings to avoid precision loss.","solutions":["Send the value as a JSON number without a fractional part (e.g. 123, not \"123\" or 123.0).","Declare the @id field as String (or Int64, which accepts both) in the schema if IDs may arrive as strings.","Coerce client-side: parse the string to an integer before passing it as a GraphQL variable.","Check the mutation variables section — string-typed variables are the most common culprit."],"exampleFix":"// before (variables)\n{ \"xid\": \"12345\" }\n// after\n{ \"xid\": 12345 }","handlingStrategy":"type-guard","validationCode":"function assertIntXid(v, field) {\n  const n = typeof v === 'string' ? Number(v) : v;\n  if (!Number.isInteger(n)) throw new Error(`${field} must be an integer for @id(Int)`);\n  return n;\n}","typeGuard":"function isIntLike(v) {\n  return (typeof v === 'number' && Number.isInteger(v)) ||\n         (typeof v === 'string' && /^-?\\d+$/.test(v));\n}","tryCatchPattern":"try {\n  await client.mutate({ mutation: ADD, variables: { input } });\n} catch (e) {\n  if (/isn't a Int but data type in schema is Int/.test(e.message)) {\n    // coerce the variable to a JSON integer and retry once\n  } else throw e;\n}","preventionTips":["Pass Int XIDs as JSON numbers, never quoted strings, in variables.","Avoid sending floats for Int fields (no 123.0).","Declare @id as String/Int64 if values may arrive as strings.","Add JSON-schema validation on request bodies in API gateways."],"tags":["graphql","type-mismatch","id-directive"],"backgroundTag":"xid-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}