2

I'm trying to run this Graphql url https://****.***.com/in/graphql by Postman

I saw in Magento document that the URL above can contain Store header https://devdocs.magento.com/guides/v2.4/graphql/send-request.html

But when I check the header it does not contain Store attribute. And I have to add it manually.

enter image description here

How can I add Store attribute to the Header request programmatically or change the URL to get the store_code automatically?

Note*: all ticked fields are automatically added by default.

1 Answer 1

1

Header Key and Value graphql query postman

// enter header key as 'Store' and value as store code e.g in
Store - in

// enter header key as 'content-currency' and value as store code e.g AED
content-currency - AED
<?php

declare(strict_types=1);

namespace Vendor\Module\Model\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

class ExampleClass implements ResolverInterface
{
    /**
     * @inheritdoc
     */
    public function resolve(
        Field $field,
        $context,
        ResolveInfo $info,
        array $value = null,
        array $args = null
    ) {
        // get store and currency from graphql
        $store = $context->getExtensionAttributes()->getStore();
        $currency = $store->getCurrentCurrencyCode();
        $store = $store->getCode();

        $data = $offer->getData();
        $data['model'] = $offer;

        return ['offer' => 'test data'];
    }
}

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.