Apollo Client 查询模式不是 GraphQLSchema 的实例

Apollo Client query schema is not instance of GraphQLSchema

我正在尝试关注 apollo client installation instructions

我正在将他们正在做的事情完全复制到我的项目中,但是每当我调用 client.query 时,我都会收到 400 状态代码并出现以下错误:

Error: Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory.

这是我项目的所有代码 index.js:

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

我已经根据 apollo 文档中的说明使用以下选项配置了我的 babelrc 文件:

{
  "presets": ["env", "react"],
  "plugins": [
    "graphql-tag"
  ]
}

我的项目只是一个带有react的基本webpack配置。我已经尝试删除我的 npm 包,并检查我的项目中是否存在冲突的 graphql 版本,但没有成功。我最好的猜测是 graphql-tag 没有正常工作,我的查询没有被翻译成请求的适当语法。感觉就像我错过了一些非常基本的东西。我将不胜感激任何澄清。谢谢!

这看起来不像是您的客户端配置问题,而是 Launchpad 的错误。如果您访问该端点的 GraphiQL 接口并尝试 运行 查询,它会抛出相同的错误。

如果您使用 Github 帐户登录 Launchpad,您可以启动一个新的 pad(与那个相同),保存它,然后在您的项目中使用 url .