The GraphQL server likely violated the globally unique ID requirement by returning the same ID for different objects.
If you're seeing an error like:
RelayResponseNormalizer: Invalid record '543'. Expected __typename to be consistent, but the record was assigned conflicting types Foo and Bar. The GraphQL server likely violated the globally unique ID requirement by returning the same ID for different objects.
the server implementation of one of the types is not spec compliant. We require the
id field to be globally unique. This is a problem because Relay stores objects in a normalized key-value store and one of the object just overwrote the other. This means your app is broken in some subtle or less subtle way.
The most common reason for this error is that 2 objects backed by an ID are using the plain ID as the id field, such as a
Less common reasons could be using array indices or auto-increment IDs from some database that might not be unique to this type.
The best way to fix this is to make your type spec compliant. For the case of 2 different types backed by the same ID, a common solution is to prefix the ID of the less widely used type with a unique string and then base64 encode the result. This can be accomplished fairly easily by implementing a
NodeTokenResolver using the helper trait
NodeTokenResolverWithPrefix. When the
NodeTokenResolver is registered is allows you to load your type using
node(id: $yourID) GraphQL call and your type can return an encoded ID.
Is this page useful?