-
Notifications
You must be signed in to change notification settings - Fork 28
Conversation
Thanks for your proposal! |
Sounds great. I am pretty new to Reason/OCaml, so there are probably many things that can be better. |
No opinions of otherss so far but in overall I liked the simplification. |
I updated the PR, a few changes:
|
Thanks a lot @jfrolich ! These next upcoming weeks we'll be really busy for me but I'll try to review and merge ASAP |
examples/persons/package.json
Outdated
"css-loader": "^3.2.0", | ||
"graphql_ppx": "^0.2.8", | ||
"@baransu/graphql_ppx_re": "^0.2.0-beta.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so cool to see activity again in this package. It has so much potential.
Cool. No worries. When this is merged I also have a pull-request that allows to do |
This looks fantastic! We've added code-gen support for the current API, you can see the current usage for both queries and mutations here: https://serve.onegraph.com/short/B8DR68 (open code exporter and choose I'd love to get this merged in and make the code that much more approachable for workshops (and for me too of course!). |
Amazing!! Will get this merged before weekend 🙏 |
Wow that codegen is awesome! |
I merged in the upstream changes and upgraded |
Merged will release soon! |
Thanks lot @jfrolich for this!! Awesome work. And thanks everyone for giving feedback |
I am a bit late to the party, but what happened to |
Looks like we have some regressions here indeed, along with #57 |
/** | ||
* apollo-client/src/core/watchQueryOptions.ts | ||
*/ | ||
type errorPolicy = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are those not used anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that is probably an upstream change that I forgot to merge in (diffs were not working anymore so I had to manually look up what has been added to master in the meantime)
We haven't released this just yet so there is still time to fix |
I will try to run the example project locally, and see what I can fix 😄 |
| (None, None) => raise(Error("Need to pass a mutation")) | ||
}; | ||
|
||
React.Ref.setCurrent(parse, Some(mutation##parse)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this runs inside of useMemo
? Callback passed into useMemo
must be pure because it will run on every render, see react docs. And later it calls jsMutate
which will send the actual query, is it correct?
I am not sure it is a good idea to implement it this way, I think we will have to rethink this approach a bit, what do you think, @fakenickels ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad, spent some time alazying the code and realised that it is memoizing the function and not actually calling it 🤦♀ 😄 Maybe it makes sense to use useCallback
instead of useMemo
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I merged this change from master, but good suggestion. useCallback is just a shortcut for memoizing functions with useMemo if I remember correctly.
(edit: it actually memoizes the result and doesn't memoize the function, so useCallback is not applicable here)
edit2:
Callback passed into
useMemo
must be pure because it will run on every render, see react docs.
It does not run on every render, it only runs if the dependencies change.
|
||
let useMutation = | ||
( | ||
~incompleteMutation=?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure incompleteMutation
is the right name here, it might get really verbose and tedious to write on many mutations, can we come up with something more succinct for this case? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually you would use the mutation argument, unless you need to set the arguments dynamically. It would be better to have the mutation as an optional argument, but that needs some changes on the javascript side (I think!). Anyway I agree it's not ideal (and hopefully temporarily). Let me know what better name you are thinking of!
| (_, Some(incompleteMutation)) => incompleteMutation | ||
| (None, None) => | ||
raise( | ||
Error("You need to provide a mutation or an incomplete mutation"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to have a better exception type, something more descriptive than Error
, does it makes sense, @fakenickels ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can avoid throwing errors here by making sure the user can't make a mistake on the type level? I think it will be better to not throw errors if the type system can guarantee that the values are correct 😄 I was thinking about using some kind of a variant:
type mutationConfig('a) = Query(string) | Config('a);
and then have it in useMutation
:
let useMutation =
(
~mutation: mutationConfig('a)=?,
~client=?,
....
(),
)
And remove incompleteMutation
, maybe something in that direction could be a more intuitive API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we can remove the need to pass in incompleteMutation in the future which will solve this issue.
I think will be better to revert this and open the PR again so we can make we have less breaking changes |
@jfrolich would you mind reopening this PR? |
Sorry about this. I could directly merge master because due to filename changes it wouldn't diff the fires. So I looked up the individual commits and applied them manually, but I messed up and missed two additions! I will re-open this PR, and fix the issues as reported. Some comments of @MargaretKrutikova are about existing code not related to this PR. This can be tackled in a separate PR. (Except the naming of |
@all-contributors add @jfrolich code, review and ideas |
I've put up a pull request to add @jfrolich! 🎉 |
This is a WIP, but I found that the functor API created quite a bit of boilerplate code. When I looked at the source of reason-urql, it found a way to implement a more concise API, so I messed around with the source of reason-react-hooks if we can have something like that that with apollo and this is the result. I would like to get your opinion and possible improvements.
In short we can go from this:
to this:
Similar for mutations, however we need to pass in an initial mutation if we want to provide variables later:
We can run the create function like this:
or we can add the mutation from the get go (and then we don't have to supply it later):
To be honest the mutation API is suboptimal. I think there is a way that we do not need to provide the
incompleteMutation
but this involves changing the javascriptuseMutation
hook.OR we need to modify
graphql_ppx
, to generate a different module.