0

In a custom module in etc/schema.graphqls, I declared my query :

type Query { getAvailableCountries: [Country!] @resolver(class: "\\Vendor\\Module\\Model\\Resolver\\getAvailableCountries") @doc(description: "Get list of country allowed on magento's side.") } 

There is my resolver code :

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { $allowedCountries = $this->scopeConfig->getValue( AllowedCountries::ALLOWED_COUNTRIES_PATH ); if (empty($allowedCountries)) { return []; } $allowedCountries = explode(",", $allowedCountries); $return = []; foreach ($allowedCountries as $countryCode) { $return[] = [ "two_letter_abbreviation" => $countryCode, "full_name_english" => $this->translate->getCountryTranslation($countryCode, "en_US") ]; } return $return; } 

In the schema.graphql generated I have : getAvailableCountries: [Country] Why is the ! not kept ?

I also tried [Country!]! and it's becoming [Country]!

Is there a way to force it to be : [Country!] the type Country is coming from Magento_DirectoryGraphQl but i also tried to declare my own type with only the two field i want and it's the same, the ! is still removed

3
  • why need custom graphQL ? you can use query Countries { countries { full_name_english two_letter_abbreviation } } Commented Jan 21 at 12:41
  • For me this query is return all country, and i need only the ones chosen in config AllowedCountries::ALLOWED_COUNTRIES_PATH Commented Jan 22 at 13:10
  • it will only return allowed country.. I just ran query..as per doc The countries query returns all countries in which the entity can do business. developer.adobe.com/commerce/webapi/graphql/schema/store/… Commented Jan 23 at 3:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.