You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my server api, a lot of the mutations send back a response with an updated version of the of the object that’s been modified. It makes sense to update the cached copy of the object with that rather than request it again.
I’ve had some great help from @markerikson with making that happen based on the code from the Optimistic Updates section in the docs. I have a snippet of code that works which looks like this:
I’ve got a lot of locations in my api where this piece of code needs to be repeated with a different endpoint and endpoint parameters and it makes sense to me to try to encapsulate this in a generic typescript function to do that. Trouble is, the typescript is a bit beyond me to get right.
What I’d like to do is specify the endpoint name and a little function that takes the object from the response and returns the endpoint parameter, say, like this:
I’m having trouble getting the types on this right, here’s what I’ve got so far but even trying to use QueryArg here generates an error because it’s not exported (and that makes me think I’m going about this the wrong way):
Ideally it’d be great if the the endpoint name was checked if it was valid and that the type of the endpoint parameter matched as well (I’ve just used any). I’m hoping someone with some serious typescript juju can help me a bit? Thanks.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In my server api, a lot of the mutations send back a response with an updated version of the of the object that’s been modified. It makes sense to update the cached copy of the object with that rather than request it again.
I’ve had some great help from @markerikson with making that happen based on the code from the Optimistic Updates section in the docs. I have a snippet of code that works which looks like this:
I’ve got a lot of locations in my api where this piece of code needs to be repeated with a different endpoint and endpoint parameters and it makes sense to me to try to encapsulate this in a generic typescript function to do that. Trouble is, the typescript is a bit beyond me to get right.
What I’d like to do is specify the endpoint name and a little function that takes the object from the response and returns the endpoint parameter, say, like this:
I’m having trouble getting the types on this right, here’s what I’ve got so far but even trying to use
QueryArg
here generates an error because it’s not exported (and that makes me think I’m going about this the wrong way):Ideally it’d be great if the the endpoint name was checked if it was valid and that the type of the endpoint parameter matched as well (I’ve just used
any
). I’m hoping someone with some serious typescript juju can help me a bit? Thanks.Beta Was this translation helpful? Give feedback.
All reactions