Skip to content

Drupal 9 compatibility #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphql.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ type: module
description: 'Base module for integrating GraphQL with Drupal.'
package: GraphQL
configure: graphql.config_page
core: 8.x
core_version_requirement: '^8.7.7 || ^9'
2 changes: 1 addition & 1 deletion modules/graphql_core/graphql_core.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: GraphQL Core
type: module
description: 'Provides type system plugins and derivers on behalf of core modules.'
package: GraphQL
core: 8.x
core_version_requirement: '^8.7.7 || ^9'
dependencies:
- graphql
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function resolveValues($value, array $args, ResolveContext $context, R
$url = $style->buildUrl($file->getFileUri());
}
else {
$url = $file->url();
$url = $file->toUrl();
}

yield new CacheableValue([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Drupal\Tests\graphql_core\Kernel\Context;
namespace Drupal\Tests\graphql_core\Kernel\Entity;

use Drupal\node\Entity\Node;
use Drupal\Tests\graphql_core\Kernel\GraphQLContentTestBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testImageField() {
'image' => [[
'alt' => $a->image->alt,
'title' => $a->image->title,
'entity' => ['url' => $a->image->entity->url()],
'entity' => ['url' => $a->image->entity->toUrl()],
'width' => $a->image[0]->width,
'height' => $a->image[0]->height,
'thumbnailImage' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Form/EntityQueryMapImportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function save(array $form, FormStateInterface $formState) {
$entity->set('map', array_flip((array) json_decode($json)));
$entity->save();

drupal_set_message($this->t('Saved the query map version %id.', [
$this->messenger()->addStatus($this->t('Saved the query map version %id.', [
'%id' => $entity->id(),
]));

Expand Down
41 changes: 19 additions & 22 deletions src/Routing/QueryRouteEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,36 @@
namespace Drupal\graphql\Routing;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
use Drupal\Core\Routing\EnhancerInterface;
use Drupal\graphql\GraphQL\QueryProvider\QueryProviderInterface;
use Drupal\graphql\Utility\JsonHelper;
use GraphQL\Server\Helper;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;

class QueryRouteEnhancer implements RouteEnhancerInterface {

/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return $route->hasDefault('_graphql');
}
class QueryRouteEnhancer implements EnhancerInterface {

/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
$helper = new Helper();
$method = $request->getMethod();
$body = $this->extractBody($request);
$query = $this->extractQuery($request);
$operations = $helper->parseRequestParams($method, $body, $query);

// By default we assume a 'single' request. This is going to fail in the
// graphql processor due to a missing query string but at least provides
// the right format for the client to act upon.
return $defaults + [
'_controller' => $defaults['_graphql']['single'],
'operations' => $operations,
];
$route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
if ($route->hasDefault('_graphql')) {
$helper = new Helper();
$method = $request->getMethod();
$body = $this->extractBody($request);
$query = $this->extractQuery($request);
$operations = $helper->parseRequestParams($method, $body, $query);

// By default we assume a 'single' request. This is going to fail in the
// graphql processor due to a missing query string but at least provides
// the right format for the client to act upon.
return $defaults + [
'_controller' => $defaults['_graphql']['single'],
'operations' => $operations,
];
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/src/Kernel/Framework/TestFrameworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testFieldMock() {
]);

$schema = $this->introspect();
$this->assertArraySubset([
$expectedSubset = [
'types' => [
'Query' => [
'fields' => [
Expand All @@ -49,7 +49,11 @@ public function testFieldMock() {
],
],
],
], $schema);
];
foreach ($expectedSubset as $key => $value) {
$this->assertArrayHasKey($key, $schema);
$this->assertSame($value, $schema[$key]);
}

$this->assertResults('{ root }', [], [
'root' => 'test',
Expand Down
3 changes: 2 additions & 1 deletion tests/src/Kernel/Framework/UploadMutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class UploadMutationTest extends GraphQLTestBase {
*/
public function testFileUpload() {
// Create dummy file, since symfony will test if it exists..
$file = file_directory_temp() . '/graphql_upload_test.txt';
$file = \Drupal::service('file_system')
->getTempDirectory() . '/graphql_upload_test.txt';
touch($file);

// Mock a mutation that accepts the upload input and just returns
Expand Down
8 changes: 4 additions & 4 deletions tests/src/Traits/MockGraphQLPluginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ protected function mockFieldFactory($definition, $result = NULL, $builder = NULL
* @param mixed|null $applies
* A result for the types "applies" method. Defaults to `TRUE`.
*
* @return \PHPUnit_Framework_MockObject_MockObject
* @return \PHPUnit\Framework\MockObject\MockObject
* The type mock object.
*/
protected function mockType($id, array $definition, $applies = TRUE, $builder = NULL) {
Expand Down Expand Up @@ -463,7 +463,7 @@ protected function mockInputTypeFactory($definition, $builder) {
* A result for this mutation. Can be a value or a callback. If omitted, no
* resolve method mock will be attached.
*
* @return \PHPUnit_Framework_MockObject_MockObject
* @return \PHPUnit\Framework\MockObject\MockObject
* The mutation mock object.
*/
protected function mockMutation($id, array $definition, $result = NULL, $builder = NULL) {
Expand Down Expand Up @@ -513,7 +513,7 @@ protected function mockMutationFactory($definition, $result = NULL, $builder = N
* @param array $definition
* The plugin definition. Will be merged with the interface defaults.
*
* @return \PHPUnit_Framework_MockObject_MockObject
* @return \PHPUnit\Framework\MockObject\MockObject
* The interface mock object.
*/
protected function mockInterface($id, array $definition, $builder = NULL) {
Expand Down Expand Up @@ -555,7 +555,7 @@ protected function mockInterfaceFactory($definition, $builder = NULL) {
* @param array $definition
* The plugin definition. Will be merged with the union defaults.
*
* @return \PHPUnit_Framework_MockObject_MockObject
* @return \PHPUnit\Framework\MockObject\MockObject
* The union mock object.
*/
protected function mockUnion($id, array $definition, $builder = NULL) {
Expand Down