I am trying to get subsccriptions working. I have ...
# orm-help
p
I am trying to get subsccriptions working. I have a prisma, node, graphql-yoga back end that is running and working. I can go to the playground and subscribe to my subscription and it works great. However, when i try to subscribe on my front end (angular, apollo-angular, apollo-client) it does not work. The subscription never fires and nothing happens. I am also not finding any examples or documentation on how to set up an angular front end to work with the subscriptions. Is there any configuration i need to do with the http links with apollo? If someone could just point me to a good guide, i would love to take a look at it. thanks
⁉️ 1
h
Did you followed the bolierplate code at Apollo docs
Subscription don't work with Apollo boost I guess you need to migrate and use your custom Apollo link , see the docs
p
i need links to the docs you are referring to. There is a good chance that i already looked at them. But i don’t know which ones you are referring to until i have links. I have been looking at this issue for 2 days now and have tried a lot of guides and docs. Can you please give me the 2 links you are referring to. Thank you
h
Okay
Are you using Apollo boost RN?
p
no
i dont even know what that is
h
Ok
p
That guide is for React
i am using angular
h
The Apollo client setup is same for both
Just the bindings are different you can easily for this guide
p
ok
if i have to do that link stuff for subscriptions, do i have to do anything special on my backend for it to work?
h
Just don't do subscription component part, do that the angular way
p
because i was under the impression that everything was setup with prisma for subscriptions without me having to do anythnig special
h
No, if you are using Prisma just expose them in graphql-yoga of yours
p
expose them?
i may not have done that eitehr
h
Like you are doing for queries
p
either*
through the schema?
h
Yes
And a resolver
p
ok, yeah i have done that
i can get the sub to work in the playground
it works fine there
h
Ok that will work then 😄
p
just cant get my frontend to use them
ok, i will try this. I will be in touch. I will let you know if it works or doesn’t
ty for your help so far
WebSocket connection to ‘ws://localhost:5000/’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
This is what i get when trying to launch my front end with the code from the guide
Test
` // Create an apollo-upload-client link so we can upload files with graphql const httpLink = createUploadLink({uri: “http://localhost:8080“}); const wsLink = new WebSocketLink({ uri:
<ws://localhost:5000/>
, options: { reconnect: true } }); // Create a middleware link with apollo-link so we can attach headers to requests. // Automatically injects a JWT onto every http call made with the angular http. const middlewareLink: ApolloLink = new ApolloLink((operation, forward) => { operation.setContext({ headers: { Authorization: “Bearer ” + localStorage.getItem(GqlAuthService.TOKEN_ID) } }); return forward(operation); }); return { // link: middlewareLink.concat(httpLink), link: split( // split based on operation type ({ query }) => { const { kind, operation } = getMainDefinition(query); return kind === ‘OperationDefinition’ && operation === ‘subscription’; }, middlewareLink.concat(wsLink), middlewareLink.concat(httpLink), ), cache: new InMemoryCache() };`
h
Ok are you surely able to use that in localhost:5000
p
i dont see why not
just my local machine
the code i pasted is what i have
for creating the links
sorry, i posted twice
h
You link is fine
Your server has a prob now
Have you done something similar for subscription?
p
no
i dont have that pubsub stuff
i was under the impression that prisma did that stuff already
without me having to do that
h
Yes it do
p
so, i dont have to do the pubsub stuff?
Somewhat follow this
Are you using Prisma bindings or Prisma client lib
p
prisma bindings on the backend, yes
i did follow that guide
i have the backend working in the playground
i just can’t get my front end to conect to the subscriptions
h
Yes so you can follow and no need of pubsub
p
when i launch the front end it gives me that error
WebSocket connection to '<ws://localhost:5000/>' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
h
Do the stuff in backend first
p
What stuff?
I provided the link to the tutorial
p
Yeah, i already have all that
my backend is working
everything works fine in the playground
h
A subscription type on schema as well?
p
yeah
h
Are you sure that is the correct endpoint?
p
no
i just did what was in the guide you linked earlier
h
p
do i need to change
<ws://localhost:5000/>
to the address that i am using for my http link?
or do they need to be different
my httplink is localhost:8080 and wslink is localhost:5000
h
Ohhh
Change it to 8080
p
ok…
that seems to be working
i need to do some testing
but i think it might be working now
i will keep you updated
ty again!
h
👍 you just need to write a component in angular now
I use react most the time not that familiar with angular but I know the gist of it
p
yes, this appears to be working now. ty
🙌 1