Skip to content

Commit

Permalink
refactor(drupal9): Drop Drupal 9 support (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi authored May 8, 2024
1 parent e29468f commit 4e042b7
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 35 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.3', '7.4', '8.0', '8.1']
# Keep testing Drupal 9 untill 6 months after it got unsupported, so
# untill May 1st 2024.
drupal-core: ['9.5.x']
php-versions: ['8.1', '8.2']
drupal-core: ['10.2.x']
phpstan: ['0']
include:
# Extra runs to also test on latest Drupal 10.
# Extra run to test older supported Drupal 10.1.x.
- php-versions: '8.1'
drupal-core: '10.2.x'
phpstan: '0'
- php-versions: '8.2'
drupal-core: '10.2.x'
drupal-core: '10.1.x'
phpstan: '0'
# We only need to run PHPStan once on the latest PHP version.
- php-versions: '8.3'
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql_composable/graphql_composable.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ package: GraphQL
dependencies:
- graphql:graphql
- node:node
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^10.1
2 changes: 1 addition & 1 deletion examples/graphql_example/graphql_examples.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ package: GraphQL
dependencies:
- graphql:graphql
- node:node
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^10.1
2 changes: 1 addition & 1 deletion graphql.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ type: module
description: 'Base module for integrating GraphQL with Drupal.'
package: GraphQL
configure: graphql.config_page
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^10.1
dependencies:
- typed_data:typed_data
21 changes: 9 additions & 12 deletions src/GraphQL/Execution/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\graphql\GraphQL\Execution;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\CacheBackendInterface;
Expand All @@ -22,7 +23,6 @@
use GraphQL\Utils\AST;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Executes GraphQL queries with cache lookup.
Expand Down Expand Up @@ -51,11 +51,9 @@ class Executor implements ExecutorImplementation {
protected $contextsManager;

/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
* The date/time service.
*/
protected $requestStack;
protected TimeInterface $time;

/**
* The event dispatcher.
Expand Down Expand Up @@ -127,8 +125,8 @@ class Executor implements ExecutorImplementation {
* The cache contexts manager service.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
* The cache backend for caching query results.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The date/time service.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher.
* @param \GraphQL\Executor\Promise\PromiseAdapter $adapter
Expand All @@ -143,7 +141,7 @@ class Executor implements ExecutorImplementation {
public function __construct(
CacheContextsManager $contextsManager,
CacheBackendInterface $cacheBackend,
RequestStack $requestStack,
TimeInterface $time,
EventDispatcherInterface $dispatcher,
PromiseAdapter $adapter,
Schema $schema,
Expand All @@ -156,7 +154,7 @@ public function __construct(
) {
$this->contextsManager = $contextsManager;
$this->cacheBackend = $cacheBackend;
$this->requestStack = $requestStack;
$this->time = $time;
$this->dispatcher = $dispatcher;

$this->adapter = $adapter;
Expand Down Expand Up @@ -198,7 +196,7 @@ public static function create(
return new static(
$container->get('cache_contexts_manager'),
$container->get('cache.graphql.results'),
$container->get('request_stack'),
$container->get('datetime.time'),
$container->get('event_dispatcher'),
$adapter,
$schema,
Expand Down Expand Up @@ -444,8 +442,7 @@ protected function cacheWrite($prefix, CacheableExecutionResult $result) {
* @see \Drupal\Core\Cache\CacheBackendInterface::set()
*/
protected function maxAgeToExpire($maxAge) {
// @todo Can be removed when D9 support is dropped.
$time = $this->requestStack->getMainRequest()->server->get('REQUEST_TIME');
$time = $this->time->getRequestTime();
return ($maxAge === Cache::PERMANENT) ? Cache::PERMANENT : (int) $time + $maxAge;
}

Expand Down
8 changes: 4 additions & 4 deletions src/GraphQL/Utility/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
switch ($uploaded_file->getError()) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
// @todo Drupal 9 compatibility, needs to be converted to ByteSizeMarkup
// later.
// @todo Drupal 10.1 compatibility, needs to be converted to
// ByteSizeMarkup later.
// @phpstan-ignore-next-line
$maxUploadSize = format_size($this->getMaxUploadSize($settings));
$response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [
Expand Down Expand Up @@ -271,7 +271,7 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
$file->setSize(@filesize($temp_file_path));

// Validate against file_validate() first with the temporary path.
// @todo Drupal 9 compatibility, needs to be converted to file validate
// @todo Drupal 10.1 compatibility, needs to be converted to file validate
// service later.
// @phpstan-ignore-next-line
$errors = file_validate($file, $validators);
Expand Down Expand Up @@ -505,7 +505,7 @@ protected function prepareFilename(string $filename, array &$validators): string
/** @var \Drupal\file\FileInterface $file */
$file = $this->fileStorage->create([]);
$file->setFilename($filename);
// @todo Drupal 9 compatibility, needs to be converted to file
// @todo Drupal 10.1 compatibility, needs to be converted to file
// validator service later.
// @phpstan-ignore-next-line
$passes_validation = empty(file_validate_extensions($file, $validators['file_validate_extensions'][0]));
Expand Down
4 changes: 1 addition & 3 deletions src/Routing/QueryRouteEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ protected function assertValidPostRequestHeaders(Request $request) : void {
// Allow other origins as configured in the CORS policy.
if (!empty($this->corsOptions['enabled'])) {
$cors_service = new CorsService($this->corsOptions);
// Drupal 9 compatibility, method name has changed in Drupal 10.
// @phpstan-ignore-next-line
if ($cors_service->isActualRequestAllowed($request)) {
if ($cors_service->isOriginAllowed($request)) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/DataProducer/EntityDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ enum FieldTypes {
])
);

// @todo Different description between Drupal 9 and 10, can be removed when
// Drupal 9 support is dropped.
// @todo Different description between Drupal 10.1 and 10.2, can be removed
// when Drupal 10.1 support is dropped.
$this->fullDefinitionResult['entityDefinition']['fields'][11]['description'] =
$this->container->get('entity_field.manager')->getBaseFieldDefinitions('node')['created']->getDescription();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Kernel/DataProducer/EntityReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Drupal\node\Entity\NodeType;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;

// @todo Drupal 9 compatibility: use the deprecated trait for Drupal 9.
if (strpos(\Drupal::VERSION, '9') === 0) {
// @todo Drupal 10.1 compatibility: use the deprecated trait for Drupal 10.1.
if (strpos(\Drupal::VERSION, '10.1') === 0) {

/**
* Helper trait for compatibility with Drupal 9.
Expand Down

0 comments on commit 4e042b7

Please sign in to comment.