refactor(github): build GraphQL query without the client bundle
The eightpoints/guzzle-bundle and idci/graphql-client-bundle only existed to build one near-static query string, and the bundle's own HTTP transport was already bypassed in favor of Symfony HttpClient. Build the query with sprintf/json_encode instead, drop both bundles from config/bundles.php, and update the test double accordingly.
This commit is contained in:
@@ -3,6 +3,4 @@
|
||||
return [
|
||||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
|
||||
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
|
||||
EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle::class => ['all' => true],
|
||||
IDCI\Bundle\GraphQLClientBundle\IDCIGraphQLClientBundle::class => ['all' => true],
|
||||
];
|
||||
|
||||
+2
-59
@@ -37,7 +37,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||
* @psalm-type ArgumentsType = list<mixed>|array<string, mixed>
|
||||
* @psalm-type CallType = array<string, ArgumentsType>|array{0:string, 1?:ArgumentsType, 2?:bool}|array{method:string, arguments?:ArgumentsType, returns_clone?:bool}
|
||||
* @psalm-type TagsType = list<string|array<string, array<string, mixed>>> // arrays inside the list must have only one element, with the tag name as the key
|
||||
* @psalm-type CallbackType = string|array{0:string|ReferenceConfigurator,1:string}|\Closure|ReferenceConfigurator|ExpressionConfigurator
|
||||
* @psalm-type CallbackType = string|array{0:string|ReferenceConfigurator,1:string}|\Closure|ReferenceConfigurator
|
||||
* @psalm-type DeprecationType = array{package: string, version: string, message?: string}
|
||||
* @psalm-type DefaultsType = array{
|
||||
* public?: bool,
|
||||
@@ -302,7 +302,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||
* },
|
||||
* },
|
||||
* translator?: bool|array{ // Translator configuration
|
||||
* enabled?: bool|Param, // Default: true
|
||||
* enabled?: bool|Param, // Default: false
|
||||
* fallbacks?: string|list<scalar|Param|null>,
|
||||
* logging?: bool|Param, // Default: false
|
||||
* formatter?: scalar|Param|null, // Default: "translator.formatter.default"
|
||||
@@ -833,73 +833,18 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||
* },
|
||||
* }>,
|
||||
* }
|
||||
* @psalm-type EightPointsGuzzleConfig = array{
|
||||
* clients?: array<string, array{ // Default: []
|
||||
* class?: scalar|Param|null, // Default: "%eight_points_guzzle.http_client.class%"
|
||||
* base_url?: scalar|Param|null, // Default: null
|
||||
* lazy?: bool|Param, // Default: false
|
||||
* logging?: int|Param, // Default: null
|
||||
* handler?: scalar|Param|null, // Default: null
|
||||
* options?: array{
|
||||
* headers?: array<string, scalar|Param|null>,
|
||||
* allow_redirects?: mixed,
|
||||
* auth?: mixed,
|
||||
* query?: mixed,
|
||||
* curl?: list<scalar|Param|null>,
|
||||
* cert?: mixed,
|
||||
* connect_timeout?: scalar|Param|null,
|
||||
* debug?: bool|Param,
|
||||
* decode_content?: mixed,
|
||||
* delay?: float|Param,
|
||||
* form_params?: array<string, mixed>,
|
||||
* multipart?: list<mixed>,
|
||||
* sink?: scalar|Param|null,
|
||||
* http_errors?: bool|Param,
|
||||
* expect?: mixed,
|
||||
* ssl_key?: mixed,
|
||||
* force_ip_resolve?: mixed, // Default: null
|
||||
* stream?: bool|Param,
|
||||
* synchronous?: bool|Param,
|
||||
* read_timeout?: scalar|Param|null,
|
||||
* timeout?: scalar|Param|null,
|
||||
* verify?: mixed,
|
||||
* cookies?: bool|Param,
|
||||
* proxy?: string|array{
|
||||
* http?: scalar|Param|null,
|
||||
* https?: scalar|Param|null,
|
||||
* no?: list<scalar|Param|null>,
|
||||
* },
|
||||
* version?: scalar|Param|null,
|
||||
* },
|
||||
* plugin?: array<mixed>,
|
||||
* }>,
|
||||
* logging?: bool|Param, // Default: true
|
||||
* profiling?: bool|Param, // Default: true
|
||||
* slow_response_time?: int|Param, // Default: 0
|
||||
* }
|
||||
* @psalm-type IdciGraphqlClientConfig = array{
|
||||
* cache_enabled?: bool|Param, // Default: false
|
||||
* clients?: list<array{ // Default: []
|
||||
* http_client?: scalar|Param|null,
|
||||
* cache?: scalar|Param|null,
|
||||
* }>,
|
||||
* }
|
||||
* @psalm-type ConfigType = array{
|
||||
* imports?: ImportsConfig,
|
||||
* parameters?: ParametersConfig,
|
||||
* services?: ServicesConfig,
|
||||
* framework?: FrameworkConfig,
|
||||
* monolog?: MonologConfig,
|
||||
* eight_points_guzzle?: EightPointsGuzzleConfig,
|
||||
* idci_graphql_client?: IdciGraphqlClientConfig,
|
||||
* "when@dev"?: array{
|
||||
* imports?: ImportsConfig,
|
||||
* parameters?: ParametersConfig,
|
||||
* services?: ServicesConfig,
|
||||
* framework?: FrameworkConfig,
|
||||
* monolog?: MonologConfig,
|
||||
* eight_points_guzzle?: EightPointsGuzzleConfig,
|
||||
* idci_graphql_client?: IdciGraphqlClientConfig,
|
||||
* },
|
||||
* "when@prod"?: array{
|
||||
* imports?: ImportsConfig,
|
||||
@@ -907,8 +852,6 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param;
|
||||
* services?: ServicesConfig,
|
||||
* framework?: FrameworkConfig,
|
||||
* monolog?: MonologConfig,
|
||||
* eight_points_guzzle?: EightPointsGuzzleConfig,
|
||||
* idci_graphql_client?: IdciGraphqlClientConfig,
|
||||
* },
|
||||
* ...<string, ExtensionType|array{ // extra keys must follow the when@%env% pattern or match an extension alias
|
||||
* imports?: ImportsConfig,
|
||||
|
||||
@@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Provider;
|
||||
|
||||
use IDCI\Bundle\GraphQLClientBundle\Client\GraphQLApiClient;
|
||||
use IDCI\Bundle\GraphQLClientBundle\Client\GraphQLApiClientRegistryInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
@@ -24,7 +22,6 @@ final class GitHubProvider implements ProviderInterface
|
||||
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $client,
|
||||
private readonly GraphQLApiClientRegistryInterface $registry,
|
||||
private readonly string $username,
|
||||
private readonly string $token,
|
||||
private readonly LoggerInterface $logger,
|
||||
@@ -54,25 +51,14 @@ final class GitHubProvider implements ProviderInterface
|
||||
$from = (new \DateTimeImmutable('-365 days'))->format('Y-m-d\T00:00:00\Z');
|
||||
$to = (new \DateTimeImmutable())->format('Y-m-d\T23:59:59\Z');
|
||||
|
||||
/** @var GraphQLApiClient $graphqlClient */
|
||||
$graphqlClient = $this->registry->get('github');
|
||||
$query = sprintf(
|
||||
'query { user(login: %s) { contributionsCollection(from: %s, to: %s) { contributionCalendar { weeks { contributionDays { date contributionCount } } } } } }',
|
||||
json_encode($this->username),
|
||||
json_encode($from),
|
||||
json_encode($to),
|
||||
);
|
||||
|
||||
$query = $graphqlClient->buildQuery(
|
||||
['user' => ['login' => $this->username]],
|
||||
[
|
||||
'contributionsCollection' => [
|
||||
'_parameters' => ['from' => $from, 'to' => $to],
|
||||
'contributionCalendar' => [
|
||||
'weeks' => [
|
||||
'contributionDays' => ['date', 'contributionCount'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
)->getGraphQLQuery();
|
||||
|
||||
// GitHub's GraphQL API requires application/json — the bundle's built-in
|
||||
// transport sends form_params, so we use Symfony HttpClient here instead.
|
||||
// GitHub's GraphQL API requires application/json.
|
||||
// request() doesn't block; the response is read in resolveFetch() so
|
||||
// multiple providers' requests can be in flight at once.
|
||||
return $this->client->request('POST', self::GRAPHQL_URL, [
|
||||
|
||||
@@ -5,9 +5,6 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Unit\Service\Provider;
|
||||
|
||||
use App\Service\Provider\GitHubProvider;
|
||||
use IDCI\Bundle\GraphQLClientBundle\Client\GraphQLApiClient;
|
||||
use IDCI\Bundle\GraphQLClientBundle\Client\GraphQLApiClientRegistryInterface;
|
||||
use IDCI\Bundle\GraphQLClientBundle\Query\GraphQLQuery;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -23,22 +20,9 @@ final class GitHubProviderTest extends TestCase
|
||||
string $username = 'user',
|
||||
string $token = 'token',
|
||||
?HttpClientInterface $client = null,
|
||||
?GraphQLApiClientRegistryInterface $registry = null,
|
||||
): GitHubProvider {
|
||||
if ($registry === null) {
|
||||
$graphqlQuery = $this->createStub(GraphQLQuery::class);
|
||||
$graphqlQuery->method('getGraphQLQuery')->willReturn('query {}');
|
||||
|
||||
$graphqlClient = $this->createStub(GraphQLApiClient::class);
|
||||
$graphqlClient->method('buildQuery')->willReturn($graphqlQuery);
|
||||
|
||||
$registry = $this->createStub(GraphQLApiClientRegistryInterface::class);
|
||||
$registry->method('get')->willReturn($graphqlClient);
|
||||
}
|
||||
|
||||
return new GitHubProvider(
|
||||
$client ?? $this->createStub(HttpClientInterface::class),
|
||||
$registry,
|
||||
$username,
|
||||
$token,
|
||||
$this->createStub(LoggerInterface::class),
|
||||
|
||||
Reference in New Issue
Block a user