Skip to content

Graphql returns empty array

I’m using graphql to get data to my PWA frontend project.Following is my schema.graphqls

type Query {
    comparelist: [ComparelistOutput]  @resolver(class: "NeoSolax\CompareList\Model\Resolver\ComparelistItemResolver")  @doc(description: "An array of items in the customer's compare list")
}

type ComparelistOutput {
    id:String
    sku:String
    url_key:String
}

ComparelistItemResolver.php

class ComparelistItemResolver implements ResolverInterface
{
     use NeoSolaxCompareListHelpergetCompareList;
        public function __construct(
            getCompareList $getCompareList,
        
        ) {
        
            $this->getCompareList = $getCompareList
    
        }
        public function resolve(
                Field $field,
                $context,
                ResolveInfo $info,
                array $value = null,
                array $args = null
            ) {
                /** @var ContextInterface $context */
                $customerId = $context->getUserId();
        
                $comparelistItems = $this->getCompareList->getCompareListItems($customerId)->getItems();
                $data = [];
                foreach ($comparelistItems as $comparelistItem) {
                    $itemProduct = $comparelistItem->getData();
                    $data[] = [
                        'id' => $itemProduct['product_id'],
                        'sku' => $itemProduct['sku'],
                        'url_key'=>$itemProduct['url_key']
                    ];
                }
                return $data;
        
            }
}

Following is how I get my data to pwa frontend

const {data,loading:comparelistLoading}=useQuery(getCustomerCompareList);

data gets a empty array comparelist.What is wrong with my code?Please help