-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
RFC: Primitive Proxies #1516
Comments
@redbar0n You may be interested on this one. |
Proxies sounds good. The implementation goes over my head, though. Will probably have more opinions and suggestions as far as the API goes. user.name.$skip({ if: showName }) looks particularly neat! Compared to previous suggestion in #448 : user.name({ '@skip': { if: showName } }) // from the suggestion in issue 448 which was: u.member({ '@skip': { if: true } }) But what about duplicate directives on the same field, which the GraphQL spec allows, as you mentioned previously. So this previous suggestion: u.name({ '@skip': { if: skipName }, ‘@include’: { if: true } }), Could maybe be chained like this instead? user.name.$skip({ if: showName }).$include({ if: includeName }) Btw, the React PoC gives:
|
@redbar0n Sorry I forgot to fork again before I start testing for nullables, the React PoC should be working now. Directives API should be easy if we have primitives sorted out, the main concern is whether people find primitive wrapper classes surprising. i.e. This problem could be particularly bad for booleans, |
Could this work? query.me.username.value
query.me.username.directives I feel like I've seen similar type of API's in JS before, maybe in data or request objects, or maybe on the frontend with stuff like |
Vanilla conventions such as I like the chaining API for directives, I am wondering if users would find primitive objects surprising, consider the following example: function Component() {
return (
<>
{ // This will ALWAYS render
query.me.isVerified && <h1>Verified</h1>
}
{ // This renders correctly
query.me.isVerified.valueOf() && <h1>Verified</h1>
}
</>
);
} The |
Just a thought: If the underlying implementation is a proxy object, then maybe it is best to use an object as the API instead of chaining, to reduce the impedance mismatch? Inspired by reading: "Passing a shared value without .value getter causes Reanimated to watch for shared value changes." https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/animations/#animations-in-inline-styles |
@redbar0n How would you like to add directives with object as the API? |
@vicary ah, I see how it was ambiguous. I was thinking about passing in an object to a function, instead of chaining. But that only works for setting the proxy state, not retrieving it. |
Yes, I think so. I would for sure. I'm coming back to my suggestion here #448 (comment) :
I think that would solve it, because then you'd have full control over what the function returns. The only thing the user would have to remember is to always end the chaining with a |
Summary
Just had a rough idea of primitive proxies while I am refactoring, PoC works so far.
This, albeit a bit hacky, allows us to add custom methods into scalars while retaining all existing primitive methods.
This affects all existing scalars, please let us know what you think and whether you have conflicting implementations.
Intended use cases
Directives
(This is only an example, API not decided yet)
Custom GraphQL Scalars
Besides directives, I am also planning to treat this as an extension point for custom GraphQL scalars (graphql-scalars) in the future.
Questions
null
andundefined
The text was updated successfully, but these errors were encountered: