Ошибка graphql пользовательского модуля Magento 2


У меня есть пользовательский модуль со схемой.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__
);

Схема.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
}

Когда я пытаюсь подключить свой сервер с расширением Altair, я получаю следующую ошибку

"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']
    ];
}

Что я сделал не так, пожалуйста, помогите

Author: Shafeel Sha, 2020-12-05

1 answers

Сохраняйте пространство между выводом списка сравнения и открывающей скобкой. теперь ваш тип вывода graphql выглядит как одно слово, если между ними нет пробела, компилятор graphql не может понять

wrong => CompareListOutput{

correct => CompareListOutput {

Перепишите, как показано ниже.

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

Надеюсь, это сработает.

 1
Author: Shafeel Sha, 2020-12-05 12:20:20