0

Here is my schema.graphqls

type Query {
    products (
        special_code: String @doc(description: "special code")
    ): Products
}

interface ProductInterface {
    addl_data: String @doc(description: "additonal data") @resolver(class: "Vendor\\Module\\Model\\Resolver\\Product\\AddlData")
}

On my resolver file

<?php
namespace Vendor\Module\Model\Resolver\Product;

use Magento\Catalog\Model\Product;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

class YourPrice implements ResolverInterface
{
    protected $_logger;

    public function __construct(
        \Psr\Log\LoggerInterface $logger,
    ) {
        $this->_logger = $logger;
    }

    /**
     * @inheritdoc
     */
    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {
        if (!isset($value['model'])) {
            throw new LocalizedException(__('"model" value should be specified'));
        }

        $this->_logger->debug("args: " . var_dump($args));
        $this->_logger->debug("special_code: " . $args['special_code']);
        return 'something test';
    }
}

However, $args is empty

[2022-03-29 09:38:56] main.DEBUG: args:  [] []
[2022-03-29 09:38:56] main.DEBUG: args:  [] []
[2022-03-29 09:38:56] main.DEBUG: args:  [] []
[2022-03-29 09:38:57] main.DEBUG: args:  [] []
[2022-03-29 09:38:57] main.DEBUG: args:  [] []
[2022-03-29 09:38:57] main.DEBUG: args:  [] []
[2022-03-29 09:38:57] main.ERROR: Notice: Undefined index: special_code in

How do I access my custom input argument and access it from my output custom field resolver?

4
  • Same issue I am facing for products query. Any help would be appreciated. Jun 2, 2022 at 8:08
  • @rainebow did you found any solution for this, I am facing same issue Jul 27, 2022 at 7:00
  • same problem.. any solution? Feb 20, 2023 at 14:06
  • @RanjitShinde Added answer below Mar 2, 2023 at 4:42

1 Answer 1

0
  1. Check the Interface custom attribute resolver code

  2. Check your code for any errors or missing code. Ensure that your resolver class implements the Magento\Framework\GraphQl\Query\ResolverInterface interface and that you have correctly defined the resolve method.

  3. Check the Interface custom attribute type code Ensure that you have properly defined the custom attribute type in your schema.xml file and that it is linked to the appropriate resolver. Also, check that the arguments are properly defined for the field in the schema file.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.