Skip to content

Commit

Permalink
global extend uniq params
Browse files Browse the repository at this point in the history
  • Loading branch information
Isigar committed Jul 17, 2018
1 parent b48d10a commit 7cc2f01
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
17 changes: 16 additions & 1 deletion DI/GraphQLExtension.php
Expand Up @@ -25,7 +25,8 @@ class GraphQLExtension extends CompilerExtension
'url' => '',
'auth' => '',
'autoAuth' => true,
'sections' => []
'sections' => [],
'uniqParams' => []
];

private $sections = [];
Expand All @@ -39,6 +40,13 @@ public function loadConfiguration()
$builder->addDefinition($this->prefix("request"))
->setFactory(MainRequest::class,[$this->makeUrl($config),$this->makeAuthUrl($config),"@session"])
->addSetup("setAutoAuth",[$config["autoAuth"]]);

if(isset($config["uniqParams"])){
if(!empty($config["uniqParams"])){
$builder->getDefinition($this->prefix("request"))
->addSetup("extendUniqParams",[$config["uniqParams"]]);
}
}
$this->createSectionsConnection($builder,$config);
parent::loadConfiguration();
}
Expand All @@ -62,6 +70,13 @@ public function createSectionsConnection($builder,$config){
->setFactory("Relisoft\GraphQL\Request\\".$className,[$this->makeUrl($values),$this->makeAuthUrl($values),"@session"])
->addSetup("setAutoAuth",[$values["autoAuth"]]);

if(isset($config["uniqParams"])){
if(!empty($config["uniqParams"])){
$builder->getDefinition($this->prefix("section.".$key))
->addSetup("extendUniqParams",[$config["uniqParams"]]);
}
}

$this->sections[] = "graphql.section.".$key;

}
Expand Down
2 changes: 2 additions & 0 deletions parser/Parser.php
Expand Up @@ -11,6 +11,7 @@

use Latte\Engine;
use Relisoft\GraphQL\DI\GraphQLException;
use Tracy\Debugger;

class Parser
{
Expand All @@ -26,6 +27,7 @@ class Parser

public function __construct($type = self::UNIVERSAL_GETTER,$body = [])
{
Debugger::barDump($this->customUniqParams);
$this->body = $body;
switch ($type){
case self::UNIVERSAL_GETTER:
Expand Down
18 changes: 18 additions & 0 deletions request/Request.php
Expand Up @@ -73,6 +73,7 @@ public function auth($parserType = Parser::UNIVERSAL_QUERY){
];
$parser = new Parser($parserType,$body);
if(!empty($this->uniqParams)){

$parser->setCustomUniqParams($this->uniqParams);
}
$rendered = $parser->render();
Expand Down Expand Up @@ -135,6 +136,7 @@ public function call($query, $variables = [], $parserType){
$parser->setCustomUniqParams($this->uniqParams);
}
$rendered = $parser->render();
Debugger::barDump($rendered);
try{
$response = $this->client->raw($rendered,$variables,$this->headers());
$body = $response->getBody()->getContents();
Expand Down Expand Up @@ -260,6 +262,22 @@ public function extendUniqParams(array $params){
$this->uniqParams = $params;
}

/**
* @return array
*/
public function getUniqParams(): array
{
return $this->uniqParams;
}

/**
* @param array $uniqParams
*/
public function setUniqParams(array $uniqParams): void
{
$this->uniqParams = $uniqParams;
}

public function setAutoAuth($param){
$this->autoAuth = $param;
}
Expand Down

0 comments on commit 7cc2f01

Please sign in to comment.