Apollo客户端查询模式不是GraphQLSchema

时间:2018-03-08 22:08:07

标签: graphql babel apollo apollo-client

我正在尝试关注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"
  ]
}

我的项目只是一个基本的webpack配置和反应。我尝试过对我的npm软件包进行重复数据删除,并检查了我的项目中是否存在有冲突的graphql版本,但没有成功。我最好的猜测是graphql-tag没有正常工作,我的查询没有被翻译成请求的相应语法。感觉我错过了一些非常基本的东西。我非常感谢任何澄清。谢谢!

1 个答案:

答案 0 :(得分:1)

对于您的客户端配置而言,这看起来不像启动板的错误。如果您访问该端点的GraphiQL接口并尝试运行查询,它将抛出相同的错误。

如果您使用Github帐户登录Launchpad,则可以启动一个新的pad(与其相同),保存,然后在项目中使用该URL。

相关问题