I have what might be a stupid question... Is there...
# prisma-whats-new
m
I have what might be a stupid question... Is there a mutation that increments an integer field, instead of setting it directly?
a
@morley AFAIK you can only do this in the TRANSFORM_ARGUMENT hook. See https://github.com/graphcool/feature-requests/issues/122 for a possibly related feature request.
m
Hmm. I'm not sure TRANSFORM_ARGUMENT works for me. I want to increment the existing value, not manipulate the value that I'm getting in from the server.
The use case for me is a like count; I want to always increment that value
So if I could make a function that has access to the existing value, and returned a new value, that would work for me
a
What would trigger that function?
m
I guess another way to handle this is to make a new data type, Vote, and just increment entries into the votes... but I'm trying not to have a table with hundreds of thousands of entries
I'll do that for now and worry about the scaling later I guess
Thanks!
m
With the client-side option? Yeah, that summarizes it
a
You could cheat by raising an error in the pre_write event hook for the Vote table. That way, you can update your likes based on the payload of the Vote type, but prevent the creation of the actual record.
m
Making a new table seems better for my use case
How do I get a count of relations instead of fetching each vote?
a
_votesMeta { count }
m
cool thanks!
a
But with my approach, you wouldn't have an entry in a new table for every single like...
m
Hmm... I see what you're saying but I think it's better to worry about scaling later
Shouldn't be hard to move to the hack if we run into trouble
a
True
'Premature optimization is the root of all evil' 😄
m
Yup!
a
Updated my count answer, made a typo... it's _votesMeta, not _votesMetadata
m
👍
n
Really interesting discussion, I like @agartha's suggestion a lot. Would love to hear back from you @morley if you run into any problems with this approach 🙂
🙂 1