Skip to content

Commit

Permalink
Merge branch '8.x-4.x' into explorer-introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi authored Nov 11, 2023
2 parents 503358f + 6798e26 commit cf24a8b
Show file tree
Hide file tree
Showing 55 changed files with 1,304 additions and 239 deletions.
53 changes: 26 additions & 27 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
drupal:
name: Drupal ${{ matrix.drupal-core }} (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
env:
extensions: mbstring, xml, pdo_sqlite, gd, opcache
strategy:
Expand All @@ -19,11 +19,11 @@ jobs:
include:
# Extra runs to also test on latest Drupal 10.
- php-versions: '8.1'
drupal-core: '10.0.x'
drupal-core: '10.1.x'
phpstan: '0'
# We only need to run PHPStan once on the latest PHP version.
- php-versions: '8.2'
drupal-core: '10.0.x'
drupal-core: '10.1.x'
phpstan: '1'
steps:
- name: Checkout Drupal core
Expand Down Expand Up @@ -60,11 +60,12 @@ jobs:
php-version: ${{ matrix.php-versions }}
# Disable Xdebug for better performance.
coverage: none
ini-file: development
extensions: ${{ env.extensions }}

- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
Expand All @@ -82,25 +83,11 @@ jobs:
composer config --no-plugins allow-plugins.phpstan/extension-installer true
- name: Install GraphQL dependencies
run: composer --no-interaction --no-progress require \
webonyx/graphql-php:^14.8 \
drupal/typed_data:^1.0 \
drupal/redirect:^1.0 \
phpstan/phpstan:^1.7.14 \
mglaman/phpstan-drupal:^1.1.2 \
phpstan/phpstan-deprecation-rules:^1.0.0 \
jangregor/phpstan-prophecy:^1.0.0 \
phpstan/phpstan-phpunit:^1.0.0 \
phpstan/extension-installer:^1.0

# We install Coder separately because updating did not work in the local
# Drupal vendor dir.
- name: Install Coder
run: |
mkdir coder
cd coder
echo '{"config": {"allow-plugins": {"dealerdirect/phpcodesniffer-composer-installer": true}}}' > composer.json
composer require drupal/coder:8.3.15 --no-interaction --no-progress
composer --no-interaction --no-progress require \
webonyx/graphql-php:^14.8 \
drupal/typed_data:^1.0 \
drupal/redirect:^1.0
- name: Run PHPUnit
run: |
Expand All @@ -109,11 +96,23 @@ jobs:
env:
SIMPLETEST_DB: "sqlite://localhost/:memory:"

- name: Install PHPStan and Coder dependencies
if: ${{ matrix.phpstan == '1' }}
# Pin the exact Coder version to upgrade manually when we want to.
run: |
composer --no-interaction --no-progress require \
phpstan/phpstan:^1.10.38 \
mglaman/phpstan-drupal:^1.1.2 \
phpstan/phpstan-deprecation-rules:^1.0.0 \
jangregor/phpstan-prophecy:^1.0.0 \
phpstan/phpstan-phpunit:^1.0.0 \
phpstan/extension-installer:^1.0
composer --no-interaction --no-progress --with-all-dependencies upgrade drupal/coder:8.3.21
- name: Run PHPStan
# phpstan-drupal bug, so we remove 1 stub file
# https://github.com/mglaman/phpstan-drupal/issues/509
run: if [[ ${{ matrix.phpstan }} == "1" ]]; then rm vendor/mglaman/phpstan-drupal/stubs/Drupal/Core/Field/FieldItemList.stub && cd modules/graphql && ../../vendor/bin/phpstan analyse; fi
if: ${{ matrix.phpstan == '1' }}
run: cd modules/graphql && ../../vendor/bin/phpstan analyse

- name: Run PHPCS
run: |
cd modules/graphql && ../../coder/vendor/bin/phpcs -p
if: ${{ matrix.phpstan == '1' }}
run: cd modules/graphql && ../../vendor/bin/phpcs -p
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\graphql_composable\GraphQL\Response\ArticleResponse;
use Drupal\node\Entity\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;

/**
* Creates a new article entity.
Expand Down
2 changes: 1 addition & 1 deletion graphql.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ services:
# Upcasting for graphql query request parameters.
graphql.route_enhancer.query:
class: Drupal\graphql\Routing\QueryRouteEnhancer
arguments: ['@request_stack']
arguments: ['%cors.config%']
tags:
- { name: route_enhancer }

Expand Down
7 changes: 0 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,3 @@ parameters:
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removePersistedQueryInstance\\(\\) has no return type specified\\.$#"
count: 1
path: src/Entity/ServerInterface.php

# We already use the ProphecyTrait, so not sure why PHPStan complains about
# this?
- """
#^Call to deprecated method prophesize\\(\\) of class Drupal\\\\Tests\\\\graphql\\\\Kernel\\\\GraphQLTestBase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/4141$#
"""
8 changes: 4 additions & 4 deletions src/Entity/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\graphql\GraphQL\Execution\ExecutionResult as CacheableExecutionResult;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\PersistedQueryPluginInterface;
use GraphQL\Error\DebugFlag;
use GraphQL\Server\OperationParams;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use GraphQL\Server\ServerConfig;
use Drupal\graphql\GraphQL\ResolverRegistryInterface;
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
use Drupal\graphql\Plugin\PersistedQueryPluginInterface;
use Drupal\graphql\Plugin\SchemaPluginInterface;
use GraphQL\Error\DebugFlag;
use GraphQL\Error\Error;
use GraphQL\Error\FormattedError;
use GraphQL\Executor\Executor;
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
use GraphQL\Language\AST\DocumentNode;
use GraphQL\Server\Helper;
use GraphQL\Server\OperationParams;
use GraphQL\Server\ServerConfig;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Validator\DocumentValidator;
use GraphQL\Validator\Rules\DisableIntrospection;
Expand Down
2 changes: 1 addition & 1 deletion src/Event/OperationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Drupal\graphql\Event;

use Drupal\Component\EventDispatcher\Event;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use GraphQL\Executor\ExecutionResult;
use Drupal\Component\EventDispatcher\Event;

/**
* Represents an event that is triggered before and after a GraphQL operation.
Expand Down
2 changes: 1 addition & 1 deletion src/EventSubscriber/ApqSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\graphql\Event\OperationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use GraphQL\Error\Error;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Save persisted queries to cache.
Expand Down
17 changes: 14 additions & 3 deletions src/Form/ServerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
Expand Down Expand Up @@ -243,6 +244,19 @@ public function form(array $form, FormStateInterface $formState): array {
return $form;
}

/**
* {@inheritdoc}
*/
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state): void {
// Translate the debug flag from individual checkboxes to the enum value
// that the GraphQL library expects.
$debug_flag = $form_state->getValue('debug_flag');
if (is_array($debug_flag)) {
$form_state->setValue('debug_flag', array_sum($debug_flag));
}
parent::copyFormValuesToEntity($entity, $form, $form_state);
}

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -274,9 +288,6 @@ public function validateForm(array &$form, FormStateInterface $formState): void
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $formState): void {
// Translate the debug flag from individual checkboxes to the enum value
// that the GraphQL library expects.
$formState->setValue('debug_flag', array_sum($formState->getValue('debug_flag')));
parent::submitForm($form, $formState);

$schema = $formState->getValue('schema');
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/Execution/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Drupal\graphql\GraphQL\Execution;

use GraphQL\Executor\ExecutionResult as LibraryExecutionResult;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
use GraphQL\Executor\ExecutionResult as LibraryExecutionResult;

/**
* Expand the upstream ExecutionResult to make it Drupal cachable.
Expand Down
1 change: 1 addition & 0 deletions src/GraphQL/Execution/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ protected function cachePrefix() {
'query' => DocumentSerializer::serializeDocument($this->document),
'variables' => $variables,
'extensions' => $extensions,
'operation' => $this->operation,
]));

return $hash;
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/Resolver/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Drupal\graphql\GraphQL\Resolver;

use Drupal\graphql\GraphQL\Execution\FieldContext;
use GraphQL\Executor\Promise\Adapter\SyncPromise;
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
use GraphQL\Executor\Promise\Adapter\SyncPromise;
use GraphQL\Type\Definition\ResolveInfo;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/GraphQL/Resolver/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function __construct(array $branches) {
*/
public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
$branches = $this->branches;
while ([$condition, $resolver] = array_pad(array_shift($branches), 2, NULL)) {
while ($branch = array_shift($branches)) {
[$condition, $resolver] = array_pad($branch, 2, NULL);
if ($condition instanceof ResolverInterface) {
if (($condition = $condition->resolve($value, $args, $context, $info, $field)) === NULL) {
// Bail out early if a resolver returns NULL.
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/ResolverBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
use Drupal\graphql\GraphQL\Resolver\DefaultValue;
use Drupal\graphql\GraphQL\Resolver\Map;
use Drupal\graphql\GraphQL\Resolver\ParentValue;
use Drupal\graphql\GraphQL\Resolver\ResolverInterface;
use Drupal\graphql\GraphQL\Resolver\SourceContext;
use Drupal\graphql\GraphQL\Resolver\Tap;
use Drupal\graphql\GraphQL\Resolver\Value;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerProxy;
use Drupal\typed_data\DataFetcherTrait;
use Drupal\graphql\GraphQL\Resolver\ResolverInterface;

/**
* Wires and maps different resolvers together to build the GraphQL tree.
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/ResolverRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use Drupal\graphql\GraphQL\Resolver\ResolverInterface;
use GraphQL\Executor\Executor;
use GraphQL\Type\Definition\ImplementingType;
use GraphQL\Type\Definition\ResolveInfo;
use GraphQL\Type\Definition\Type;
use Drupal\graphql\GraphQL\Resolver\ResolverInterface;

/**
* Contains all the mappings how to resolve a GraphQL request.
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/Utility/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Component\Utility\Environment;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\File\Event\FileUploadSanitizeNameEvent;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Image\ImageFactory;
Expand All @@ -20,10 +21,9 @@
use Drupal\Core\Utility\Token;
use Drupal\file\FileInterface;
use Drupal\graphql\GraphQL\Response\FileUploadResponse;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Drupal\Core\File\Event\FileUploadSanitizeNameEvent;
use Symfony\Component\Mime\MimeTypeGuesserInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Service to manage file uploads within GraphQL mutations.
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/GraphQL/DataProducer/DataProducerPluginBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\DataProducerPluginInterface;
use Drupal\Core\Plugin\ContextAwarePluginTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\TypedData\TypedDataTrait;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\DataProducerPluginInterface;

/**
* Base class for data producers that resolve fields for queries or mutations.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/GraphQL/DataProducer/DataProducerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use Drupal\graphql\Plugin\DataProducerPluginCachingInterface;
use Drupal\graphql\Plugin\DataProducerPluginInterface;
use Drupal\graphql\Plugin\DataProducerPluginManager;
use Symfony\Component\HttpFoundation\RequestStack;
use GraphQL\Type\Definition\ResolveInfo;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* A proxy class that lazy resolves data producers and has a result cache.
Expand Down
17 changes: 13 additions & 4 deletions src/Plugin/GraphQL/DataProducer/Entity/EntityAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Drupal\graphql\Plugin\GraphQL\DataProducer\Entity;

use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;

/**
Expand Down Expand Up @@ -37,13 +38,21 @@ class EntityAccess extends DataProducerPluginBase {
* Resolver.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to check access for.
* @param string $operation
* The access operation, for example "view".
* @param \Drupal\Core\Session\AccountInterface $user
* The user account access should be checked for.
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
* The context to add caching information to.
*
* @return bool|\Drupal\Core\Access\AccessResultInterface
* @return bool
* TRUE when access to the entity is allowed, FALSE otherwise.
*/
public function resolve(EntityInterface $entity, $operation = NULL, AccountInterface $user = NULL) {
return $entity->access($operation ?? 'view', $user);
public function resolve(EntityInterface $entity, ?string $operation, ?AccountInterface $user, FieldContext $context) {
$result = $entity->access($operation ?? 'view', $user, TRUE);
$context->addCacheableDependency($result);
return $result->isAllowed();
}

}
Loading

0 comments on commit cf24a8b

Please sign in to comment.