I have sellerProducts
Query and SellerProducts
type has product interface. When i call SellerProducts query it returns configurable_options and variants are null for configurable products in custom product collection.
type Query {
sellerProducts(
input: SellerInput @doc(description: "Getting seller products details.")
): SellerProducts @resolver(class:"Custom\\MpGraphQl\\Model\\Resolver\\SellerProducts") @doc(description: "Return query of marketplace sellers products")
}
input SellerInput @doc(description: "Filters to fetch Seller") {
seller_id: String @doc(description: "Seller Id")
}
type SellerProducts @doc(description: "") {
details: [Details] @doc(description: "")
products: [ProductInterface]
}
Seller product resolver code.
$sellerProducts = $this->getSellerProducts($sellerId);
foreach ($sellerProducts as $product) {
$productData[] = [
'name' => $product->getName(),
'type_id' => $product->getTypeId(),
'sku' => $product->getSku(),
'url_key' => $product->getUrlKey(),
'model' => $product
];
}
return [
'products' => $productData,
];
public function getSellerProducts($sellerId)
{
$collection = $this->productCollectionFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('status', 1)
->addAttributeToFilter('visibility', ['in' => [2, 4]])
->addAttributeToSort('created_at', 'desc')
->addStoreFilter(1);
return $collection;
}
Graphql payload
{
sellerProducts(input: { seller_id: "115921" }) {
products {
name
sku
image {
url
label
}
... on ConfigurableProduct {
configurable_options {
id
attribute_id
label
position
use_default
attribute_code
values {
value_index
label
swatch_data{
value
}
}
product_id
}
variants {
product {
id
name
sku
attribute_set_id
... on PhysicalProductInterface {
weight
}
media_gallery{
url
position
}
price_range{
minimum_price{
regular_price{
value
currency
}
}
}
}
attributes {
uid
label
code
value_index
}
}
}
}
}
}
Response