Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
GraphQL-526: Cannot return null for non-nullable field AvailableShipp…
Browse files Browse the repository at this point in the history
…ingMethod.method_code when no shipping methods are available
  • Loading branch information
naydav committed Apr 23, 2019
1 parent 3b48e1d commit cf46fef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\Data\ShippingMethodInterface;
Expand Down Expand Up @@ -66,19 +65,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$shippingRates = $address->getGroupedAllShippingRates();
foreach ($shippingRates as $carrierRates) {
foreach ($carrierRates as $rate) {
$method = $this->dataObjectConverter->toFlatArray(
$methods[] = $this->dataObjectConverter->toFlatArray(
$this->shippingMethodConverter->modelToDataObject($rate, $cart->getQuoteCurrencyCode()),
[],
ShippingMethodInterface::class
);
if ($method['available'] && $method['error_message'] === "") {
$methods[] = $method;
}
}
}
if (count($methods) === 0) {
throw new GraphQlNoSuchEntityException(__(' This shipping method is not available. To use this shipping method, please contact us.'));
}
return $methods;
}
}
7 changes: 4 additions & 3 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,14 @@ type SelectedShippingMethod {
type AvailableShippingMethod {
carrier_code: String!
carrier_title: String!
method_code: String!
method_title: String!
method_code: String @doc(description: "Could be null if method is not available")
method_title: String @doc(description: "Could be null if method is not available")
error_message: String
amount: Float!
base_amount: Float!
base_amount: Float @doc(description: "Could be null if method is not available")
price_excl_tax: Float!
price_incl_tax: Float!
available: Boolean!
}

type AvailablePaymentMethod {
Expand Down

0 comments on commit cf46fef

Please sign in to comment.