hi guys, for those of you who are working with mob...
# orm-help
r
hi guys, for those of you who are working with mobile apps in combination with Prisma, can I ask how you would model notifications? I have different types of notifications, such as likes, comments, follower, tag, ... but I m not sure what the best approach is to model those as data structure. Since there is still no interface type in Prisma, Im checking other options but id be curious to hear if anyone else here already has encountered/solved this problem. Cheers!
j
Graphql has interfaces, so prisma does
r
thats not how it works sadly
prisma is a proxy between your db and a graphql schema, it is not pure graphql, which means they’d need to implement interfaces before we could use them.
m
Hi, I've have been asking myself the same question. So far, I created a
Notification
type and used a enum
NotificationType
so signify the kind of event causing the notification. Works well but is a little tedious to maintain.
r
@Moritz thats exactly what I was doing atm
haha
but I have the same thoughts about the difficulty to maintain something like that
@Moritz can I ask where you create your notifications? For example, I need to create a Notification when someone likes a post but to do that in the createLike resolver would make that resolver slower
I wish there was a way to do that when the resolver has already returned
m
Haha we have been asking ourselves the same questions 🙂
So far, I have been creating the notification in the likePost resolver asnycronously, i.e. call
ctx.db.createNotification(...)
without await, which should be unblocking. However, there is no way to inform the client about failed notification creation...
r
yeah, plus, I want to check first to see if a notification already exists
m
I think a very intersting new approach ist possible with https://github.com/prismagraphql/graphql-middleware
r
haha, I just tried that 😛
but it seems to trigger multiple times for me
which is not very reliable
m
The lib is still pretty young 🙂
r
when I log operationName/variables I see it pass by 3*4 times
so I wouldnt want 4 notifications to be created
m
Intersting... I havent played around with it much... Sounds like this might be worth an issue report.
If you check if the notification exists this should be a problem for now, should it? Its just ugly performance wise...
r
yup
m
But yea please ping me if you find a neat solution, Id be eager to refactor mine 🙂
r
ill do so more experimenting
m
Good luck 🍾
w
If you need quick and immediate response, then what you need is optimistic update, but calling
createNotification()
shouldn’t be a problem, it’s just an insert 😕