Good evening (in Sweden at-least). Anyone here pl...
# prisma-whats-new
k
Good evening (in Sweden at-least). Anyone here playing with graph.cool and react-native (or native ios/android). I'm playing with subscriptions and that is all fine and dandy as long as the app is in the foreground. Now I'm sitting here thinking about how to solve it while the app is in the background. Push-notifications would be a really good candidate, but it kind of feels like writing the same logic twice. I’m guessing someone else has thought about this (and maybe solved it in some nice way)
n
@kimf coming from the native Android world, you would solve this with a Service. a Service is a background task that is longliving, in constrast to an App (Activity), which is mostly only active in the foreground
I'm sure there is a similar concept on iOS
you would do the subscriptions in that service instead of in the activity
k
Yep, there is, unfortunately iOS does not allow long living connections unless you have an audio, video or similar app. And react-native, unfortunately does not have background-tasks (in js) for iOS, yet.
n
So to my understanding push notifications fulfill a different purpose than subscriptions. but depending on your use case they could still be suitable. What is your use case?
k
I have a leaderboard (golf-app that’s not in the foreground that often) that I want to keep up to date. I guess the limitation is really on react-native’s side right now
n
so what you can do is use a push notification that tells the user when a new result is there
it's like a poke that makes him open the app
and when he opens it, you query the latest updated/created scores
a
@kimf Do you mean you want to be able to still receive information from subscriptions while the app is in the background or when you background an app and then foreground it the subscriptions have not updated? (I’m also using graphcool with react native)
k
@aurnik Preferrably I would like the app to still receive the information while it’s in the background, so when it comes in to the foreground I can show the live data straight away (And even send local push notifications about the updates)
n
for this you would need the background service. Push notifications are not really meant to transfer real time data, it's more like a notification thing
k
@nilan Yeah, right now I query the latest when the app comes back in to foreground, and it works. I’m just trying to do it a little bit more “effeciently” as usually on a golf course you don’t have the best cell-service coverage. Yeah, Think I will try to do a background service. There is always something new to learn 😄
n
I mean querying only the latest from the last time you queried is already pretty efficient
a
Yeah for react native IOS there arent background tasks yet but you could get away with checking your subscriptions
on an interval*
n
you cannot check subscriptions on an interval - you are notified whenever the subscribed event happens
k
Yep, it works really great querying the latest, and refreshing the original query when the app comes back in to foreground.. It’s a “just-for-fun-app”, and I’m doing it to learn new things. So was sitting here thinking about how to do it “right” on native..
n
I see. Definitely sounds like a great exercise. Let me know your findings! 🙂
Btw, exponents seems to have a nice way to do push notifications: https://docs.getexponent.com/versions/v14.0.0/guides/push-notifications.html
k
Nice. Now I only need to figure out how to make a subscription-based callback that sends the push-notification from graphcool 😏
a
Yeah I was addressing that on IOS you can’t do background tasks yet but you can set an interval to still run code in the background
n
Ahh I see @aurnik
@kimf you will need to setup some kind of microservice. you can create a new
PushNotification
model and set a mutation callback that calls your microservice whenever a new
PushNotication
has been created
you also need to associate a user with his Exponent token (in case of using exponent)
hope that helps
k
Yep, or maybe have a mutation-callback on the model that is saved and do the logic in the micro-service of what push to send or not.
n
ah yea. you just need the token of the user that should receive the notification somehow
k
Yep, will play around with it. I need to add push-notifications anyway. Thanks, as always, for taking your time
🙌 1
s
Hope you had a great #lastnightinsweden
😜 2
🌃 1