我正在尝试从我的反应应用程序中的服务器获取国家/地区列表graphql。该getAllCountry查询在操场上运行良好,但每当我在应用程序上调用相同的查询时,我都会收到以下错误:
- “需要查询选项。您必须在查询选项中指定您的 GraphQL 文档”(屏幕上显示错误),
- “未捕获的不变违规:需要查询选项。您必须在查询选项中指定您的 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) 之外,它们都工作正常。