- Newest
- Most votes
- Most comments
The issue you're experiencing with large integer values being rounded in AppSync subscriptions is likely related to the handling of JSON numbers in JavaScript. JavaScript has limitations when it comes to representing large integers, as it uses 64-bit floating-point numbers (IEEE 754) for all numeric values. This can lead to precision loss for integers larger than 2^53 - 1.
In your case, the value 263505143177162752 exceeds this limit, which is why it's being rounded when parsed as a regular JavaScript number.
To address this issue, you have a few options:
-
Use string representation: Instead of sending the large integer as a number, you can send it as a string. This will preserve the exact value without any rounding.
-
Use BigInt in JavaScript: If your client-side environment supports BigInt, you can use it to handle large integers without precision loss. However, be aware that BigInt is not supported in all JavaScript environments.
-
Custom parsing: Implement custom parsing logic on the client-side to handle large integers correctly. This could involve checking if a number exceeds a certain threshold and treating it specially.
-
Use a data type that preserves precision: If possible, consider using a data type in your schema that can handle large integers without loss of precision, such as a string or a custom scalar type.
It's important to note that the issue is not with AppSync itself, as the correct value is present in the raw event string. The problem occurs during the JSON parsing/deserialization process, likely on the client side.
To ensure data integrity, you may need to adjust your client-side code to handle these large integer values appropriately, possibly by using one of the methods mentioned above.
Sources
AWS AppSync Events concepts - AWS AppSync Events
Type system (request mapping) - AWS AppSync
Thanks . Yes, I made it as string value and it is working fine. Do we have any documentations or articles to talk about these kind of limitations in general ?
answered a year ago
Relevant content
asked 2 years ago
