-
Notifications
You must be signed in to change notification settings - Fork 41
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
[WIP]:Initial Compose functionality and tests #31
Conversation
Couldn't we just add a compose helper similar to const isHappy = compose(
isNotSad,
isNotMad,
isNotStressed,
isNotAnxious
)(
(root, args, context, info) => ...
(root, args, context, error, info) => ...
) |
Yeah, absolutely. Figured I'd stick strictly to the proposed implementation in the v2 spec, but that's totally reasonable. |
Oh I see what you did. This is actually quite clever! Let's stick with this approach, but maybe axe the "composable" class requirement? |
Yeah, we can make composable a function, rather than a class. It's more consistent with the rest of the API. |
e10d9f5
to
84696cf
Compare
@thebigredgeek ok, refactored and added a few more tests. // The basic API would be:
const myResolver = createResolver( resolve => {}, error => {} );
const base = composable( resolve => {}, error => {} );
// All composed will pass calls and bubble errors though base.
const composed = base.compose( {
r1: { resolve: r => {}, error: e => {} }, // declate separate resolve and error handlers
r3: resolve => {}, // resolve declared inline
r4: myResolver // reuse a pre-constructed resolver
});
// And provide your Query and Mutation wiring like so...
{ Query: {
someResolver: resFn,
...composed
},
Mutation: {
someMutation: muteFn,
...composed
} Added babel-plugin-transform-object-rest-spread for the spread operator syntax. Updated babel-preset-es2015 to babel-preset-env as recommended by babel's docs. (though not strictly necessary for this PR) |
Right, sorry... what I meant was that couldn't we just do something like... const base = createResolver(
() => undefined,
err => err
);
// All composed will pass calls and bubble errors though base.
const composed = base.compose( {
r1: { resolve: r => {}, error: e => {} }, // declate separate resolve and error handlers
r3: resolve => {}, // resolve declared inline
r4: myResolver // reuse a pre-constructed resolver
});
// And provide your Query and Mutation wiring like so...
{ Query: {
someResolver: resFn,
...composed
},
Mutation: {
someMutation: muteFn,
...composed
} So basically just adding |
@mringer bump |
Word, busy couple weeks at work, should be able to circle back to this in the next couple days. |
add babel-plugin-transform-object-rest-spread for spread syntax support add test to cover spreading composed into object.
99dd1bb
to
3593237
Compare
@thebigredgeek I think this is what you were asking for. |
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.
glorious
#4
Quick and dirty implementation of the compose functionality proposed in the API v2 thread.
With some basic tests.
Proposed Usage: