-
Notifications
You must be signed in to change notification settings - Fork 792
Query skip option does not work with react-redux's connect decorator #350
Comments
Hmmm... this seems very surprising. If you write skip(ownProps) { console.log(ownProps); } what do you see? |
I have seemingly the same behavior happening when using SSR, during the getDataFromTree phase. With this setup: @connect(
({globalSearch: name}) => ({
name,
doSearch: Boolean(name),
}),
{setFilter}
)
@graphql(SearchResultsQuery)
class MainSearchbox extends Component { =>
When I instrument the |
Same. This appears to only happen for me during SSR. Wondering if Apollo is somehow bypassing |
Oh! This is during ssr? Ok, I'll look into it |
So the problem here is that A work around would be to insert some kind of simple wrapper between the two that short-circuits this. For instance, you can probably use one of the things in this library: https://github.com/acdlite/recompose, like @connect(...)
@defaultProps({foo: 'bar'})
@graphql(...) @jbaxleyiii I can think of two solutions: a. In b. Not make |
Couldn't you just recurse down through wrapped components to find the "base"? |
@thebigredgeek that's more or less what I'm suggesting in a. The problem is that I think one of the major reasons for making it a static property was so other libraries could define their own |
@tmeasday I think we should remove the static nature of fetchData! 👍 |
One interesting albeit unorthodox approach might be to append a uuid suffix to the fetchData namespace that is computed once at startup and used everywhere in constant form. This would prevent collision. You could then expose a "public" version with the name simply "fetchData". This way if it is overridden apollo still works |
I agree though. fetchData should be hidden IMO. Perhaps some sort of public interface could be exposed, but I think for safety it makes more sense for the public interface to be a reference to a private interface that is guaranteed to work |
Fixes issue with Redux's `connect` hoisting `fetchData` statically. See #350
Fixes issue with Redux's `connect` hoisting `fetchData` statically. See #350
Fixes issue with Redux's `connect` hoisting `fetchData` statically. See #350
Fixes issue with Redux's `connect` hoisting `fetchData` statically. See #350
* Use instance.fetchData rather than a static method. Fixes issue with Redux's `connect` hoisting `fetchData` statically. See #350 * Added changelog entry
Fixed by v0.7.1 |
Yay thanks!!! |
Hi @tmeasday, it looks like this is still an issue as of react-apollo v2.0.4 when the See this StackOverflow question for more context: How To Pass Props From Redux Store into Apollo GraphQL Query? Luckily the workaround is effective for some users, but I like to test my components separately from Apollo -- I use several decorators to give the test component its static props, but mock the Apollo data -- thus Do you think this is solvable? Note: Not sure how I "unassigned" you? That was automatic I think. |
@cooperka I don't think it can really conceptually work to do it the other way, if you think about how the component heirarchy is working in this case. If you want to test the component without If you are using export default compose(
connect(mapPropsForGraphql),
graphql(...),
connect(mapPropsForComponent))(Component) Does that help?
Ha! you have special powers. |
Hmm, that does make sense -- I was originally thinking about props as being defined on the component, but really they're being passed into the component, in which case I was thinking I solved my issue by simply mocking the // __mocks__/react-apollo.js
module.exports = {
ApolloProvider: ({ children }) => children,
graphql: () => (component) => component,
}; Thanks again for the help! |
The new component-based API in 2.1 sidesteps this whole issue, you can do
the proper composing yourself. Nice :)
…On Sat, Mar 24, 2018 at 5:29 PM Kevin Cooper ***@***.***> wrote:
Hmm, that does make sense -- I was originally thinking about props as
being defined on the component, but really they're being passed *into*
the component, in which case connect passes the props *into* the graphql
HOC.
I was thinking graphql could statically analyze whatever data connect has
added to the component in order to grab the props, but clearly that would
be overly complex and out of the scope of Apollo's job.
I solved my issue by simply mocking the graphql HOC with Jest:
// __mocks__/react-apollo.js
module.exports = {
ApolloProvider: ({ children }) => children,
graphql: () => (component) => component,
};
Thanks again for the help!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#350 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADWlrf8VDXDAavcnltG4LcExng1wLZaks5thnRZgaJpZM4LCFbF>
.
|
Steps to Reproduce
Buggy Behavior
I have to ensure that
isAuthenticated
isn't undefined before checking if it is false because the skip callback seems to fire BEFORE the connect method. This seems to happen regardless of whether@connect
occurs above or below@graphql
.Expected Behavior
ownProps
should be decorated by@connect
, if used, beforeskip
is called.Version
The text was updated successfully, but these errors were encountered: