-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose all of urql context #64
Conversation
Thanks @gugahoa! The intention is to get all of the hooks bound and be fully on the JSX 3 syntax. Once we land |
I have some thoughts about tests, but it pertains more about the type safety of the bindings. As they're right now, they're not type safe, so you can compile unsound code and it'll only blow up at runtime. (The hooks bindings, at least, the others I haven't taken a look yet) Maybe it would be interesting to try and create tests for type safety? |
🤔 Can you give an example of unsound code that would compile but blow up at runtime? I definitely like the idea of verifying type safety, but it'd be helpful to have an example of where things are going awry currently 😅 |
Sure, in It'll compile just fine, but if you try to render the component, it'll crash the React application. |
That's because of the bindings to JS-land I have been trying to think of ways to make it safer, there's three approaches I thought of:
The approach 2 seems like it would make users add a lot of boilerplate if they want to have type-safe return values, the approach 3 seems like it would require some refactoring. |
@gugahoa gotcha, thanks for the Gist and for being patient with the explanation. I like approach 3 best, and I think our components do support something like this, i.e. this seems to work: module PatDog = [%graphql
{|
mutation patDog($key: ID!) {
patDog(key: $key) {
pats
}
}
|}
];
<Mutation query=Mutations.patDog>
...{({executeMutation}: Mutation.mutationRenderProps(PatDog.t)) =>
<EmojiButton
emoji={j|✋|j}
count={string_of_int(pats)}
hex="db4d3f"
onClick={_ => executeMutation(Some(payload)) |> ignore}
/>
}
</Mutation> Is there any chance we can use this same approach for the hooks? For example, I believe this works already for module PatDog = [%graphql
{|
mutation patDog($key: ID!) {
patDog(key: $key) {
pats
}
}
|}
];
let ({ response }: Hooks.useMutationResponse(PatDog.t), executeMutation) = Hooks.useMutation(~query=Mutations.treatDog);
let pats = switch (response) {
/* Attempting to access d##patDog##pat or d##patDog##treat will fail compilation. */
| Data(d) => d##patDog##pats
| _ => 0
}; It does force users to pass in the type explicitly, but that's the point of type arguments 😅If we document this well, do you feel it would work as a nice API? I'm not totally sure outside of type arguments how we apply the |
@parkerziegler I have been looking for a way to do it in a type safe way, but I can't seem to find any documentation about a module signature that the output from |
Hello again! :)
I noticed only the Provider binding from urql was exposed here, whereas in the urql lib it exports Provider, Consumer and Context, so I created binding for those.
Is the intention to have 100% bindings from urql before 1.0?