{"record":{"id":"6a00a0548b865b29","repo":"dgraph-io/dgraph","slug":"encountered-an-xid-s-with-s-that-isn-tallowed-as","errorCode":null,"errorMessage":"encountered an XID %s with %s that isn'tallowed as Xid","messagePattern":"encountered an XID (.+?) with (.+?) that isn'tallowed as Xid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graphql/resolve/mutation_rewriter.go","lineNumber":2484,"sourceCode":"\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)\n\t}\n\treturn nil, \"\"\n}\n\n// This function returns true if there are multiple nodes present","sourceCodeStart":2466,"sourceCodeEnd":2502,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/graphql/resolve/mutation_rewriter.go#L2466-L2502","documentation":"This error comes from Dgraph's GraphQL XID (external ID) handling when rewriting a mutation to DQL. The code switches on the GraphQL type of the field carrying the @id directive and only supports String-typed XIDs; any other type (e.g. Int, ID) hits the default branch and fails. It indicates the schema uses an @id field whose type is not a String, which Dgraph cannot use as an external identifier.","triggerScenarios":"Defining a GraphQL schema where a field annotated with @id has a non-String type (Int, ID, custom scalar) and then running an add/update mutation on that type, causing the mutation rewriter to look up the XID value and fail the type switch.","commonSituations":"Developers porting schemas from other databases where external keys are integers; auto-generated schemas where an ID field is typed as GraphQL ID instead of String; schema changes after the fact that retyped an @id field.","solutions":["Change the @id field's type in the GraphQL schema to String and re-update the schema","Remove the @id directive if external uniqueness is not needed","Migrate existing data so the identifier values are strings, then redeploy the schema"],"exampleFix":"// before\ntype User {\n  userId: Int! @id\n  name: String\n}\n// after\ntype User {\n  userId: String! @id\n  name: String\n}","handlingStrategy":"validation","validationCode":"func validateXidType(t *graphql.Definition) error {\n  if t.Kind != graphql.String.Kind {\n    return fmt.Errorf(\"@id field %s must be String, got %s\", t.Name, t.Kind)\n  }\n  return nil\n}","typeGuard":"func isStringXid(v interface{}) (string, bool) {\n  s, ok := v.(string)\n  return s, ok\n}","tryCatchPattern":null,"preventionTips":["Always declare @id fields as String! in GraphQL schemas","Lint the schema for non-String @id fields before deploy","Test add/update mutations against a staging schema after type changes"],"tags":["graphql","schema","xid","dgraph"],"backgroundTag":"invalid-id-field-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}