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.

Diana
5,3701 gold badge12 silver badges27 bronze badges
asked Jun 14, 2021 at 9:24

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'];
 }
}
answered Feb 5, 2024 at 5:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.