简体   繁体   English

带有React的Apollo客户端2无法进行查询

[英]Apollo client 2 with React couldn't make query

I have an issue with Apollo client version 2 with React. 我在使用React的Apollo客户端版本2时遇到了问题。 ( https://www.apollographql.com/docs/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: 当我根据文档设置Apollo客户端时,我无法在GraphQl服务器上进行查询,它会引发错误:

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. 不确定这里到底发生了什么,但似乎是Windows上的webpack问题。 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. 我很幸运能够在MacBook Pro上运行Parallels(Windows 10),因此我可以通过在Mac上而不是Windows上运行webpack来解决这个问题。

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. 如果你无法在Mac上构建,虽然这在短期内没有多大帮助。 One more reason to consider switching to Apple if you haven't already ;) 如果您还没有考虑切换到Apple的另一个原因;)

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. Probs需要记录webpack团队的一个问题才能解决问题https://github.com/webpack/webpack/issues ,但这项工作现在将让我解决,所以我将继续前进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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