-
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
ObserveQuery / OnUpdate not respecting selection set nested models - returns function instead #13267
Comments
Hi @m9rc1n it looks like you are using So, the function in place of the new record's |
Hi @chrisbonifacio, Thanks for looking into this issue. I see your point. On the other hand, this design decision might cause confusion among end users (i.e. how to use nested fields in subscriptions?) and lead to some race conditions. For instance, if I do:
Then the content will be still Also I was able to recreate this issue using reverse subscription - listening to updates on |
Hi @m9rc1n we're going to classify this as a bug at the moment, as this probably needs some discussion. Returning the relationship before it exists won't be possible via the subscription so we will look into improving this experience, at least avoiding confusion around related data in messages from onCreate subscriptions. |
Hi @chrisbonifacio, sure thing. |
It is worth noting that typescript errors pop up if an onCreate or onUpdate subscription uses a selection set and we try to lazy load the relations because they're not typed as functions. |
Hi @m9rc1n, it looks like you're using the beta versions of backend (and the version of Edited: I originally thought I demo'd working behavior on my end; but missed part of the issue/repro steps. 😓 |
Sorry for the jumping the gun on a response above. My brain definitely dropped some context between when I popped this issue open and when I returned to really look at it. 😓 So, I want to clarify one thing in particular: Updating to the latest versions should 100% be done, but will not fix this. Some of the complexity here is that graphql subscriptions can only receive fields present on the corresponding mutations. In addition to the chicken-egg problem @chrisbonifacio noted, which would probably be best addressed by simply "touching" relevant models to broadcast a "refresh", the more complicated side of this is aligning selection sets between mutations and subscriptions. And that's really the stickier point without a clear solution here. If you subscribe to fields |
i found an alternative that works well for my issue, maybe will work for you try something like this:
|
Hi Rat-fi, what type are you using for currentCard? |
|
Hey folks, a few fixes and docs sites updates have been submitted now that I believe address the problems identified in this thread. Here's a summary: ✅ Fixed: Custom selection sets on mutationsThe ✅ Fixed: Custom selection sets containing related models on subscriptionsThe types were correct for custom selection sets on subscriptions (including ✅ Docs Updated: Subscription selection set limitations and patternsEven with the aforementioned fixes, some of the code samples on this issue will not work as desired. Most notably, a subscription can only select fields provided to it via the corresponding mutation's selection set, and specifically for mutations that directly touch that specific model. In other words, if you want to subscribe to Documentation has been updated to explain this with examples. Those updates can be found under the "Set up real-time list query" heading in the "Missing real-time events and model fields" Troubleshooting accordion/dropdown. Next Steps: Update your apps
Hope that helps! |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API, DataStore
Amplify Version
v6
Amplify Categories
api
Backend
Amplify Gen 2 (Preview)
Environment information
Describe the bug
Nested model is replaced with function after it is delivered by
observeQuery
oronUpdate
.Selection Set setting is not respected by
observeQuery
oronUpdate
.Expected behavior
Selection Set setting will work the same for observeQuery as it does for other functions i.e. get, or list.
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: