Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

currentObservable.query.getCurrentResult is not a function #3148

Closed
mfpiccolo opened this issue Jun 21, 2019 · 30 comments · Fixed by #3149
Closed

currentObservable.query.getCurrentResult is not a function #3148

mfpiccolo opened this issue Jun 21, 2019 · 30 comments · Fixed by #3149
Assignees
Milestone

Comments

@mfpiccolo
Copy link

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

@GreenGremlin
Copy link

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].

@mfpiccolo
Copy link
Author

2.6.3 does indeed fix it. Thanks. I will leave this open due to 2.5.7 issue @GreenGremlin mentioned.

@hwillson
Copy link
Member

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.

@hwillson hwillson self-assigned this Jun 21, 2019
@hwillson hwillson added this to the Release 3.0 milestone Jun 21, 2019
hwillson added a commit that referenced this issue Jun 21, 2019
RA 3 is dependent on changes made in `apollo-client` 2.6.3.

Fixes #3148.
@GreenGremlin
Copy link

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.

@hwillson
Copy link
Member

Definitely a fair point @GreenGremlin. We were a bit anxious to get issue #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 #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.

@hwillson
Copy link
Member

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 #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)

@GreenGremlin
Copy link

@hwillson that sounds like a great solution. Thanks!

hwillson added a commit that referenced this issue Jun 22, 2019
To fix issue #3090, the `ObservableQuery.resetQueryStoreErrors`
method was introduced in `apollo-client` 2.6.3. While
`apollo-client` 2.6.3 is a peer dep of the latest version of
`react-apollo` (2.5.7), people who can't update their version
of `apollo-client` to >= 2.6.3 are running into issues when
updating to the latest version of `react-apollo`, since
`ObservableQuery.resetQueryStoreErrors` isn't available to them.
Since we can't enforce the version of `apollo-client` people are
using, this commit adjusts the `Query` component to only use
`resetQueryStoreErrors` if it's available. If it isn't, it will
call into the `ObservableQuery`'s private API to do the same
things as `resetQueryStoreErrors`. This is a hack, but it is
temporary as `react-apollo` is launching soon, and will enforce
a minimum `apollo-client` version of 2.6.3 (so this workaround
won't be needed).

Fixes #3148.
@hwillson
Copy link
Member

@GreenGremlin I've wired up a solution in #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!

hwillson added a commit that referenced this issue Jun 22, 2019
* Conditionally use AC's `ObservableQuery.resetQueryStoreErrors`

To fix issue #3090, the `ObservableQuery.resetQueryStoreErrors`
method was introduced in `apollo-client` 2.6.3. While
`apollo-client` 2.6.3 is a peer dep of the latest version of
`react-apollo` (2.5.7), people who can't update their version
of `apollo-client` to >= 2.6.3 are running into issues when
updating to the latest version of `react-apollo`, since
`ObservableQuery.resetQueryStoreErrors` isn't available to them.
Since we can't enforce the version of `apollo-client` people are
using, this commit adjusts the `Query` component to only use
`resetQueryStoreErrors` if it's available. If it isn't, it will
call into the `ObservableQuery`'s private API to do the same
things as `resetQueryStoreErrors`. This is a hack, but it is
temporary as `react-apollo` is launching soon, and will enforce
a minimum `apollo-client` version of 2.6.3 (so this workaround
won't be needed).

Fixes #3148.

* Changelog update
@hwillson
Copy link
Member

react-apollo 2.5.8 is now available. Let me know if you notice any issues. Thanks!

@krvajal
Copy link

krvajal commented Jun 27, 2019

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.

@jcane86
Copy link

jcane86 commented Jul 10, 2019

+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

@pffreitas
Copy link

pffreitas commented Jul 16, 2019

@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"
  }

@jcane86
Copy link

jcane86 commented Jul 16, 2019

yesss!

@pffreitas you're a hero!

Cheers for that, it works

@idanlo
Copy link

idanlo commented Jul 23, 2019

@jcane86 his solution still didn't fix it for me (with appsync), did you change anything else?

@jcane86
Copy link

jcane86 commented Jul 23, 2019

@idanlo I believe I just did a yarn install and restarted the dev server.

Are you still getting the same error about getcurrentresult?

@idanlo
Copy link

idanlo commented Jul 23, 2019

@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

@jcane86
Copy link

jcane86 commented Jul 23, 2019 via email

@idanlo
Copy link

idanlo commented Jul 23, 2019

@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

@developdeez
Copy link

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" />; }

@dctanner
Copy link

dctanner commented Aug 8, 2019

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.

@Ko-stant
Copy link

Ko-stant commented Aug 8, 2019

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",

@acostajake
Copy link

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?

@Ayc0
Copy link

Ayc0 commented Aug 14, 2019

This seems to be related to this issue: #3365

@vemundeldegard
Copy link

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.

@ghost
Copy link

ghost commented Aug 16, 2019

@jcane86 I'm using AppSync as well and none of the solutions below workes for me. Any news in this sense?

@manicode097
Copy link

With exactly the same setup, useMutation works for me. However, useQuery throws currentObservable.query.getCurrentResult. Any solution?

@stewartduffy
Copy link

Has anyone got this working with AppSync & @apollo/react-hooks ?

@Nisfan
Copy link

Nisfan commented Sep 13, 2019

@manicode097, #3148 (comment) 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;
};

@superjose
Copy link

superjose commented Sep 15, 2019

@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"

@superjose
Copy link

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

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

Successfully merging a pull request may close this issue.