Skip to content

Commit d80b9a0

Browse files
committed
Fix merge 8.x.4.x
2 parents d19bf09 + 4f92c53 commit d80b9a0

36 files changed

+959
-56
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ jobs:
8585
run: composer --no-interaction --no-progress require \
8686
webonyx/graphql-php:^14.8 \
8787
drupal/typed_data:^1.0 \
88+
drupal/redirect:^1.0 \
8889
phpstan/phpstan:^1.7.14 \
8990
mglaman/phpstan-drupal:^1.1.2 \
9091
phpstan/phpstan-deprecation-rules:^1.0.0 \

assets/explorer/dist/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/explorer/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Explorer from './Explorer';
1010
*/
1111
Drupal.behaviors.graphQLRenderExplorer = {
1212
attach: (context, settings) => {
13-
const container = jQuery('#graphql-explorer', context).once('graphql-explorer')[0] || undefined;
13+
const container = jQuery(once('graphql-explorer', '#graphql-explorer', context))[0] || undefined;
1414

1515
if (typeof container === 'undefined') {
1616
return;

assets/voyager/dist/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/voyager/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"lint": "eslint src"
77
},
88
"dependencies": {
9+
"@drupal/once": "^1.0.1",
910
"graphql": "^15.5.1",
1011
"graphql-voyager": "^1.0.0-rc.27",
1112
"react": "^16.3",

assets/voyager/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import ReactDOM from 'react-dom';
33
import { Voyager } from 'graphql-voyager';
44
import Drupal from 'drupal';
55
import jQuery from 'jquery';
6+
import once from '@drupal/once';
67

78
/**
89
* Behavior for rendering the GraphQL Voyager interface.
910
*/
1011
Drupal.behaviors.graphQLRenderVoyager = {
1112
attach: (context, settings) => {
12-
const container = jQuery('#graphql-voyager', context).once('graphql-voyager')[0] || undefined;
13+
const container = jQuery(once('graphql-voyager', '#graphql-voyager', context))[0] || undefined;
1314

1415
if (typeof container === 'undefined') {
1516
return;

assets/voyager/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.6.tgz#d5e0706cf8c6acd8c6032f8d54070af261bbbb2f"
100100
integrity sha512-ws57AidsDvREKrZKYffXddNkyaF14iHNHm8VQnZH6t99E8gczjNN0GpvcGny0imC80yQ0tHz1xVUKk/KFQSUyA==
101101

102+
"@drupal/once@^1.0.1":
103+
version "1.0.1"
104+
resolved "https://registry.yarnpkg.com/@drupal/once/-/once-1.0.1.tgz#7c1ef480aec6d5fa4b5ae986afa5a607afc38482"
105+
integrity sha512-O8tQmNDBgSm3ADuFZ5OZlGxsrdsc+pEqd1NBoMpSzWwiOnWwC91tqDwnlX+mDh7sBJoJ+4vVwFh0NLUV4LPFvg==
106+
102107
"@eslint/eslintrc@^1.1.0":
103108
version "1.1.0"
104109
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.1.0.tgz#583d12dbec5d4f22f333f9669f7d0b7c7815b4d3"

doc/producers/custom.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Custom data producers allow you essentially hook into any data of Drupal, becaus
66

77
Lets look at a custom Data producer that loads the current user (similar to the 3.x version of currentUser query).
88

9-
The first step as seen before is to add our query to the schema :
9+
The first step as seen before is to add our query to the schema :
1010

11-
```
11+
```
1212
type Query {
1313
...
1414
currentUser: User
@@ -21,7 +21,7 @@ type User {
2121
}
2222
```
2323

24-
Now that we have this we need to make a resolver that actually loads this user, but for that first we need our own custom data producer "CurrentUser" :
24+
Now that we have this we need to make a resolver that actually loads this user, but for that first we need our own custom data producer "CurrentUser" :
2525

2626
```php
2727
<?php
@@ -99,7 +99,7 @@ class CurrentUser extends DataProducerPluginBase implements ContainerFactoryPlug
9999

100100
We are defining a custom data producer `current_user` that we can now use to resolve our query that we previously added to the schema. Notice that our data producer returns only the user id and not the actual user object. However we can combine it with an entity_load which is already made very efficient with in the module (taking advantage of caching strategies using buffering) so we don't have to actually load the user here.
101101

102-
Lets see how we can consume our newly created data producer :
102+
Lets see how we can consume our newly created data producer :
103103

104104
```php
105105
$registry->addFieldResolver('Query', 'currentUser', $builder->compose(
@@ -112,7 +112,7 @@ $registry->addFieldResolver('Query', 'currentUser', $builder->compose(
112112

113113
Notice how we combine our custom data producer with a built-in `entity_load` to make querying more performance and standardized across. We will look at `compose` in more detail in the next section.
114114

115-
In the end when we do a query like this :
115+
In the end when we do a query like this :
116116

117117
```graphql
118118
{
@@ -123,7 +123,7 @@ In the end when we do a query like this :
123123
}
124124
```
125125

126-
we get a result like this :
126+
we get a result like this :
127127

128128
```json
129129
{
@@ -136,4 +136,15 @@ we get a result like this :
136136
}
137137
```
138138

139-
(For this to actually work we would need to add resolvers to the User object to resolve the `id` and `name` properties).
139+
For this to actually work we would need to add resolvers to the User object to resolve the `id` and `name` properties like so:
140+
```php
141+
$registry->addFieldResolver('User', 'id', $builder->callback(function ($account) {
142+
/** @var \Drupal\Core\Session\AccountProxyInterface $account */
143+
return $account->id();
144+
}));
145+
146+
$registry->addFieldResolver('User', 'name', $builder->callback(function ($account) {
147+
/** @var \Drupal\Core\Session\AccountProxyInterface $account */
148+
return $account->getAccountName();
149+
}));
150+
```

graphql.libraries.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ explorer:
99
dependencies:
1010
- core/drupal
1111
- core/jquery
12-
- core/jquery.once
12+
- core/once
1313

1414
voyager:
1515
version: VERSION
@@ -23,7 +23,7 @@ voyager:
2323
dependencies:
2424
- core/drupal
2525
- core/jquery
26-
- core/jquery.once
26+
- core/once
2727

2828
persisted_queries:
2929
version: VERSION
@@ -32,4 +32,4 @@ persisted_queries:
3232
dependencies:
3333
- core/drupal
3434
- core/jquery
35-
- core/jquery.once
35+
- core/once

graphql.routing.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ graphql.explorer:
4848
options:
4949
_admin_route: TRUE
5050
parameters:
51-
server:
52-
type: entity:graphql_server
51+
graphql_server:
52+
with_config_overrides: TRUE
5353

5454
graphql.voyager:
5555
path: '/admin/config/graphql/servers/manage/{graphql_server}/voyager'
@@ -62,7 +62,7 @@ graphql.voyager:
6262
_admin_route: TRUE
6363
parameters:
6464
graphql_server:
65-
type: entity:graphql_server
65+
with_config_overrides: TRUE
6666

6767
graphql.validate:
6868
path: '/admin/config/graphql/servers/manage/{graphql_server}/validate'
@@ -75,8 +75,7 @@ graphql.validate:
7575
_admin_route: TRUE
7676
parameters:
7777
graphql_server:
78-
type: entity:graphql_server
79-
78+
with_config_overrides: TRUE
8079

8180
entity.graphql_server.delete_form:
8281
path: '/admin/config/graphql/servers/manage/{graphql_server}/delete'

graphql.services.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ services:
3939
tags:
4040
- { name: cache.context }
4141

42+
# Cache bin for the persisted queries.
43+
cache.graphql.apq:
44+
class: Drupal\Core\Cache\CacheBackendInterface
45+
tags:
46+
- { name: cache.bin }
47+
factory: cache_factory:get
48+
arguments: [graphql_apq]
49+
4250
# Cache bin for the parsed sdl ast.
4351
cache.graphql.ast:
4452
class: Drupal\Core\Cache\CacheBackendInterface
@@ -116,6 +124,13 @@ services:
116124
tags:
117125
- { name: event_subscriber }
118126

127+
# Cache the queries to be persistent.
128+
graphql.apq_subscriber:
129+
class: Drupal\graphql\EventSubscriber\ApqSubscriber
130+
arguments: ['@cache.graphql.apq']
131+
tags:
132+
- { name: event_subscriber }
133+
119134
# Plugin manager for schemas
120135
plugin.manager.graphql.schema:
121136
class: Drupal\graphql\Plugin\SchemaPluginManager

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ parameters:
2525
# that.
2626
- "#^Access to an undefined property Drupal\\\\#"
2727
# PHPUnit deprecation warnings in Drupal 9 that we don't care about.
28-
- "#^Call to deprecated method setMethods\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\MockBuilder:#"
2928
- "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#"
3029
# Drupal allows object property access to custom fields, so we cannot fix
3130
# that.

src/Entity/ServerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function removeAllPersistedQueryInstances();
6060
/**
6161
* Returns the current persisted queries set.
6262
*
63-
* @return \Drupal\graphql\Plugin\PersistedQueryPluginInterface[]
63+
* @return \Drupal\graphql\Plugin\PersistedQueryPluginInterface[]|null
6464
*/
6565
public function getPersistedQueryInstances();
6666

src/Event/AlterSchemaDataEvent.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Drupal\graphql\Event;
6+
7+
use Drupal\Component\EventDispatcher\Event;
8+
9+
/**
10+
* Represents an event that is triggered to alter schema data.
11+
*/
12+
class AlterSchemaDataEvent extends Event {
13+
14+
/**
15+
* Event fired to alter schema data.
16+
*
17+
* @var string
18+
*/
19+
const EVENT_NAME = 'graphql.sdl.alter_schema';
20+
21+
/**
22+
* The schema array data.
23+
*
24+
* @var array
25+
*/
26+
protected $schemaData;
27+
28+
/**
29+
* AlterSchemaDataEvent constructor.
30+
*
31+
* @param array $schemaData
32+
* The schema data reference.
33+
*/
34+
public function __construct(array &$schemaData) {
35+
$this->schemaData = $schemaData;
36+
}
37+
38+
/**
39+
* Returns the schema data.
40+
*
41+
* @return array
42+
* The schema data.
43+
*/
44+
public function getSchemaData(): array {
45+
return $this->schemaData;
46+
}
47+
48+
/**
49+
* Sets the schema data.
50+
*
51+
* @param array $schemaData
52+
* The schema data.
53+
*/
54+
public function setSchemaData(array $schemaData): void {
55+
$this->schemaData = $schemaData;
56+
}
57+
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Drupal\graphql\Event;
6+
7+
use Drupal\Component\EventDispatcher\Event;
8+
9+
/**
10+
* Represents an event that is triggered to alter schema extension data.
11+
*/
12+
class AlterSchemaExtensionDataEvent extends Event {
13+
14+
/**
15+
* Event fired to alter schema extension data.
16+
*
17+
* @var string
18+
*/
19+
const EVENT_NAME = 'graphql.sdl.alter_schema_extension';
20+
21+
/**
22+
* The schema array data.
23+
*
24+
* @var array
25+
*/
26+
protected $schemaExtensionData;
27+
28+
/**
29+
* AlterSchemaExtensionDataEvent constructor.
30+
*
31+
* @param array $schemaExtensionData
32+
* The schema extension data.
33+
*/
34+
public function __construct(array $schemaExtensionData) {
35+
$this->schemaExtensionData = $schemaExtensionData;
36+
}
37+
38+
/**
39+
* Returns the schema extension data.
40+
*
41+
* @return array
42+
* The schema extension data.
43+
*/
44+
public function getSchemaExtensionData(): array {
45+
return $this->schemaExtensionData;
46+
}
47+
48+
/**
49+
* Returns the schema extension data.
50+
*
51+
* @param array $schemaExtensionData
52+
* The schema extension data.
53+
*/
54+
public function setSchemaExtensionData(array $schemaExtensionData): void {
55+
$this->schemaExtensionData = $schemaExtensionData;
56+
}
57+
58+
}

0 commit comments

Comments
 (0)