1

I have a custom module with schema.graphqls

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="NeoSolax_CompareList" setup_version="0.0.3" >
        <sequence>
            <module name="Magento_GraphQl"/>
        </sequence>
    </module>
</config>

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'NeoSolax_CompareList',
    __DIR__
);

schema.graphqls

type Mutation {
    addProductToCompareList(input:compareListInput): CompareListOutput @resolver(class: "NeoSolax\\CompareList\\Model\\Resolver\\addToCompareList")@doc(description:"Add products to compare")
}

input compareListInput{
    productId:String
    customerId: String
}

type CompareListOutput{
    count:Int
    listUrl:String
    items:[CompareItem]
}
type CompareItem{
    id:String
    product_url:String
    name:String
    remove_url:String
    productScope:String
}

When I try to connect my backend with Altair extension I get the following error

"1 exception(s):\nException #0 (GraphQL\\Error\\Error): Type \"CompareListOutput\" not found in document.\n\nException #0 (GraphQL\\Error\\Error): Type \"CompareListOutput\" not found in document.\n<pre>#1 GraphQL\\Utils\\ASTDefinitionBuilder->internalBuildType() called at [vendor/webonyx/graphql-php/src/Utils/ASTDefinitionBuilder.php:189]\n#2 GraphQL\\Utils\\ASTDefinitionBuilder->buildType() called at [vendor/webonyx/graphql-php/src/Utils/ASTDefinitionBuilder.php:171]\n#3 GraphQL\\Utils\\ASTDefinitionBuilder->internalBuildWrappedType() called at [vendor/webonyx/graphql-php/src/Utils/ASTDefinitionBuilder.php:309]\n#4 GraphQL\\Utils\\ASTDefinitionBuilder->buildField() called at [vendor/webonyx/graphql-php/src/Utils/ASTDefinitionBuilder.php:297]\n#5 GraphQL\\Utils\\ASTDefinitionBuilder->GraphQL\\Utils\\{closure}() called at [vendor/webonyx/graphql-php/src/Utils/Utils.php:284]\n#6 GraphQL\\Utils\\Utils::keyValMap() called at [vendor/webonyx/graphql-php/src/Utils/ASTDefinitionBuilder.php:298]\n#7 GraphQL\\Utils\\ASTDefinitionBuilder->makeFieldDefMap() called at [vendor/webonyx/graphql-php/src/Utils/ASTDefinitionBuilder.php:279]\n#8 GraphQL\\Utils\\ASTDefinitionBuilder->GraphQL\\Utils\\{closure}() called at 

addToCompareList.php

public function resolve(
    Field $field,
    $context,
    ResolveInfo $info,
    array $value = null,
    array $args = null
) {
    /** @var ContextInterface $context */
    $productId = $args['productId'];

    if ($productId && ($this->_customerVisitor->getId() || $this->_customerSession->isLoggedIn())) {
        $storeId = $this->_storeManager->getStore()->getId();
        try {
            /** @var Product $product */
            $product = $this->productRepository->getById($productId, false, $storeId);
        } catch (NoSuchEntityException $e) {
            $product = null;
        }

        if ($product && $this->compareAvailability->isAvailableForCompare($product)) {
            $this->_catalogProductCompareList->addProduct($product);
        }

    }
    $compareList = $this->compareProducts->getSectionData();
    return [
        'items' => $compareList['items'],
        'count'=>$compareList['count'],
        'listUrl'=>$compareList['listUrl']
    ];
}

What have I done wrong please help

1 Answer 1

2

Keep Space between CompareListOutput and the opening bracket. now your output type graphql look like a single word, if there is no space between them cannot understand the graphql compiler

wrong => CompareListOutput{

correct => CompareListOutput {

Rewrite like below.

type CompareListOutput {
    count:Int
    listUrl:String
    items:[CompareItem]
}

Hope this works .

3
  • Oh thank you it helped me.Didn't think that the spaces matter Commented Dec 5, 2020 at 12:21
  • you are welcome brother. please upvote if it works Commented Dec 5, 2020 at 12:22
  • Can you answer this questions magento.stackexchange.com/questions/327639/… Commented Dec 9, 2020 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.