dgraph-io/dgraph · error

encountered an XID %s with %s that isn'tallowed as Xid

Error message

encountered an XID %s with %s that isn'tallowed as Xid

What it means

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.

Source

Thrown at graphql/resolve/mutation_rewriter.go:2484

		case int64:
			return strconv.FormatInt(xVal, 10), nil
		// If the xid field is of type Int64, both String and Int forms are allowed.
		case string:
			return xVal, nil
		default:
			return "", fmt.Errorf("encountered an XID %s with %s that isn't "+
				"a Int64 but data type in schema is Int64", xidName, typeName)
		}
		// "ID" is given as input for the @extended type mutation.
	case "String", "ID":
		xidString, ok := xidVal.(string)
		if !ok {
			return "", fmt.Errorf("encountered an XID %s with %s that isn't "+
				"a String", xidName, typeName)
		}
		return xidString, nil
	default:
		return "", fmt.Errorf("encountered an XID %s with %s that isn't"+
			"allowed as Xid", xidName, typeName)
	}
}

// This function will return interface type and variable for existence query on interface,
// if given xid is inherited from interface, otherwise it will return nil and empty string
func interfaceVariable(typ schema.Type, varGen *VariableGenerator, xidName string,
	xidString string) (schema.Type, string) {

	interfaceType, isInherited := typ.FieldOriginatedFrom(xidName)
	fieldDef := typ.Field(xidName)
	if isInherited && fieldDef.HasInterfaceArg() {
		return interfaceType, varGen.Next(typ, "Int."+xidName, xidString, false)
	}
	return nil, ""
}

// This function returns true if there are multiple nodes present

View on GitHub (pinned to 759e242be6)

Solutions

  1. Change the @id field's type in the GraphQL schema to String and re-update the schema
  2. Remove the @id directive if external uniqueness is not needed
  3. Migrate existing data so the identifier values are strings, then redeploy the schema

Example fix

// before
type User {
  userId: Int! @id
  name: String
}
// after
type User {
  userId: String! @id
  name: String
}
Defensive patterns

Strategy: validation

Validate before calling

func validateXidType(t *graphql.Definition) error {
  if t.Kind != graphql.String.Kind {
    return fmt.Errorf("@id field %s must be String, got %s", t.Name, t.Kind)
  }
  return nil
}

Type guard

func isStringXid(v interface{}) (string, bool) {
  s, ok := v.(string)
  return s, ok
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/6a00a0548b865b29. Report an issue: GitHub.