-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(@aws-amplify/datastore): Support SSR #5450
Conversation
HMR will re-run imports, so sideEffects have to be graceful
This reverts commit 9ce2624.
packages/datastore/src/storage/adapter/getDefaultAdapter/index.ts
Outdated
Show resolved
Hide resolved
This pull request introduces 4 alerts when merging 2ece0d7 into dee0607 - view on LGTM.com new alerts:
|
2ece0d7
to
644a5f1
Compare
5e0fc62
to
24eeeb7
Compare
…datastore # Conflicts: # packages/core/src/Util/Reachability.ts # packages/datastore/package.json # packages/datastore/src/datastore/datastore.ts
24eeeb7
to
b476969
Compare
Argument of type '{ online: boolean; }' is not assignable to parameter of type 'Observable<NetworkStatus> | ObservableLike<NetworkStatus> | ArrayLike<NetworkStatus>'. Object literal may only specify known properties, and 'online' does not exist in type 'Observable<NetworkStatus> | ObservableLike<NetworkStatus> | ArrayLike<NetworkStatus>'.ts(2345)
// In Node, we need to wait for queries to be synced to prevent returning empty arrays. | ||
// In the Browser, we can begin returning data once subscriptions are in place. | ||
const readyType = isNode | ||
? ControlMessage.SYNC_ENGINE_SYNC_QUERIES_READY | ||
: ControlMessage.SYNC_ENGINE_STORAGE_SUBSCRIBED; | ||
|
||
if (type === readyType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change fixes expected behavior in Node (particularly lambdas).
Notice here where I'm listening to Hub.listen('datastore')
and finally logging out { posts }
:
// 👇 Hub.listen('datastore', ...)
datastore {
channel: 'datastore',
payload: { event: 'storageSubscribed', data: undefined },
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: { event: 'networkStatus', data: { active: true } },
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: { event: 'outboxStatus', data: { isEmpty: true } },
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: { event: 'subscriptionsEstablished', data: undefined },
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: { event: 'syncQueriesStarted', data: { models: [Array] } },
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: {
event: 'modelSynced',
data: {
model: [Function],
isFullSync: true,
isDeltaSync: false,
counts: [Object]
}
},
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: {
event: 'modelSynced',
data: {
model: [Function],
isFullSync: true,
isDeltaSync: false,
counts: [Object]
}
},
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: { event: 'syncQueriesReady', data: undefined },
source: '',
patternInfo: []
}
datastore {
channel: 'datastore',
payload: { event: 'ready', data: undefined },
source: '',
patternInfo: []
}
// 👇 { posts }
{
posts: [
Post {
id: 'd4ad30d3-bb95-4cb2-9f55-b5917605e797',
title: 'New Post (4/16/2020, 4:58:42 PM)',
rating: 1,
status: 'ACTIVE',
_version: 2,
_lastChangedAt: 1587081528053,
_deleted: null
},
Post {
id: '7b14789a-40a9-4b3a-8a23-849e3866f77a',
title: 'New Post (4/17/2020, 3:17:13 PM)',
rating: 4,
status: 'INACTIVE',
_version: 1,
_lastChangedAt: 1587161833864,
_deleted: null
},
Post {
id: '2e5a6422-47e8-4693-b141-a126e8aaacfc',
title: 'New Post (4/16/2020, 4:28:16 PM)',
rating: 3,
status: 'ACTIVE',
_version: 2,
_lastChangedAt: 1587081526956,
_deleted: null
},
Post {
id: 'f05918fc-2209-4013-a185-d6f9f8d9c468',
title: 'New Post (4/20/2020, 2:04:21 PM)',
rating: 2,
status: 'INACTIVE',
_version: 1,
_lastChangedAt: 1587416662244,
_deleted: null
},
Post {
id: 'a94a6cc5-8a0b-441a-9da8-5dfc391df18d',
title: 'New Post (4/16/2020, 4:58:43 PM)',
rating: 3,
status: 'INACTIVE',
_version: 1,
_lastChangedAt: 1587081523206,
_deleted: null
}
]
}
{
posts: [
Post {
id: 'd4ad30d3-bb95-4cb2-9f55-b5917605e797',
title: 'New Post (4/16/2020, 4:58:42 PM)',
rating: 1,
status: 'ACTIVE',
_version: 2,
_lastChangedAt: 1587081528053,
_deleted: null
},
Post {
id: '7b14789a-40a9-4b3a-8a23-849e3866f77a',
title: 'New Post (4/17/2020, 3:17:13 PM)',
rating: 4,
status: 'INACTIVE',
_version: 1,
_lastChangedAt: 1587161833864,
_deleted: null
},
Post {
id: '2e5a6422-47e8-4693-b141-a126e8aaacfc',
title: 'New Post (4/16/2020, 4:28:16 PM)',
rating: 3,
status: 'ACTIVE',
_version: 2,
_lastChangedAt: 1587081526956,
_deleted: null
},
Post {
id: 'f05918fc-2209-4013-a185-d6f9f8d9c468',
title: 'New Post (4/20/2020, 2:04:21 PM)',
rating: 2,
status: 'INACTIVE',
_version: 1,
_lastChangedAt: 1587416662244,
_deleted: null
},
Post {
id: 'a94a6cc5-8a0b-441a-9da8-5dfc391df18d',
title: 'New Post (4/16/2020, 4:58:43 PM)',
rating: 3,
status: 'INACTIVE',
_version: 1,
_lastChangedAt: 1587081523206,
_deleted: null
}
]
}
Fixed via #6146 |
This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
What
Add Next.js support (#5435) for
DataStore
:Why
https://www.pivotaltracker.com/n/projects/2174488
How
Add
DataStore
forimport { DataStore, Predicates } from "aws-amplify"
fix(aws-amplify): add DataStore export #5421Support
WebSocket
s on the server.Add
DataStore.toJSON()
to automatically serialize models on the server.I would've preferred
model.toJSON()
so thatJSON.stringify(posts)
worked implicitly & automatically, but that only serializes properties ofPost
, rather than the object itself. The result is:[Post {}, Post {}, Post {}]
To solve for this, we would have to provide an
Array
-like wrapper with.toJSON()
to castPost
as a plainObject
.Alternatives for users would be to
JSON.parse(JSON.stringify(posts))
, but it's likely that we'll need to support serialization/deserialization based on theschema
.Add
Model.fromJSON()
to cast JSON as a new model instance (includingid
)Generate types for
Model.fromJSON()
:Securely transport
id
?Wait for
syncQueriesReady
before returning results on the server.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.