简体   繁体   中英

Apollo client 2 with React couldn't make query

I have an issue with Apollo client version 2 with React. ( https://www.apollographql.com/docs/react/ )

When I setup Apollo client according to docs, I can't make query on GraphQl server, it raises error:

Uncaught (in promise) TypeError: _super.call is not a function
    at new ObservableQuery (ObservableQuery.js:36)
    at QueryManager.watchQuery (QueryManager.js:393)
    at QueryManager.js:420
    at new Promise (<anonymous>)
    at QueryManager.query (QueryManager.js:418)
    at ApolloClient.query (ApolloClient.js:86)
    at Object._typeof (index.js:21)
    at __webpack_require__ (bootstrap 4164d2c8f7d280e544dd:19)
    at Object.<anonymous> (location.js:34)
    at __webpack_require__ (bootstrap 4164d2c8f7d280e544dd:19)

My code here:

import { ApolloClient } from "apollo-client";
import { HttpLink } from "apollo-link-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import gql from "graphql-tag";
const client = new ApolloClient({
  link: new HttpLink({ uri: "https://q80vw8qjp.lp.gql.zone/graphql" }),
  cache: new InMemoryCache()
});
client
  .query({query: gql`{hello}`})
  .then(console.log);

Could anyone help me in resolving this issue?

Disclaimer: My response assumes you are having the same problem as me.

Not sure exactly what is going on here, but seems like a problem with webpack on Windows. I'm fortunate enough to be running Parallels (Windows 10) on a MacBook Pro so I was able to overcome this problem by running webpack against my Windows project on the Mac instead of Windows.

Not quite an answer, but a clue, and work around.

If you're not able to build on a Mac though this is not much help in the short term. One more reason to consider switching to Apple if you haven't already ;)

Probs need to log an issue with the webpack team to get the problem fixed https://github.com/webpack/webpack/issues , but this work around will get me by for now, so am going to move on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM