I’ve been trying to set up a subscription in my react app and haven’t been able to get it working.
In the app I’m running up against this error:
"Cannot read property ‘routeKey’ of undefined"
When I try the same subscription in the API explorer I’m seeing this:
Basically it fails but just remains in the loading state with nothing happening.
Here is my subscription:
Any ideas what is going on?
The “routeKey” of undefined is what is returned by the api when I try to create the subscription, not an error from my react frontend FYI.
@squadsdev we are looking into it. I will get back to you a bit later.
@squadsdev Two things
- Right now the error message is incorrect. We already have a fix and going to upload it next week.
- Could you provide us an example of your code how are you trying to configure subscription link? We suppose subscriptions are not working for you because you are using http protocol which doesn’t supported. This is an correct example of how to use it https://github.com/8base/sdk/blob/master/packages/apollo-client/src/index.ts
and you should use the following Apollo link https://github.com/8base/sdk/blob/master/packages/apollo-links/src/SubscriptionLink.ts
Please let me know if it helps!
@ilya.8base thanks for the update.
On that first point, does that mean I won’t be able to get subscriptions working until the fix goes in?
Re my setup, I’m currently using the @8base/react-sdk/app-provider to wrap my app and provide auth and an apollo client instance. Inside of that I’m using the Subscription component from react-apollo with the apollo client instance from the app-provider. The code works fine for a standard query with Query component from react-apollo, I ran into issues when I tried switching over to subscription instead.
I’ve just noticed the withSubscriptions prop for the app-provider which I’d missed previously. Looks like that will add the required link for subscriptions to Apollo. Setting that to true has changed the error now so I’m seeing the same problem in my app as what I’m seeing in the API explorer.
I can provide access to my project repo if you need to take a closer look at my setup.
I’m also using version 0.37.2 of a lot of the 8base packages. I’ve noticed you’ve made some more releases and most are version 1+ now. Will those new versions be published to npm soon or should I just point to the repo and get the latest asap?
@squadsdev That fix just for error message which is incorrect. Subscriptions are working. To understand your problem please send me error what you are getting in API Explorer. And yes, please provide access to you repo for user zouxuoz if it is on GitHub.
@ilya.8base I managed to get subscriptions working, turns out my config in the app wasn’t quite right! Sorry for the fail and thanks for the assistance.
One last subscription question, is it possible to subscribe to updates in a list of related field items? For example if my user record had a list of groups they were a member of, would I be able to subscribe to changes in those groups through the user?
Yes, it’s possible. Here’s sample query:
As you can see, there is list of groups which were added to a user in the last update mutation.