-
Notifications
You must be signed in to change notification settings - Fork 108
Hooks & a Custom Reason Apollo PPX #192
Comments
YES 🔥 Great idea @nikgraf! |
One thing I'm not sure of: could the PPX create different hooks based on the provided input e.g. for a mutation a |
Can you elaborate? I don't quite understand |
@peterpme a mutation can have a |
Not sure whether this matters for usage or not, but you may end up having to use |
@anmonteiro definitely matters from my perspective! Can you elaborate on why we need to access |
It would be good to compare this to https://github.com/Astrocoders/reason-apollo-hooks/blob/master/README.md#usequery, and especially the "full" usage which we've found necessary in order to capture all the states via destructuring. The gql ppx is nice, but I think it should probably be The hook-based approach looks great though! And using an additional ppx to generate the other (confusing) boilerplate is a great idea as well. Generating specific functions/modules based on whether the operation is a query/mutation is definitely possible (fairly easy, in fact), one challenge might be the magic nature. I think you could take a lead from JST's Core playbook, where you always generate the same functions, but in the case of a |
Totally agree on the Exposing the What would be a good name for a function covering query, mutation and subscription? |
This is great, we were even thinking in adding support for the official lib (reasonml-community/reason-apollo-hooks#3) but here is definitely a better place to have it! Also about the full query for different situations was a discussion we had way back then, I'm not sure about having different methods for each but I'm curious to see how that would look like |
@nikgraf I haven't tried to compile it, but based on past experience I think you would have to disambiguate record access in the following case: type foo = { result: ... };
...
switch(query.Apollo.result) {
...
} Granted, this is not a very common case, but still. |
I saw this, and thought I'd share it here: https://github.com/sync/hackerz/blob/master/app/GraphqlHooks.re |
Any status update on this effort? I think a dedicated Apollo PPX would bring a lot of value. There are a bunch of situations like So while I’m very excited about improved ergonomics, this hasn’t been my main pain point when working with Apollo. I feel like providing a At first I was fine with just going through the pain of writing JSON encoders and decoders combined with parse for everything in these situations, but then I would find that the parent query or something would get an addition of some data and we’d end up with a mismatch because now we’re only writing a subset of what’s in the cache and it fails. Worse, it seems that Apollo provides no mechanism for detecting when this situation happens. At best you get a console warning about a “Missing field …” if you’re in development. |
@jeddeloh its in a separate repo https://github.com/Astrocoders/reason-apollo-hooks |
We added code-gen support for Astrocoders' fork, you can see the current usage for both queries and mutations here: https://serve.onegraph.com/short/B8DR68 (open code exporter and choose |
This is a proposal for the future of reason-apollo.
I just created a first version implementing a useQuery hook based on the new
@apollo/react-hooks
beta. You can find it here: https://github.com/nikgraf/reason-apollo-hooks/blob/master/src/Apollo.reHere you can see how it's used: https://github.com/nikgraf/reason-apollo-hooks/blob/master/src/App.re
Personally I don't like the extra step of
Apollo.CreateQuery
. I was thinking we could create a fork of the graphql-ppx specifically for reason-apollo to achieve the following API:The PPX would be named gql to avoid naming conflicts with graphQL PPX and the module would automatically expose
useQuery
The text was updated successfully, but these errors were encountered: