From 885dec357eeeeb24c28f752f41cb52fa11e60f41 Mon Sep 17 00:00:00 2001 From: Haylan Date: Sat, 11 Jul 2026 16:46:11 +0200 Subject: [PATCH] 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. --- config/bundles.php | 2 - config/reference.php | 61 +------------------ src/Service/Provider/GitHubProvider.php | 28 +++------ .../Service/Provider/GitHubProviderTest.php | 16 ----- 4 files changed, 9 insertions(+), 98 deletions(-) diff --git a/config/bundles.php b/config/bundles.php index 80187e8..5b11b41 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -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], ]; diff --git a/config/reference.php b/config/reference.php index cd63856..3a03fa6 100644 --- a/config/reference.php +++ b/config/reference.php @@ -37,7 +37,7 @@ use Symfony\Component\Config\Loader\ParamConfigurator as Param; * @psalm-type ArgumentsType = list|array * @psalm-type CallType = array|array{0:string, 1?:ArgumentsType, 2?:bool}|array{method:string, arguments?:ArgumentsType, returns_clone?:bool} * @psalm-type TagsType = list>> // 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, * 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, - * allow_redirects?: mixed, - * auth?: mixed, - * query?: mixed, - * curl?: list, - * cert?: mixed, - * connect_timeout?: scalar|Param|null, - * debug?: bool|Param, - * decode_content?: mixed, - * delay?: float|Param, - * form_params?: array, - * multipart?: list, - * 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, - * }, - * version?: scalar|Param|null, - * }, - * plugin?: array, - * }>, - * 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, - * } * @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, * }, * ...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, [ diff --git a/tests/Unit/Service/Provider/GitHubProviderTest.php b/tests/Unit/Service/Provider/GitHubProviderTest.php index 0307a12..fbb1907 100644 --- a/tests/Unit/Service/Provider/GitHubProviderTest.php +++ b/tests/Unit/Service/Provider/GitHubProviderTest.php @@ -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),