Skip to content

Commit cf46fef

Browse files
committed
GraphQL-526: Cannot return null for non-nullable field AvailableShippingMethod.method_code when no shipping methods are available
1 parent 3b48e1d commit cf46fef

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddress/AvailableShippingMethods.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\GraphQl\Config\Element\Field;
13-
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
1514
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1615
use Magento\Quote\Api\Data\ShippingMethodInterface;
@@ -66,19 +65,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6665
$shippingRates = $address->getGroupedAllShippingRates();
6766
foreach ($shippingRates as $carrierRates) {
6867
foreach ($carrierRates as $rate) {
69-
$method = $this->dataObjectConverter->toFlatArray(
68+
$methods[] = $this->dataObjectConverter->toFlatArray(
7069
$this->shippingMethodConverter->modelToDataObject($rate, $cart->getQuoteCurrencyCode()),
7170
[],
7271
ShippingMethodInterface::class
7372
);
74-
if ($method['available'] && $method['error_message'] === "") {
75-
$methods[] = $method;
76-
}
7773
}
7874
}
79-
if (count($methods) === 0) {
80-
throw new GraphQlNoSuchEntityException(__(' This shipping method is not available. To use this shipping method, please contact us.'));
81-
}
8275
return $methods;
8376
}
8477
}

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,14 @@ type SelectedShippingMethod {
231231
type AvailableShippingMethod {
232232
carrier_code: String!
233233
carrier_title: String!
234-
method_code: String!
235-
method_title: String!
234+
method_code: String @doc(description: "Could be null if method is not available")
235+
method_title: String @doc(description: "Could be null if method is not available")
236236
error_message: String
237237
amount: Float!
238-
base_amount: Float!
238+
base_amount: Float @doc(description: "Could be null if method is not available")
239239
price_excl_tax: Float!
240240
price_incl_tax: Float!
241+
available: Boolean!
241242
}
242243

243244
type AvailablePaymentMethod {

0 commit comments

Comments
 (0)