【问题标题】:Apollo Client query schema is not instance of GraphQLSchemaApollo 客户端查询模式不是 GraphQLSchema 的实例
【发布时间】: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


【解决方案1】:

这看起来不像是客户端配置的问题,更像是 Launchpad 的错误。如果您访问该端点的 GraphiQL 界面并尝试运行查询,则会引发相同的错误。

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

【讨论】:

  • 你摇滚。这完美地解决了这个问题。我已经把头发拉了几个小时了!!!
猜你喜欢
  • 2020-01-04
  • 2020-06-14
  • 2018-12-09
  • 2021-10-01
  • 2021-06-01
  • 2018-07-23
  • 2022-07-26
  • 2018-05-12
  • 2021-03-20
相关资源
最近更新 更多