Code style fixes
This commit is contained in:
parent
2f789cc4cf
commit
9ba1bd4c90
@ -293,74 +293,6 @@ abstract class APIRequestBuilder {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a GraphQL query and return the Request object
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param array $variables
|
|
||||||
* @return Request
|
|
||||||
*/
|
|
||||||
public function queryRequest(string $name, array $variables = []): Request
|
|
||||||
{
|
|
||||||
$file = realpath("{$this->filePath}/Queries/{$name}.graphql");
|
|
||||||
if ( ! file_exists($file))
|
|
||||||
{
|
|
||||||
throw new LogicException('GraphQL query file does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = file_get_contents($file);
|
|
||||||
$body = [
|
|
||||||
'query' => $query
|
|
||||||
];
|
|
||||||
|
|
||||||
if ( ! empty($variables))
|
|
||||||
{
|
|
||||||
$body['variables'] = [];
|
|
||||||
foreach($variables as $key => $val)
|
|
||||||
{
|
|
||||||
$body['variables'][$key] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->setUpRequest('POST', $this->baseUrl, [
|
|
||||||
'body' => $body,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a GraphQL mutation request, and return the Request object
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param array $variables
|
|
||||||
* @return Request
|
|
||||||
* @throws Throwable
|
|
||||||
*/
|
|
||||||
public function mutateRequest (string $name, array $variables = []): Request
|
|
||||||
{
|
|
||||||
$file = "{$this->filePath}/Mutations/{$name}.graphql";
|
|
||||||
if ( ! file_exists($file))
|
|
||||||
{
|
|
||||||
throw new LogicException('GraphQL mutation file does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = file_get_contents($file);
|
|
||||||
$body = [
|
|
||||||
'query' => $query
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!empty($variables)) {
|
|
||||||
$body['variables'] = [];
|
|
||||||
foreach ($variables as $key => $val)
|
|
||||||
{
|
|
||||||
$body['variables'][$key] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->setUpRequest('POST', $this->baseUrl, [
|
|
||||||
'body' => $body,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the full request url
|
* Create the full request url
|
||||||
*
|
*
|
||||||
|
@ -31,6 +31,7 @@ use const Aviat\AnimeClient\USER_AGENT;
|
|||||||
use Aviat\AnimeClient\API\APIRequestBuilder;
|
use Aviat\AnimeClient\API\APIRequestBuilder;
|
||||||
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
final class RequestBuilder extends APIRequestBuilder {
|
final class RequestBuilder extends APIRequestBuilder {
|
||||||
use ContainerAware;
|
use ContainerAware;
|
||||||
@ -117,7 +118,7 @@ final class RequestBuilder extends APIRequestBuilder {
|
|||||||
*/
|
*/
|
||||||
public function runQuery(string $name, array $variables = []): array
|
public function runQuery(string $name, array $variables = []): array
|
||||||
{
|
{
|
||||||
$file = realpath(__DIR__ . "/Queries/{$name}.graphql");
|
$file = __DIR__ . "/Queries/{$name}.graphql";
|
||||||
if ( ! file_exists($file))
|
if ( ! file_exists($file))
|
||||||
{
|
{
|
||||||
throw new LogicException('GraphQL query file does not exist.');
|
throw new LogicException('GraphQL query file does not exist.');
|
||||||
@ -150,7 +151,7 @@ final class RequestBuilder extends APIRequestBuilder {
|
|||||||
*/
|
*/
|
||||||
public function mutateRequest (string $name, array $variables = []): Request
|
public function mutateRequest (string $name, array $variables = []): Request
|
||||||
{
|
{
|
||||||
$file = realpath(__DIR__ . "/Mutations/{$name}.graphql");
|
$file = __DIR__ . "/Mutations/{$name}.graphql";
|
||||||
if ( ! file_exists($file))
|
if ( ! file_exists($file))
|
||||||
{
|
{
|
||||||
throw new LogicException('GraphQL mutation file does not exist.');
|
throw new LogicException('GraphQL mutation file does not exist.');
|
||||||
|
@ -200,6 +200,74 @@ final class RequestBuilder extends APIRequestBuilder {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a GraphQL query and return the Request object
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param array $variables
|
||||||
|
* @return Request
|
||||||
|
*/
|
||||||
|
public function queryRequest(string $name, array $variables = []): Request
|
||||||
|
{
|
||||||
|
$file = realpath("{$this->filePath}/Queries/{$name}.graphql");
|
||||||
|
if ( ! file_exists($file))
|
||||||
|
{
|
||||||
|
throw new LogicException('GraphQL query file does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = file_get_contents($file);
|
||||||
|
$body = [
|
||||||
|
'query' => $query
|
||||||
|
];
|
||||||
|
|
||||||
|
if ( ! empty($variables))
|
||||||
|
{
|
||||||
|
$body['variables'] = [];
|
||||||
|
foreach($variables as $key => $val)
|
||||||
|
{
|
||||||
|
$body['variables'][$key] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->setUpRequest('POST', $this->baseUrl, [
|
||||||
|
'body' => $body,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a GraphQL mutation request, and return the Request object
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param array $variables
|
||||||
|
* @return Request
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
public function mutateRequest (string $name, array $variables = []): Request
|
||||||
|
{
|
||||||
|
$file = "{$this->filePath}/Mutations/{$name}.graphql";
|
||||||
|
if ( ! file_exists($file))
|
||||||
|
{
|
||||||
|
throw new LogicException('GraphQL mutation file does not exist.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = file_get_contents($file);
|
||||||
|
$body = [
|
||||||
|
'query' => $query
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($variables)) {
|
||||||
|
$body['variables'] = [];
|
||||||
|
foreach ($variables as $key => $val)
|
||||||
|
{
|
||||||
|
$body['variables'][$key] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->setUpRequest('POST', $this->baseUrl, [
|
||||||
|
'body' => $body,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a request
|
* Make a request
|
||||||
*
|
*
|
||||||
|
@ -48,6 +48,11 @@ function loadConfig(string $path): array
|
|||||||
$output = [];
|
$output = [];
|
||||||
$files = glob("{$path}/*.toml");
|
$files = glob("{$path}/*.toml");
|
||||||
|
|
||||||
|
if ( ! is_array($files))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($files as $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
$key = str_replace('.toml', '', basename($file));
|
$key = str_replace('.toml', '', basename($file));
|
||||||
|
Loading…
Reference in New Issue
Block a user