1

I have been trying to build something that needs real-time data.

I have created the subscription structure, but all the tut videos from like 2018. documentation is extremely limited. I was wondering did something came up and everybody moved away from subscription? or am I the only one struggling with the PubSub modal.

I have session and userToSession modals that connect session and user with extra information. If the user updates userToSession type subscription listens to change on the session because I try to update that but I can't reach out to userToSession details from the subscription because it is listening to the parent type.

Anyway, if you can direct me to a good tutorial it would be wonderful thank you.

Bora ALAP
  • 269
  • 3
  • 13
  • Apollo got rid of the subscription feature in the apollo-server version 3, so that might be the reason you're not finding a lot of recent content. I think most of the content you will find will be a few years old and will use relational databases (in case it's for Prisma). So you'll have to adjust it appropriately for MongoDB. – Tasin Ishmam Nov 29 '21 at 17:48
  • If they got rid of it, what is the equivalent of it? I'm using "@prisma/client": "^3.6.0", "apollo-server": "^3.1.2", "apollo-server-core": "^3.3.0", "apollo-server-express": "^3.3.0", on backend and front end is "@apollo/client": "^3.4.16", data is not getting updated automatically on the frontend. and I see documentation of https://www.apollographql.com/docs/react/data/subscriptions/ really confused here, thanks for help @TasinIshmam – Bora ALAP Dec 04 '21 at 19:47
  • I think this is the documentation you should be looking at: is the one for [apollo-server](https://www.apollographql.com/docs/apollo-server/data/subscriptions/) which mentions that Apollo deprecated subscriptions. They also provide a workaround with apollo-server-express, so since you're using that, you can use that workaround. In terms of content: I think you could use the pre-2018 content that you just referred to (any popular one should work). – Tasin Ishmam Dec 07 '21 at 18:43
  • I'm not sure which tutorial would be the _best_ though. There's one on [howtographql](https://www.howtographql.com/graphql-js/7-subscriptions/) which demonstrates using subscriptions on the server-side. But it's a multi-chapter tutorial that covers a lot of other things too and it's using a relational database, so I'm not sure if it's best for your purpose. It's also using Apollo Server 2, which used to support subscriptions. (Disclosure: I'm a maintainer for howtographql). – Tasin Ishmam Dec 07 '21 at 18:45
  • @TasinIshmam thanks for all the help. my question is what should I use if a subscription is not a thing anymore. I'm trying to find what is current. If my data is should auto-update, can you point me in the direction of what might be missing? I'm using Expo, React Native, Mongodb, Prisma 2, Apollo-server-express:3.3, apollo-client: 3.4. trying the build this with the latest. Thanks again really appreciate it. – Bora ALAP Dec 12 '21 at 03:01
  • 1
    So when I say subscription isn't a _thing_ anymore, I mostly mean it in the context of Apollo's core feature set. But even then, they provide a [workaround](https://www.apollographql.com/docs/apollo-server/data/subscriptions/#enabling-subscriptions) with Apollo server express, which I would definitely suggest considering if this fits your use case. Mostly what I'm saying is, most tutorials with Apollo + Subscriptions will likely be a bit dated as it's not a core feature any longer. – Tasin Ishmam Dec 12 '21 at 08:00
  • 1
    However, if you would prefer an _alternative_, you could consider using websockets (typically people use socket.io) to directly create a persistent connection with the client and notify it in case of relevant data changes or events. There's also a technology called Server-Sent Events which fits your use-case, but I haven't used it much hands-on so can't comment. – Tasin Ishmam Dec 12 '21 at 08:05

0 Answers0