I'm trying to get a list of countries from a graphql
server in my react app. The getAllCountry
query works fine on playground but whenever I call the same query on the app, I get the following errors:
- "query option is required. You must specify your GraphQL document in the query option" (error as seen on screen),
- "Uncaught Invariant Violation: query option is required. You must specify your GraphQL document in the query option." (error on console)
Here's what my code looks like:
// 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));
};
I'm very sure my client is configured correctly because I have other queries in my gqlQueries.js
file and they all work fine except this particular one (getAllCountry
).
gql.
variable. Likeimport { GET_ALL_COUNTRIES as query } from ...
and use justquery
– Blest