Uncaught Invariant Violation: query option is required. You must specify your GraphQL document in the query option
Solution 1:
Have you tried importing the query directly? e.g.
import { GET_ALL_COUNTRIES } from "./gqlQueries";
const getAllCountries = () => {
client
.query({
query: GET_ALL_COUNTRIES
})
.then((res) => {
console.log(res.data);
})
.catch((err) => console.log(err));
};
I had a similar issue and it was the syntax within the .query method. Not sure if the way you're importing it is causing an issue (although maybe not if you've done the same for your other queries).
Solution 2:
I think the problem is the gql here:
.query({
query: gql.GET_ALL_COUNTRIES
})
It should be like this:
.query({
query: GET_ALL_COUNTRIES
})
gql is already inside the const:
export const GET_ALL_COUNTRIES = gql`
query getAllCountry {
getAllCountry {
name
id
countryCode
currencyCode
}
}`;