-
Notifications
You must be signed in to change notification settings - Fork 28
How to make updateQuery type safe? #65
Comments
I could successfully use js_deep_ppx in this project I'm working on let concatResults: (TransactionsQuery.t, { . "fetchMoreResult": TransactionsQuery.t }) => TransactionsQuery.t = (prev, next) => {
let getEdges = obj => obj##currentUser->Belt.Option.flatMap(user => user##transactions##edges)->Belt.Option.getWithDefault([||]);
let fetchMoreResultEdges = getEdges(next##fetchMoreResult);
let previousEdges = getEdges(prev);
let newEdges = Belt.Array.concat(previousEdges, fetchMoreResultEdges);
[%js.deep prev["currentUser"].map(
user => user->Belt.Option.map(user => user["transactions"]["edges"].replace(Some(newEdges)))
)]
}; |
I am not sure If we want them to be of type The problem with different types in the apollo cache and what we get after parsing the response via |
Fair point, wasn't recalling that the cache data can be slightly different from the result we consume – even more if our users are making use of Probably we would need a way to use |
I would love to have that 😓 , it's just way too error-prone with raw JS |
There is this PR in I was also thinking about the overhead of serializing/parsing data to and fro. Like in case of On the other hand, if you only use |
Probably it would, just not sure if would be too much of it. We can totally benchmark and run some tests when that PR lands in graphql_ppx_re, will solve all of our problems 🙏 . Another way could be to have a "pure JS" |
We use both
I think this is the easiest way to get there. It's at least way more more ergonomic and less error-prone than manually translating to a js object. I.e. we can get graphql_ppx_re to expose types that precisely describe the shape of the object expected by apollo. We're still experimenting with patterns to find good ones, but I find that what I end up doing when working directly with the apollo cache is to write out the types anyway, like so:
updateQuery, readQuery, writeQuery and optimisticResponse would all make use of this pure JS type, which could then be passed to |
Currently there is no way to not to avoid to use a escape hatch bs.raw to do the logic.
Probably we could recommend the usage of https://github.com/jaredly/js_deep_ppx?
And of course change the types of updateQuery to use
(prev: Query.t, {. "fetchMoreResult": Query.t}) => Query.t
The text was updated successfully, but these errors were encountered: