{"record":{"id":"54e91736f2230989","repo":"dgraph-io/dgraph","slug":"encountered-an-xid-s-with-s-that-isn-t-a-string","errorCode":null,"errorMessage":"encountered an XID %s with %s that isn't a String","messagePattern":"encountered an XID (.+?) with (.+?) that isn't a String","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation_rewriter.go","lineNumber":2479,"sourceCode":"\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)\n\t\t}\n\t\t// \"ID\" is given as input for the @extended type mutation.\n\tcase \"String\", \"ID\":\n\t\txidString, ok := xidVal.(string)\n\t\tif !ok {\n\t\t\treturn \"\", fmt.Errorf(\"encountered an XID %s with %s that isn't \"+\n\t\t\t\t\"a String\", xidName, typeName)\n\t\t}\n\t\treturn xidString, nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"encountered an XID %s with %s that isn't\"+\n\t\t\t\"allowed as Xid\", xidName, typeName)\n\t}\n}\n\n// This function will return interface type and variable for existence query on interface,\n// if given xid is inherited from interface, otherwise it will return nil and empty string\nfunc interfaceVariable(typ schema.Type, varGen *VariableGenerator, xidName string,\n\txidString string) (schema.Type, string) {\n\n\tinterfaceType, isInherited := typ.FieldOriginatedFrom(xidName)\n\tfieldDef := typ.Field(xidName)\n\tif isInherited && fieldDef.HasInterfaceArg() {\n\t\treturn interfaceType, varGen.Next(typ, \"Int.\"+xidName, xidString, false)","sourceCodeStart":2461,"sourceCodeEnd":2497,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation_rewriter.go#L2461-L2497","documentation":"While extracting an @id (XID) value whose schema type is String or ID, Dgraph received a value that is not a JSON string. String/ID XIDs only accept string values, so the conversion via type assertion fails and the error names the XID field and type.","triggerScenarios":"An add/update mutation supplying a number, boolean, or other non-string JSON value for an @id field declared as String (or the ID scalar used for @extended type mutations).","commonSituations":"Clients passing unquoted numeric usernames/codes (12345 instead of \"12345\"), booleans from checkboxes mapped to string XIDs, or API gateways re-serializing strings as numbers.","solutions":["Send the value as a JSON string (wrap it in quotes) in the mutation or its variables.","Coerce client-side with String(value) before building the request.","If numeric values are expected, change the @id field's schema type to Int or Int64.","Fix client serialization so string-typed GraphQL variables are never emitted as numbers."],"exampleFix":"// before (variables)\n{ \"username\": 12345 }\n// after\n{ \"username\": \"12345\" }","handlingStrategy":"type-guard","validationCode":"function assertStringXid(v, field) {\n  if (typeof v !== 'string') throw new Error(`${field} must be a string for @id(String)`);\n  return v;\n}","typeGuard":"function isStringXid(v) {\n  return typeof v === 'string';\n}","tryCatchPattern":"try {\n  await client.mutate({ mutation: ADD, variables: { input } });\n} catch (e) {\n  if (/isn't a String/.test(e.message)) {\n    // coerce the value with String(v) and retry once\n  } else throw e;\n}","preventionTips":["Quote string XID values in JSON payloads and variables.","Coerce values with String(v) before building mutation variables.","Keep GraphQL variable declarations typed (String!) so the client coerces or fails early.","Audit checkbox/boolean inputs that map to string @id fields."],"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"}