【发布时间】:2018-08-17 09:47:03
【问题描述】:
我正在尝试关注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 无法正常工作,并且我的查询没有被转换为请求的适当语法。感觉就像我错过了一些非常基本的东西。我将不胜感激任何澄清。谢谢!
【问题讨论】:
-
奇怪...因为 the default template 工作得很好,而你的和你的一样...
-
我想知道我的项目中是否还有其他东西,但我的配置是超级香草......
标签: graphql babeljs apollo apollo-client