Closed waynekhalifa closed 2 years ago
These come from headless cms plugin. Please ensure the this plugin is active
i am having this issue after just pulling this down i have headless plugin activated
me too
Hi @imranhsayed I am also having this issue. I've deactivated all plugins and reactivated Headless CMS first. I've activated WPGraphQL then WooGraphQL then Headless CMS, and still, nothing works. Any ideas?
EDIT: The issue was that the latest Headless CMS plugin release in the Wordpress repository is v1.2.0 whereas the latest release on GitHub is v1.7.0. Updating to 1.7.0 downloaded from GitHub solved the issue!
Update wp graphql, and woographql both of them to the latest version
Sent from my iPhone
On 12 Oct 2021, at 10:10 PM, Travis @.***> wrote:
Hi @imranhsayed I am also having this issue. I've deactivated all plugins and reactivated Headless CMS first. I've activated WPGraphQL then WooGraphQL then Headless CMS, and still, nothing works. Any ideas?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
For anyone else who is continuing to see Cannot query field "wooCountries" on type "RootQuery".
or similar error messages from the checkout page on the demo site — I found the following workaround helpful because it appears that the "headless-cms" plugin doesn't seem to work with WordPress 5.9
. To resolve those query fields, just drop this at the end of your functions.php
file and that should do the trick:
function get_formatted_countries($countries)
{
$formatted_countries = [];
if (empty($countries) && !is_array($countries)) {
return $formatted_countries;
}
foreach ($countries as $countryCode => $countryName) {
array_push($formatted_countries, [
'countryCode' => $countryCode,
'countryName' => $countryName,
]);
}
return $formatted_countries;
}
register_graphql_object_type('WooCountry', [
'fields' => [
'countryCode' => ['type' => 'String'],
'countryName' => ['type' => 'String'],
]
]);
register_graphql_object_type('WooCountries', [
'description' => __('Countries Type', 'headless-cms'),
'fields' => [
'billingCountries' => [
'type' => [
'list_of' => 'WooCountry'
]
],
'shippingCountries' => [
'type' => [
'list_of' => 'WooCountry'
]
],
],
]);
register_graphql_field(
'RootQuery',
'wooCountries',
[
'description' => __('Countries', 'headless-cms'),
'type' => 'WooCountries',
'resolve' => function () {
// All countries for billing.
$all_countries = class_exists('WooCommerce') ? WC()->countries : [];
$billing_countries = !empty($all_countries->countries) ? $all_countries->countries : [];
$billing_countries = get_formatted_countries($billing_countries);
// All countries with states for shipping.
$shipping_countries = class_exists('WooCommerce') ? WC()->countries->get_shipping_countries() : [];;
$shipping_countries = !empty($shipping_countries) ? $shipping_countries : [];
$shipping_countries = get_formatted_countries($shipping_countries);
/**
* Here you need to return data that matches the shape of the "WooCountries" type. You could get
* the data from the WP Database, an external API, or static values.
* For example in this case we are getting it from WordPress database.
*/
return [
'billingCountries' => $billing_countries,
'shippingCountries' => $shipping_countries,
];
},
]
);
const GET_COUNTRIES = gql
query GET_COUNTRIES{ wooCountries { billingCountries { countryCode countryName } shippingCountries { countryCode countryName } } }`Server Error Error: Cannot query field "wooCountries" on type "RootQuery".