-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f108036
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "reach-digital/magento2-apollo-sandbox", | ||
"description": "Embeds Apollo Sandbox at /graphql-sandbox", | ||
"authors": [ | ||
{ | ||
"name": "Hans Nieser", | ||
"email": "hans@reachdigital.nl" | ||
} | ||
], | ||
"require": { | ||
"php": "~7.4.0||~8.1.0", | ||
"magento/product-community-edition": "^2.3" | ||
}, | ||
"type": "magento2-module", | ||
"autoload": { | ||
"files": [ | ||
"registration.php" | ||
], | ||
"psr-4": { | ||
"ReachDigital\\ApolloSandbox\\": "src/" | ||
} | ||
} | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register( | ||
ComponentRegistrar::MODULE, | ||
'ReachDigital_ApolloSandbox', | ||
__DIR__ . '/src' | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ReachDigital\ApolloSandbox\Controller\Index; | ||
|
||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\App\Action\HttpGetActionInterface; | ||
use Magento\Framework\Escaper; | ||
|
||
class Index extends Action implements HttpGetActionInterface | ||
{ | ||
private \Magento\Framework\Controller\Result\RawFactory $rawFactory; | ||
private \Magento\Framework\UrlInterface $urlBuilder; | ||
private Escaper $escaper; | ||
|
||
public function __construct( | ||
Context $context, | ||
\Magento\Framework\Controller\Result\RawFactory $rawFactory, | ||
\Magento\Framework\UrlInterface $urlBuilder, | ||
Escaper $escaper | ||
) { | ||
parent::__construct($context); | ||
$this->rawFactory = $rawFactory; | ||
$this->urlBuilder = $urlBuilder; | ||
$this->escaper = $escaper; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function execute() | ||
{ | ||
$rawResponse = $this->rawFactory->create(); | ||
$rawResponse->setContents($this->getEmbedScript()); | ||
return $rawResponse; | ||
} | ||
|
||
private function getEmbedScript(): string | ||
{ | ||
return '<body style="margin:0;padding:0;"> | ||
<div style="width: 100%; height: 100%;" id="embedded-sandbox"></div> | ||
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script> | ||
<script> | ||
new window.EmbeddedSandbox({ | ||
target: "#embedded-sandbox", | ||
initialEndpoint: "' . $this->escaper->escapeUrl($this->getGraphqlUrl()) . '" | ||
}); | ||
</script> | ||
</body>'; | ||
} | ||
|
||
private function getGraphqlUrl(): string | ||
{ | ||
return rtrim($this->urlBuilder->getBaseUrl(), '/') . '/graphql'; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd"> | ||
<policies> | ||
<policy id="script-src"> | ||
<values> | ||
<value id="apollo_sandbox_cdn" type="host">embeddable-sandbox.cdn.apollographql.com</value> | ||
</values> | ||
</policy> | ||
<policy id="frame-src"> | ||
<values> | ||
<value id="apollo_sandbox_embed" type="host">sandbox.embed.apollographql.com/</value> | ||
</values> | ||
</policy> | ||
</policies> | ||
</csp_whitelist> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> | ||
<router id="standard"> | ||
<route id="apollosandbox" frontName="graphql-sandbox"> | ||
<module name="ReachDigital_ApolloSandbox" /> | ||
</route> | ||
</router> | ||
</config> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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="ReachDigital_ApolloSandbox"> | ||
<sequence> | ||
<module name="Magento_GraphQl" /> | ||
</sequence> | ||
</module> | ||
</config> |