Skip to content
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

Redux integration #1041

Closed
kennetpostigo opened this issue Nov 16, 2015 · 11 comments
Closed

Redux integration #1041

kennetpostigo opened this issue Nov 16, 2015 · 11 comments

Comments

@kennetpostigo
Copy link

Hello,

I'm currently working on a small lib that easily enables people to integrate GraphQL into your redux workflow. Using it would look like this:

// Params it takes in
reachGraphQL(path, query, queryParams = {}, actionCreator)

// In use
reachGraphQL('localhost:3000/graphql',`{
    {
        users{
            name
        }
    }
}`, {}, getUsers);

It depends on the user to utilize redux-thunk when creating a store. Once it executes it dispatches the actionAction creator that was passed in.

I wanted to ask if there is anything that comes to mind that I should consider that I may have over looked.

@gaearon
Copy link
Contributor

gaearon commented Nov 16, 2015

It depends on the user to utilize redux-thunk when creating a store.

This is generally not a very good idea. Userland extensions shouldn't rely on user to use a particular third-party middleware. Make your own middleware if you'd like, but don't force user to use Redux Thunk.

@kennetpostigo
Copy link
Author

@gaearon, So I should integrate a middleware of my creation into the package? I just thought it would be easier to use one thats already made.

@gaearon
Copy link
Contributor

gaearon commented Nov 16, 2015

User might already be using middleware that's incompatible with Redux Thunk.

@gaearon
Copy link
Contributor

gaearon commented Nov 16, 2015

Anyway, it's hard to say more because the code snippet you posted does not fully describe the API you implement.

@kennetpostigo
Copy link
Author

@gaearon Thank you for the feedback 😄!

@kennetpostigo
Copy link
Author

Well, @gaearon currently that is the only exposed part of the API its inner working are like so:

import transport from ('./utils/transport.js');

function reachGraphQL (path, query, queryParams = {}, actionCreator) {
    return async dispatch => {
        try{
            let response = await transport(path, query, queryParams);
            dispatch(actionCreator(response.data));
        } catch (error) {
            console.log(error)
        }
    }
}

The transport import is using isomorphic-fetch in order to create the call.

@gaearon
Copy link
Contributor

gaearon commented Nov 16, 2015

I still don't understand the API. Maybe we should wait for README for your project and then we can comment on it :-)

@kennetpostigo
Copy link
Author

@gaearon will do.

@kennetpostigo
Copy link
Author

@gaearon heres the repo, I just published the beta. http://www.github.com/kennetpostigo/react-reach

@gaearon
Copy link
Contributor

gaearon commented Nov 17, 2015

I don't see where you rely on thunk middleware. You dispatch(actionCreator(response.data)) but it doesn't matter whether this action creator is powered by Redux Thunk or just returns an action (or a Promise, or whatever middleware you use). So it seems fine to me.

@gaearon gaearon closed this as completed Nov 17, 2015
@kennetpostigo
Copy link
Author

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants