Skip to content

Commit b6af617

Browse files
authored
Merge pull request #6446 from magento-honey-badgers/issue-29302-graphql-schema-change
[HB]Issue 29302 graphql doesn't return type
2 parents c3b6f72 + 25f8a33 commit b6af617

File tree

15 files changed

+255
-58
lines changed

15 files changed

+255
-58
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Relation.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,19 @@ public function getRelationsByChildren(array $childrenIds): array
149149
$select = $connection->select()
150150
->from(
151151
['cpe' => $this->getTable('catalog_product_entity')],
152-
'entity_id'
152+
['relation.child_id', 'cpe.entity_id']
153153
)->join(
154154
['relation' => $this->getTable('catalog_product_relation')],
155155
'relation.parent_id = cpe.' . $linkField
156156
)->where('relation.child_id IN(?)', $childrenIds);
157157

158-
return $connection->fetchCol($select);
158+
$result = $connection->fetchAll($select);
159+
$parentIdsOfChildIds = [];
160+
161+
foreach ($result as $row) {
162+
$parentIdsOfChildIds[$row['child_id']][] = $row['entity_id'];
163+
}
164+
165+
return $parentIdsOfChildIds;
159166
}
160167
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Category;
9+
10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
11+
use Magento\Framework\GraphQl\Query\Uid;
12+
use Magento\Framework\GraphQl\Query\Resolver\ArgumentsProcessorInterface;
13+
14+
/**
15+
* Parent Category UID processor class for category uid and category id arguments
16+
*/
17+
class ParentCategoryUidsArgsProcessor implements ArgumentsProcessorInterface
18+
{
19+
private const ID = 'parent_id';
20+
21+
private const UID = 'parent_category_uid';
22+
23+
/** @var Uid */
24+
private $uidEncoder;
25+
26+
/**
27+
* @param Uid $uidEncoder
28+
*/
29+
public function __construct(Uid $uidEncoder)
30+
{
31+
$this->uidEncoder = $uidEncoder;
32+
}
33+
34+
/**
35+
* Composite processor that loops through available processors for arguments that come from graphql input
36+
*
37+
* @param string $fieldName,
38+
* @param array $args
39+
* @return array
40+
* @throws GraphQlInputException
41+
*/
42+
public function process(
43+
string $fieldName,
44+
array $args
45+
): array {
46+
$filterKey = 'filters';
47+
$parentUidFilter = $args[$filterKey][self::UID] ?? [];
48+
$parentIdFilter = $args[$filterKey][self::ID] ?? [];
49+
if (!empty($parentIdFilter)
50+
&& !empty($parentUidFilter)
51+
&& ($fieldName === 'categories' || $fieldName === 'categoryList')) {
52+
throw new GraphQlInputException(
53+
__('`%1` and `%2` can\'t be used at the same time.', [self::ID, self::UID])
54+
);
55+
} elseif (!empty($parentUidFilter)) {
56+
if (isset($parentUidFilter['eq'])) {
57+
$args[$filterKey][self::ID]['eq'] = $this->uidEncoder->decode(
58+
$parentUidFilter['eq']
59+
);
60+
} elseif (!empty($parentUidFilter['in'])) {
61+
foreach ($parentUidFilter['in'] as $parentUids) {
62+
$args[$filterKey][self::ID]['in'][] = $this->uidEncoder->decode($parentUids);
63+
}
64+
}
65+
unset($args[$filterKey][self::UID]);
66+
}
67+
return $args;
68+
}
69+
}

app/code/Magento/CatalogGraphQl/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<argument name="processors" xsi:type="array">
7373
<item name="category_uid" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\Query\CategoryUidArgsProcessor</item>
7474
<item name="category_uids" xsi:type="object">Magento\CatalogGraphQl\Model\Category\CategoryUidsArgsProcessor</item>
75+
<item name="parent_category_uids" xsi:type="object">Magento\CatalogGraphQl\Model\Category\ParentCategoryUidsArgsProcessor</item>
7576
</argument>
7677
</arguments>
7778
</type>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ input CategoryFilterInput @doc(description: "CategoryFilterInput defines the fi
332332
{
333333
ids: FilterEqualTypeInput @deprecated(reason: "Use the `category_uid` argument instead.") @doc(description: "Deprecated: use 'category_uid' to filter uniquely identifiers of categories.")
334334
category_uid: FilterEqualTypeInput @doc(description: "Filter by the unique category ID for a `CategoryInterface` object.")
335-
parent_id: FilterEqualTypeInput @doc(description: "Filter by the unique parent category ID for a `CategoryInterface` object.")
335+
parent_id: FilterEqualTypeInput @deprecated @doc(description: "Filter by the unique parent category ID for a `CategoryInterface` object.")
336+
parent_category_uid: FilterEqualTypeInput @doc(description: "Filter by the unique parent category ID for a `CategoryInterface` object.")
336337
url_key: FilterEqualTypeInput @doc(description: "Filter by the part of the URL that identifies the category.")
337338
name: FilterMatchTypeInput @doc(description: "Filter by the display name of the category.")
338339
url_path: FilterEqualTypeInput @doc(description: "Filter by the URL path for the category.")

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/OptionsSelectionMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4040
throw new LocalizedException(__('"model" value should be specified'));
4141
}
4242

43-
$selectedOptions = $args['selectedConfigurableOptionValues'] ?? [];
43+
$selectedOptions = $args['configurableOptionValueUids'] ?? [];
4444
/** @var ProductInterface $product */
4545
$product = $value['model'];
4646

app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/SelectionMediaGallery.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
3030
foreach ($usedProducts as $usedProduct) {
3131
if (in_array($usedProduct->getId(), $availableSelectionProducts)) {
3232
foreach ($usedProduct->getMediaGalleryEntries() ?? [] as $key => $entry) {
33-
$index = $usedProduct->getId() . '_' . $key;
34-
$mediaGalleryEntries[$index] = $entry->getData();
33+
$entryData = $entry->getData();
34+
$initialIndex = $usedProduct->getId() . '_' . $key;
35+
$index = $this->prepareIndex($entryData, $initialIndex);
36+
$mediaGalleryEntries[$index] = $entryData;
3537
$mediaGalleryEntries[$index]['model'] = $usedProduct;
3638
if ($entry->getExtensionAttributes() && $entry->getExtensionAttributes()->getVideoContent()) {
3739
$mediaGalleryEntries[$index]['video_content']
@@ -42,4 +44,26 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4244
}
4345
return $mediaGalleryEntries;
4446
}
47+
48+
/**
49+
* Formulate an index to have unique set of media entries
50+
*
51+
* @param array $entryData
52+
* @param string $initialIndex
53+
* @return string
54+
*/
55+
private function prepareIndex(array $entryData, string $initialIndex) : string
56+
{
57+
$index = $initialIndex;
58+
if (isset($entryData['media_type'])) {
59+
$index = $entryData['media_type'];
60+
}
61+
if (isset($entryData['file'])) {
62+
$index = $index.'_'.$entryData['file'];
63+
}
64+
if (isset($entryData['position'])) {
65+
$index = $index.'_'.$entryData['position'];
66+
}
67+
return $index;
68+
}
4569
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Mutation {
77
type ConfigurableProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "ConfigurableProduct defines basic features of a configurable product and its simple product variants") {
88
variants: [ConfigurableVariant] @doc(description: "An array of variants of products") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\ConfigurableVariant")
99
configurable_options: [ConfigurableProductOptions] @doc(description: "An array of linked simple product items") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\Options")
10-
configurable_options_selection_metadata(selectedConfigurableOptionValues: [ID!]): ConfigurableOptionsSelectionMetadata @doc(description: "Metadata for the specified configurable options selection") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\OptionsSelectionMetadata")
10+
configurable_product_options_selection(configurableOptionValueUids: [ID!]): ConfigurableProductOptionsSelection @doc(description: "Metadata for the specified configurable options selection") @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\OptionsSelectionMetadata")
1111
}
1212

1313
type ConfigurableVariant @doc(description: "An array containing all the simple product variants of a configurable product") {
@@ -80,7 +80,7 @@ type ConfigurableWishlistItem implements WishlistItemInterface @doc(description:
8080
configurable_options: [SelectedConfigurableOption!] @resolver(class: "\\Magento\\ConfigurableProductGraphQl\\Model\\Wishlist\\ConfigurableOptions") @doc (description: "An array of selected configurable options")
8181
}
8282

83-
type ConfigurableOptionsSelectionMetadata @doc(description: "Metadata corresponding to the configurable options selection.") {
83+
type ConfigurableProductOptionsSelection @doc(description: "Metadata corresponding to the configurable options selection.") {
8484
options_available_for_selection: [ConfigurableOptionAvailableForSelection!] @doc(description: "Configurable options available for further selection based on current selection.")
8585
media_gallery: [MediaGalleryInterface!] @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\SelectionMediaGallery") @doc(description: "Product images and videos corresponding to the specified configurable options selection.")
8686
variant: SimpleProduct @resolver(class: "Magento\\ConfigurableProductGraphQl\\Model\\Resolver\\Variant\\Variant") @doc(description: "Variant represented by the specified configurable options selection. It is expected to be null, until selections are made for each configurable option.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type AddDownloadableProductsToCartOutput {
2525
}
2626

2727
type DownloadableCartItem implements CartItemInterface @doc(description: "Downloadable Cart Item") {
28-
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
28+
customizable_options: [SelectedCustomizableOption]! @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
2929
links: [DownloadableProductLinks] @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\DownloadableCartItem\\Links") @doc(description: "An array containing information about the links for the added to cart downloadable product")
3030
samples: [DownloadableProductSamples] @resolver(class: "Magento\\DownloadableGraphQl\\Resolver\\DownloadableCartItem\\Samples") @doc(description: "DownloadableProductSamples defines characteristics of a downloadable product")
3131
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ type SetGuestEmailOnCartOutput {
322322
}
323323

324324
type SimpleCartItem implements CartItemInterface @doc(description: "Simple Cart Item") {
325-
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
325+
customizable_options: [SelectedCustomizableOption]! @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
326326
}
327327

328328
type VirtualCartItem implements CartItemInterface @doc(description: "Virtual Cart Item") {
329-
customizable_options: [SelectedCustomizableOption] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
329+
customizable_options: [SelectedCustomizableOption]! @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CustomizableOptions")
330330
}
331331

332332
interface CartItemInterface @typeResolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\CartItemTypeResolver") {
@@ -354,6 +354,7 @@ type SelectedCustomizableOption {
354354
id: Int! @deprecated(reason: "Use SelectedCustomizableOption.customizable_option_uid instead")
355355
customizable_option_uid: ID! @doc(description: "The unique ID for a `CustomizableRadioOption`, `CustomizableDropDownOption`, `CustomizableMultipleOption`, etc. of `CustomizableOptionInterface` objects")
356356
label: String!
357+
type: String!
357358
is_required: Boolean!
358359
values: [SelectedCustomizableOptionValue!]!
359360
sort_order: Int!

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface WishlistItemInterface @typeResolver(class: "Magento\\WishlistGraphQl\\
4040
description: String @doc(description: "The description of the item")
4141
added_at: String! @doc(description: "The date and time the item was added to the wish list")
4242
product: ProductInterface @doc(description: "Product details of the wish list item") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\ProductResolver")
43-
customizable_options: [SelectedCustomizableOption] @doc(description: "Custom options selected for the wish list item")
43+
customizable_options: [SelectedCustomizableOption]! @doc(description: "Custom options selected for the wish list item")
4444
}
4545

4646
type WishlistItems {

0 commit comments

Comments
 (0)