Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@aws-amplify/datastore): only stringify nested AWSJSON in mutation event #8844

Merged
merged 3 commits into from
Sep 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/datastore/src/sync/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,18 @@ export function createMutationInstanceFromModelOperation<
exhaustiveCheck(opType);
}

// stringify nested objects
// stringify nested objects of type AWSJSON
// this allows us to return parsed JSON to users (see `castInstanceType()` in datastore.ts),
// but still send the object correctly over-the-wire
// but still send the object correctly over the wire
const replacer = (k, v) => {
if (k && v !== null && typeof v === 'object' && !Array.isArray(v)) {
const isAWSJSON =
k &&
v !== null &&
typeof v === 'object' &&
modelDefinition.fields[k] &&
modelDefinition.fields[k].type === 'AWSJSON';

if (isAWSJSON) {
return JSON.stringify(v);
}
return v;
Expand Down