Skip to content

Commit

Permalink
Merge branch '8.x-4.x' into route-load-language-parameter-2
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi authored Nov 12, 2023
2 parents d6ca744 + 3dd570c commit 51a5489
Show file tree
Hide file tree
Showing 61 changed files with 1,470 additions and 246 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
8 changes: 4 additions & 4 deletions doc/producers/composing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Note that you can always easily tap into the chain and e.g. use xdebug to debug
$builder->compose(
$builder->tap($builder->callback(function ($parent, $args) {
// YOU CAN SET A XDEBUG BREAKPOINT IN THESE CALLBACKS TO CHECK THE VALUES.
echo("Compose step 0.");
$compose_step = 0;
})),
// Load the file object from the field.
$builder->produce('property_path')
Expand All @@ -49,22 +49,22 @@ Note that you can always easily tap into the chain and e.g. use xdebug to debug
->map('path', $builder->fromValue('YOUR_FIELD_NAME.YOUR_FIELD_PROPERTY')),
$builder->tap($builder->callback(function ($parent, $args) {
// YOU CAN SET A XDEBUG BREAKPOINT IN THESE CALLBACKS TO CHECK THE VALUES.
echo("Compose step 1.");
$compose_step = 1;
})),
// Load the image style derivative of the file.
$builder->produce('image_derivative')
->map('entity', $builder->fromParent())
->map('style', $builder->fromValue('YOUR_IMAGE_STYLE')),
$builder->tap($builder->callback(function ($parent, $args) {
// YOU CAN SET A XDEBUG BREAKPOINT IN THESE CALLBACKS TO CHECK THE VALUES.
echo("Compose step 2.");
$compose_step = 2;
})),
// Retrieve the url of the generated image.
$builder->produce('image_style_url')
->map('derivative', $builder->fromParent()),
$builder->tap($builder->callback(function ($parent, $args) {
// YOU CAN SET A XDEBUG BREAKPOINT IN THESE CALLBACKS TO CHECK THE VALUES.
echo("Compose step 3.");
$compose_step = 3;
}))
)
);
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Drupal\graphql_examples\Wrappers\QueryConnection;
use Drupal\node\Entity\Node;
use GraphQL\Error\UserError;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -94,7 +95,13 @@ public function resolve($offset, $limit, RefinableCacheableDependencyInterface $
$entityType = $storage->getEntityType();
$query = $storage->getQuery()
->currentRevision()
->accessCheck();
->accessCheck()
// The access check does not filter out unpublished nodes automatically,
// so we need to do this explicitly here. We don't want to run access
// checks on loaded nodes later, as that would then make the query count
// numbers wrong. Therefore all fields relevant for access need to be
// included here.
->condition('status', Node::PUBLISHED);

$query->condition($entityType->getKey('bundle'), 'article');
$query->range($offset, $limit);
Expand Down
3 changes: 2 additions & 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 Expand Up @@ -183,6 +183,7 @@ services:
- '@config.factory'
- '@renderer'
- '@event_dispatcher'
- '@image.factory'

plugin.manager.graphql.persisted_query:
class: Drupal\graphql\Plugin\PersistedQueryPluginManager
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$#
"""
7 changes: 7 additions & 0 deletions src/Controller/ExplorerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public function viewExplorer(ServerInterface $graphql_server, Request $request)
$url = $this->urlGenerator->generate("graphql.query.{$graphql_server->id()}");
$introspectionData = $this->introspection->introspect($graphql_server);

if ($graphql_server->get('disable_introspection')) {
return [
'#type' => 'markup',
'#markup' => $this->t('Introspection is disabled for this server, enable it to use the Explorer.'),
];
}

return [
'#type' => 'markup',
'#markup' => '<div id="graphql-explorer"></div>',
Expand Down
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
Loading

0 comments on commit 51a5489

Please sign in to comment.