Intended outcome:
I was trying to upgrade to the new 3.0.0-beta.2 with this repo:
https://github.com/mfpiccolo/react-apollo-realworld-example-app
Actual outcome:
TypeError: this.currentObservable.query.getCurrentResult is not a function
FullTrace:
react-hooks.esm.js:201 Uncaught TypeError: this.currentObservable.query.getCurrentResult is not a function
at QueryData../node_modules/@apollo/react-hooks/lib/react-hooks.esm.js.QueryData.getQueryResult (react-hooks.esm.js:201)
at finish (react-hooks.esm.js:79)
at QueryData../node_modules/@apollo/react-hooks/lib/react-hooks.esm.js.QueryData.execute (react-hooks.esm.js:84)
at useQuery (react-hooks.esm.js:293)
at Query (react-components.esm.js:7)
at renderWithHooks (react-dom.development.js:12938)
at mountIndeterminateComponent (react-dom.development.js:15020)
at beginWork (react-dom.development.js:15625)
at performUnitOfWork (react-dom.development.js:19312)
at workLoop (react-dom.development.js:19352)
at HTMLUnknownElement.callCallback (react-dom.development.js:149)
at Object.invokeGuardedCallbackDev (react-dom.development.js:199)
at invokeGuardedCallback (react-dom.development.js:256)
at replayUnitOfWork (react-dom.development.js:18578)
at renderRoot (react-dom.development.js:19468)
at performWorkOnRoot (react-dom.development.js:20342)
at performWork (react-dom.development.js:20254)
at performSyncWork (react-dom.development.js:20228)
at requestWork (react-dom.development.js:20097)
at scheduleWork (react-dom.development.js:19911)
at scheduleRootUpdate (react-dom.development.js:20572)
at updateContainerAtExpirationTime (react-dom.development.js:20600)
at updateContainer (react-dom.development.js:20657)
at ReactRoot../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:20953)
at react-dom.development.js:21090
at unbatchedUpdates (react-dom.development.js:20459)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:21086)
at Object.render (react-dom.development.js:21155)
at Object../src/index.js (index.js:8)
at __webpack_require__ (bootstrap e3bb803e2743b8353815:678)
at fn (bootstrap e3bb803e2743b8353815:88)
at Object.0 (tokenStorage.js:3)
at __webpack_require__ (bootstrap e3bb803e2743b8353815:678)
at bootstrap e3bb803e2743b8353815:724
at bootstrap e3bb803e2743b8353815:724
index.js:2178 The above error occurred in the <Query> component:
in Query (at WithViewer.js:28)
in WithViewer (at Menu.js:8)
in ul (at Menu.js:7)
in Menu (at Header.js:9)
in div (at Header.js:7)
in nav (at Header.js:6)
in Header (at Page.js:10)
in Page (at Home.js:29)
in Home (created by Context.Consumer)
in ApolloConsumer (created by withApollo(Home))
in withApollo(Home) (created by Route)
in Route (at App.js:19)
in Switch (at App.js:18)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:16)
in ApolloProvider (at App.js:15)
in App (at src/index.js:8)
How to reproduce the issue:
Clone the project, npm i && npm start
Version
3.0.0-beta.2
I'm seeing the same thing on v2.5.7. It looks a change was recently made to apollo-client that adds the getCurrentResult function. Upgrading to [email protected] fixes the error, but I'm guessing react-apollo v2.5.7 probably shouldn't require [email protected].
2.6.3 does indeed fix it. Thanks. I will leave this open due to 2.5.7 issue @GreenGremlin mentioned.
Thanks for reporting this. react-apollo 2.5.7 has a minimum of apollo-client 2.6.3 set as a peer dep for this reason exactly. The RA 3 peer deps are a version behind though, so I'll get those updated.
Thanks for reporting this. react-apollo 2.5.7 has a minimum of apollo-client 2.6.3 set as a peer dep for this reason exactly. The RA 3 peer deps are a version behind though, so I'll get those updated.
Peer dependencies are not enforced, which means consumers pinned to react-apollo 2.5.x apollo-client 2.5.x are broken. It seems unfortunate that what is essentially a breaking change, for some users, was released in a patch release.
Definitely a fair point @GreenGremlin. We were a bit anxious to get issue https://github.com/apollographql/react-apollo/issues/3090 fixed, since it's impacting quite a few users (and is cropping up in other open issues). But I agree, this is unfortunate. I can revert the changes for that PR and publish a new version, but I'm wondering which option people would prefer. To have https://github.com/apollographql/react-apollo/issues/3090 fixed now in react-apollo 2 (which means version pinning react-apollo on their side if they can't update apollo-client), or wait until react-apollo 3 is launched to get this fixed.
Actually, I'll do this another way - I'll make the required changes from apollo-client optional; if using AC >= 2.6.3 they'll be enabled, it not they'll be disabled (and https://github.com/apollographql/react-apollo/issues/3090 won't be fixed). A new react-apollo version will be coming shortly.
(I'll leave things the way they are in RA 3)
@hwillson that sounds like a great solution. Thanks!
@GreenGremlin I've wired up a solution in https://github.com/apollographql/react-apollo/pull/3151 that should hopefully give us the best of both worlds. It's a hack for sure, but if using apollo-client < 2.6.3, react-apollo will call into ObservableQuery's private API to do the same things as ObservableQuery.resetQueryStoreErrors (which is only in AC 2.6.3). This should cover people who can't update their apollo-client version yet (and will still give them a fix for #3090), and luckily is temporary since react-apollo 3 will enforce apollo-client >= 2.6.3. This hack will remain in the react-apollo 2.x codebase only. I'll get react-apollo 2.5.8 published shortly. Thanks!
react-apollo 2.5.8 is now available. Let me know if you notice any issues. Thanks!
I had the same issue using "@apollo/react-hooks:0.1.0-beta.10". Upgrading apollo-client to 2.6.3 also fixed the issue for me.
+1 for @apollo/react-hooks
@hwillson any chance to apply the fix there as well?
Unfortunately I am using the appsync Apollo client, so I can't update to 2.6.3
@jcane86 you can force appsync to resolve to apollo-client 2.6.3
add the following to your package.json
"resolutions": {
"apollo-client": "2.6.3"
}
yesss!
@pffreitas you're a hero!
Cheers for that, it works
@jcane86 his solution still didn't fix it for me (with appsync), did you change anything else?
@idanlo I believe I just did a yarn install and restarted the dev server.
Are you still getting the same error about getcurrentresult?
@jcane86 I get a warning that says Found @client directives in a query but no ApolloClient resolvers were specified. This means ApolloClient local resolver handling has been disabled, and @client directives will be passed through to your link chain.
I think it doesn't recognize my resolvers with apollo-link-state because it was deprecated in apollo-client v2.5 but the appsync client does not receive any resolvers
I'm sorry, I can't help you with that, I'm not familiar with local
resolvers.
It looks like the original issue is solved though. Maybe open a new issue
with your particular issue to get more attention to it?
On Tue, 23 Jul 2019, 13:26 Idan Lottan, notifications@github.com wrote:
@jcane86 https://github.com/jcane86 I get a warning that says Found
@client directives in a query but no ApolloClient resolvers were specified.
This means ApolloClient local resolver handling has been disabled, and
@client directives will be passed through to your link chain.
I think it doesn't recognize my resolvers with apollo-link-state because
it was deprecated in apollo-client v2.5 but the appsync client does not
receive any resolvers—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/apollographql/react-apollo/issues/3148?email_source=notifications&email_token=AAFSHCVJU2NTC6BJVDFXXSDQA4WKVA5CNFSM4H2UYEE2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2TVVMQ#issuecomment-514284210,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFSHCTK5EIOWOTI7OVOZ5LQA4WKVANCNFSM4H2UYEEQ
.
@jcane86 this is a problem with aws-appsync, they are still with apollo-client version <2.5, there is issue open there already for 4 months and no contributor has responded
Attempting to use an HOC for auth and the Query component now rapidly makes calls to the backend causing it to trigger a rate limit in my app.
Am I calling it wrong?
onst Body = withAuth(session => session && session.currentuser)(
({ showFooter, session, refetch }) => (
<div className="layout">
<header>
<Navbar ErrorHandler={ErrorHandler} session={session} />
</header>
<main style={{ display: "flex", flex: "3", flexDirection: "column" }}>
<Switch>
<Route
onEnter={refetch}
path="/members"
render={() => (
<ProfileSearch
ErrorHandler={ErrorHandler}
ReactGA={ReactGA}
session={session}
refetch={refetch}
/>
)}
exact
/>
Or am I calling Query wrong?
<Query query={GET_CURRENT_USER} fetchPolicy="network-only">
{({ data, loading, refetch }) => {
if (loading) {
return <Spinner size="large" />;
}
I'm using react, appsync and apollo. I encountered this error. My react-apollo was 3.0.0 and apollo-client 2.6.3. I found the solution was to change react-apollo to "react-apollo": "2.5.8", in package.json. Changing apollo-client versions causes other issues.
Following what @dctanner and @pffreitas built upon (thank you both)
Current versions/steps for working queries:
"apollo-client": "^2.6.3",
"react-apollo": "^2.5.8",
Then also add the resolution:
"resolutions": {
"apollo-client": "2.6.3"
}
You will get warning Resolution field "[email protected]" is incompatible with requested version "[email protected]" on install, so be aware there might be something else broken along the line. But this works now for Queries, Mutations with:
"@apollo/react-hooks": "^3.0.0",
Using Apollo-Boost, it looks like one would need to update to 0.4.4 to resolve the issue. Can someone confirm, in case it is helpful?
This seems to be related to this issue: https://github.com/apollographql/react-apollo/issues/3365
Using Apollo-Boost, it looks like one would need to update to 0.4.4 to resolve the issue. Can someone confirm, in case it is helpful?
Same issue. I am running apollo-boost 0.3.1. It did indeed fix the issue by upgrading to 0.4.4.
@jcane86 I'm using AppSync as well and none of the solutions below workes for me. Any news in this sense?
With exactly the same setup, useMutation works for me. However, useQuery throws currentObservable.query.getCurrentResult. Any solution?
Has anyone got this working with AppSync & @apollo/react-hooks ?
@manicode097, https://github.com/apollographql/react-apollo/issues/3148#issuecomment-511622210 should work and need yarn/npm install after modifying package.json
@stewartduffy Got this working by using custom hydrate function and disableOffline: true with AWSAppSyncClient client object and also need "resolutions"
export const Rehydrated = ({ children }) => {
const client = useApolloClient();
const [rehydrated, setState] = useState(false);
useEffect(() => {
if (client instanceof AWSAppSyncClient) {
(async () => {
await client.hydrated();
setState(true);
})();
}
}, [client]);
return rehydrated ? children : null;
};
@stewartduffy I also got this working.
A difference from @Nisfan is that I had disableOffline: true, so I think that doesn't have to do with it.
I can testify that by manually upgrading to:
"apollo-boost": "0.4.4", and "apollo-client": "2.6.3",
Worked.
I'm also using appsync. Here's part of my package.json:
"apollo": "^2.18.0",
"apollo-boost": "0.4.4",
"apollo-client": "2.6.3",
"apollo-utilities": "^1.3.0",
"auth0-js": "^9.10.0",
"aws-appsync": "^1.8.1",
"aws-appsync-react": "^1.2.9",
"react": "^16.8.3",
"react-apollo": "^3.0.1",
"react-dom": "^16.8.3",
"react-error-boundary": "^1.2.3",
"react-scripts": "3.1.1",
Dev dependencies:
"typescript": "^3.6.3"
For whatever the reason, if you are not using Yarn, the resolutions in your package.json won't work. You'll have to patch the package-lock.json with npm-force-resolutions.
If you're using npm, add in resolutions "apollo-client": "2.6.4"
"scripts": {
....
},
"browserslist": [
...
],
"dependencies": {
"@apollo/react-hooks": "^3.1.0",
"aws-appsync": "^2.0.0",
"aws-appsync-react": "^2.0.0",
},
"devDependencies": {
"typescript": "^3.6.3"
},
"resolutions": {
"apollo-client": "2.6.4"
}
Delete the entire node_modules folder, and then run:
npx npm-force-resolutions
This will force all the dependencies inside package.json to reference the apollo-client package correctly.
And then:
npm install
Most helpful comment
@jcane86 you can force appsync to resolve to apollo-client 2.6.3
add the following to your package.json