Last active
June 18, 2020 12:48
-
-
Save roma-glushko/9f8c7196cbcdb2aca16ad18bd15a76a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__ . "/app/bootstrap.php"; | |
use Magento\Framework\App\Bootstrap; | |
use Magento\Framework\App\ObjectManager\ConfigLoader; | |
use GuzzleHttp\Client; | |
use Magento\Framework\Stdlib\ArrayManager; | |
$bootstrap = Bootstrap::create(BP, $_SERVER); | |
$objectManager = $bootstrap->getObjectManager(); | |
/** Configure the Object Manager **/ | |
$configurations = $objectManager->get(ConfigLoader::class)->load('global'); | |
$objectManager->configure($configurations); | |
/** @var ArrayManager $arrayManager */ | |
$arrayManager = $objectManager->get(ArrayManager::class); | |
// PoC starts here | |
$queryString = "query{ | |
cmsBlocks(identifiers: [\"my-block\"]){ | |
items { | |
title | |
identifier | |
content | |
} | |
} | |
}"; | |
$client = new Client([ | |
'base_uri' => 'https://www.magento2-store.com', | |
'headers' => ['Content-Type' => 'application/json'], | |
]); | |
$result = $client->post('graphql', ['json' => [ | |
'query' => $queryString, | |
]]); | |
$graphQlResponse = json_decode($result->getBody(), true); | |
$cmsBlocks = $arrayManager->get('data/cmsBlocks/items', $graphQlResponse); | |
var_dump($cmsBlocks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment