小编kad*_*det的帖子

未捕获的不变违规:需要查询选项。您必须在查询选项中指定您的 GraphQL 文档

我正在尝试从我的反应应用程序中的服务器获取国家/地区列表graphql。该getAllCountry查询在操场上运行良好,但每当我在应用程序上调用相同的查询时,我都会收到以下错误

  1. “需要查询选项。您必须在查询选项中指定您的 GraphQL 文档”(屏幕上显示错误),
  1. “未捕获的不变违规:需要查询选项。您必须在查询选项中指定您的 GraphQL 文档。” (控制台错误)

我的代码如下所示:

// gql query inside gqlQueries.js

export const GET_ALL_COUNTRIES = gql`
  query getAllCountry {
    getAllCountry {
      name
      id
      countryCode
      currencyCode
    }
  }
`;

// calling the query

 import { queries as gql } from "./gqlQueries";

 const getAllCountries = () => {
    client
      .query({
        query: gql.GET_ALL_COUNTRIES
      })
      .then((res) => {
        console.log(res.data);
      })
      .catch((err) => console.log(err));
  };

Run Code Online (Sandbox Code Playgroud)

我非常确定我的客户端配置正确,因为我的gqlQueries.js文件中有其他查询,并且除了这个特定的查询 ( getAllCountry) 之外,它们都工作正常。

apollo reactjs graphql react-apollo apollo-client

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

apollo ×1

apollo-client ×1

graphql ×1

react-apollo ×1

reactjs ×1