我正在尝试从我的react应用程序中的 graphql
服务器获取国家/地区列表。 getAllCountry
查询在操场上运行良好,但每当我在应用程序上调用相同的查询时,我都会收到以下错误:
- “查询选项是必需的。您必须在查询选项中指定您的 GraphQL 文档”(屏幕上看到的错误),
2.“未捕获的不变违规:需要查询选项。您必须在查询选项中指定您的 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));
};
我非常确定我的客户端配置正确,因为我的 gqlQueries.js
文件中有其他查询,除了这个特定的查询( getAllCountry
)之外,它们都可以正常工作。
我认为问题在这里是GQL:
应该这样:
GQL已经在const中: