Closed ffxsam closed 6 years ago
Hi @ffxsam , where are you using the sdk? Is it Node.js, Web or React Native?
And to confirm, are you using the latest version in npm? (1.0.6 as of today)
I'm using web (front-end), with vue-apollo
. I can submit a reproduction repository if it helps.
That would be great!
@manueliglesias will do in a few minutes here. Thanks for the prompt response! I'm rebuilding a major application using AppSync and am really excited to jump in!
@manueliglesias Here you go: https://github.com/ffxsam/try-appsync
I changed the API key and made the repo private (but invited you).. didn't want that out there for the world. ;)
Hi @manueliglesias, just wanted to check in to see how this is going. Do you need anything else from me? Is there some way I can help?
Well, that's strange! My API endpoint suddenly doesn't resolve. "Could not resolve host". I guess I'll need to delete my whole API and recreate it to get a new URL. I'll post again if this issue still persists.
EDIT: Tried a new API, the same error still occurs.
@manueliglesias I found the problem!
vue-apollo
is not waiting for client.hydrated()
to resolve. But using vue-apollo
with another provider than AppSync works just fine. Any suggestions on how to fix this? This is obviously specific to vue-apollo
. Probably the best thing would be for me to open a PR for that project that adds AppSync support, and checks for a client.hydrated
function.. and if it exists, call it and wait for it to resolve before proceeding with any queries.
Solution (in Vue's main.js
or main.ts
):
client.hydrated().then(() => {
new Vue({
el: '#app',
apolloProvider,
i18n,
router,
store,
components: { App },
template: '<App/>',
});
});
Turns out it was really simple once I figured out the issue! This delays the Vue app from setting up until the data has been hydrated.
BTW, could I contribute a Vue guide similar to this one? https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-reactnative.html
I take it back, the above solution is no good. It causes problems with Vue DevTools because it expects the DOM to be there and it's not right away.
So I went with this solution:
In App.vue
, in the script block:
data() {
return {
hydrated: false,
};
},
async mounted() {
await this.$apollo.provider.defaultClient.hydrated();
this.hydrated = true;
},
});
Then simply make sure the root div in App
is <div v-if="hydrated">
so that nothing mounts until hydration is complete.
Awesome, thanks for sharing your solution here @ffxsam !
Regarding contributing a guide, let me check if it is possible and how would that work
Hey @ffxsam can you send me a DM on twitter @menyao ?
We would love to chat with you about that guide :)
@manueliglesias Yep, I just followed you a few second ago. I can DM after you follow me. Thanks!
Thanks @manueliglesias, you saved me from pulling my hair out :)
Hello guys...i'm working with something like this and i have the same problem...did you resolve it???
Thanks
I'm getting this error
I'm not sure what I'm doing wrong, but I did notice
appsync
in the Redux store is an empty object. Seems like the cache is trying to read from something that isn't there.