@amazeelabs/silverback-gatsby 3.7.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/drupal/silverback_gatsby/.prettierignore +1 -0
  3. package/drupal/silverback_gatsby/CHANGELOG.md +1216 -0
  4. package/drupal/silverback_gatsby/README.md +297 -0
  5. package/drupal/silverback_gatsby/composer.json +15 -0
  6. package/drupal/silverback_gatsby/directives.gql +63 -0
  7. package/drupal/silverback_gatsby/directives.graphql +62 -0
  8. package/drupal/silverback_gatsby/drush.services.yml +9 -0
  9. package/drupal/silverback_gatsby/graphql/entity.directive.graphqls +2 -0
  10. package/drupal/silverback_gatsby/graphql/menu.directive.graphqls +17 -0
  11. package/drupal/silverback_gatsby/graphql/silverback_gatsby.base.graphqls +25 -0
  12. package/drupal/silverback_gatsby/graphql/silverback_gatsby.extension.graphqls +10 -0
  13. package/drupal/silverback_gatsby/graphql/stringTranslation.directive.graphqls +4 -0
  14. package/drupal/silverback_gatsby/graphql/translatableString.directive.graphqls +2 -0
  15. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/directives.gql +6 -0
  16. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/graphql/.graphqlrc.json +4 -0
  17. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/graphql/silverback_gatsby_example.graphqls +39 -0
  18. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/silverback_gatsby_example.info.yml +7 -0
  19. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/silverback_gatsby_example.module +16 -0
  20. package/drupal/silverback_gatsby/modules/silverback_gatsby_example/src/Directives.php +24 -0
  21. package/drupal/silverback_gatsby/silverback_gatsby.info.yml +8 -0
  22. package/drupal/silverback_gatsby/silverback_gatsby.install +180 -0
  23. package/drupal/silverback_gatsby/silverback_gatsby.links.task.yml +6 -0
  24. package/drupal/silverback_gatsby/silverback_gatsby.module +119 -0
  25. package/drupal/silverback_gatsby/silverback_gatsby.permissions.yml +8 -0
  26. package/drupal/silverback_gatsby/silverback_gatsby.post_update.php +15 -0
  27. package/drupal/silverback_gatsby/silverback_gatsby.routing.yml +28 -0
  28. package/drupal/silverback_gatsby/silverback_gatsby.services.yml +50 -0
  29. package/drupal/silverback_gatsby/src/Annotation/GatsbyFeed.php +41 -0
  30. package/drupal/silverback_gatsby/src/Commands/SilverbackGatsbyCommands.php +102 -0
  31. package/drupal/silverback_gatsby/src/Controller/BuildController.php +45 -0
  32. package/drupal/silverback_gatsby/src/Controller/PublisherController.php +34 -0
  33. package/drupal/silverback_gatsby/src/Directives.php +51 -0
  34. package/drupal/silverback_gatsby/src/GatsbyBuildTrigger.php +230 -0
  35. package/drupal/silverback_gatsby/src/GatsbyBuildTriggerInterface.php +52 -0
  36. package/drupal/silverback_gatsby/src/GatsbyUpdate.php +38 -0
  37. package/drupal/silverback_gatsby/src/GatsbyUpdateHandler.php +181 -0
  38. package/drupal/silverback_gatsby/src/GatsbyUpdateTracker.php +98 -0
  39. package/drupal/silverback_gatsby/src/GatsbyUpdateTrackerInterface.php +59 -0
  40. package/drupal/silverback_gatsby/src/GatsbyUpdateTrigger.php +69 -0
  41. package/drupal/silverback_gatsby/src/GatsbyUpdateTriggerInterface.php +22 -0
  42. package/drupal/silverback_gatsby/src/GraphQL/Build.php +235 -0
  43. package/drupal/silverback_gatsby/src/GraphQL/ComposableSchema.php +73 -0
  44. package/drupal/silverback_gatsby/src/LocaleStorageDecorator.php +181 -0
  45. package/drupal/silverback_gatsby/src/MenuTreeStorageDecorator.php +139 -0
  46. package/drupal/silverback_gatsby/src/Plugin/FeedBase.php +121 -0
  47. package/drupal/silverback_gatsby/src/Plugin/FeedInterface.php +132 -0
  48. package/drupal/silverback_gatsby/src/Plugin/FeedPluginManager.php +39 -0
  49. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/EntityFeed.php +252 -0
  50. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/MenuFeed.php +292 -0
  51. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/StringTranslationFeed.php +171 -0
  52. package/drupal/silverback_gatsby/src/Plugin/Gatsby/Feed/TranslatableStringFeed.php +128 -0
  53. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/CurrentUserEntity.php +43 -0
  54. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/EntityQueryBase.php +40 -0
  55. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchEntity.php +371 -0
  56. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchString.php +64 -0
  57. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FetchTranslatableString.php +74 -0
  58. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/FocalPoint.php +47 -0
  59. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/GatsbyBuildId.php +36 -0
  60. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/GatsbyExtractId.php +28 -0
  61. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/GatsbyExtractLangcode.php +28 -0
  62. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/ImageProps.php +149 -0
  63. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/ListEntities.php +88 -0
  64. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/ListStrings.php +87 -0
  65. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/StringId.php +37 -0
  66. package/drupal/silverback_gatsby/src/Plugin/GraphQL/DataProducer/StringTranslations.php +94 -0
  67. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/EntityFetch.php +51 -0
  68. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/EntityTranslationsWithDefault.php +30 -0
  69. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/FocalPoint.php +27 -0
  70. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/ImageProps.php +27 -0
  71. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/MenuLangcode.php +27 -0
  72. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/MenuTranslations.php +36 -0
  73. package/drupal/silverback_gatsby/src/Plugin/GraphQL/Directive/SilverbackGatsbyEntityId.php +39 -0
  74. package/drupal/silverback_gatsby/src/Plugin/GraphQL/SchemaExtension/SilverbackGatsbySchemaExtension.php +384 -0
  75. package/drupal/silverback_gatsby/src/SilverbackGatsbyServiceProvider.php +43 -0
  76. package/drupal/silverback_gatsby/src/SilverbackGatsbySessionConfiguration.php +30 -0
  77. package/drupal/silverback_gatsby/src/SilverbackReverseProxyMiddleware.php +49 -0
  78. package/drupal/silverback_gatsby/tests/queries/create-page-fields.gql +12 -0
  79. package/drupal/silverback_gatsby/tests/queries/current-user.gql +6 -0
  80. package/drupal/silverback_gatsby/tests/queries/feed_info.gql +12 -0
  81. package/drupal/silverback_gatsby/tests/queries/load-entity.gql +5 -0
  82. package/drupal/silverback_gatsby/tests/queries/menus.gql +31 -0
  83. package/drupal/silverback_gatsby/tests/queries/multilingual-menus.gql +11 -0
  84. package/drupal/silverback_gatsby/tests/queries/revisionable-translatable.gql +15 -0
  85. package/drupal/silverback_gatsby/tests/queries/revisionable.gql +8 -0
  86. package/drupal/silverback_gatsby/tests/queries/translatable.gql +14 -0
  87. package/drupal/silverback_gatsby/tests/queries/untranslatable.gql +10 -0
  88. package/drupal/silverback_gatsby/tests/schema/.graphqlrc.json +4 -0
  89. package/drupal/silverback_gatsby/tests/schema/translatable-strings.graphql +7 -0
  90. package/drupal/silverback_gatsby/tests/src/Kernel/CurrentUserTest.php +37 -0
  91. package/drupal/silverback_gatsby/tests/src/Kernel/EntityFeedTest.php +490 -0
  92. package/drupal/silverback_gatsby/tests/src/Kernel/EntityFeedTestBase.php +178 -0
  93. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyBuildTriggerTest.php +155 -0
  94. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyFeedInfoTest.php +319 -0
  95. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyUpdateHandlerTest.php +131 -0
  96. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyUpdateTrackerTest.php +196 -0
  97. package/drupal/silverback_gatsby/tests/src/Kernel/GatsbyUpdateTriggerTest.php +177 -0
  98. package/drupal/silverback_gatsby/tests/src/Kernel/MenuFeedTest.php +192 -0
  99. package/drupal/silverback_gatsby/tests/src/Kernel/TranslatableStringFeedTest.php +210 -0
  100. package/drupal/silverback_gatsby/tests/src/Traits/NotificationCheckTrait.php +43 -0
  101. package/package.json +15 -0
@@ -0,0 +1,37 @@
1
+ <?php
2
+
3
+ namespace Drupal\Tests\silverback_gatsby\Kernel;
4
+
5
+ use Drupal\user\Entity\User;
6
+
7
+ class CurrentUserTest extends EntityFeedTestBase {
8
+ function testAnonymousUser() {
9
+ $query = $this->getQueryFromFile('current-user.gql');
10
+ $metadata = $this->defaultCacheMetaData();
11
+ $metadata->setCacheMaxAge(0);
12
+ $anonymous = User::load(0);
13
+ $metadata->addCacheTags($anonymous->getCacheTags());
14
+ $this->setCurrentUser($anonymous);
15
+ $this->assertResults($query, [], [
16
+ '_currentUser' => [
17
+ 'id' => '0',
18
+ 'name' => null,
19
+ ],
20
+ ], $metadata);
21
+ }
22
+
23
+ function testAuthenticatedUser() {
24
+ $query = $this->getQueryFromFile('current-user.gql');
25
+ $testuser = $this->createUser([], 'test');
26
+ $metadata = $this->defaultCacheMetaData();
27
+ $metadata->setCacheMaxAge(0);
28
+ $metadata->addCacheTags($testuser->getCacheTags());
29
+ $this->setCurrentUser($testuser);
30
+ $this->assertResults($query, [], [
31
+ '_currentUser' => [
32
+ 'id' => $testuser->id(),
33
+ 'name' => $testuser->name->value,
34
+ ],
35
+ ], $metadata);
36
+ }
37
+ }
@@ -0,0 +1,490 @@
1
+ <?php
2
+
3
+ namespace Drupal\Tests\silverback_gatsby\Kernel;
4
+
5
+ use Drupal\Core\DependencyInjection\ContainerBuilder;
6
+ use Drupal\node\Entity\Node;
7
+ use Drupal\Tests\Traits\Core\PathAliasTestTrait;
8
+
9
+ class EntityFeedTest extends EntityFeedTestBase {
10
+ use PathAliasTestTrait;
11
+
12
+ protected static $modules = ['path_alias'];
13
+
14
+ public function register(ContainerBuilder $container) {
15
+ parent::register($container);
16
+
17
+ // Restore AliasPathProcessor tags which are removed in the parent method.
18
+ $container->getDefinition('path_alias.path_processor')
19
+ ->addTag('path_processor_inbound', ['priority' => 100])
20
+ ->addTag('path_processor_outbound', ['priority' => 300]);
21
+ }
22
+
23
+ public function setUp(): void {
24
+ parent::setUp();
25
+ $this->installEntitySchema('path_alias');
26
+ }
27
+
28
+ public function testUntranslatableEntity() {
29
+ $node = Node::create([
30
+ 'type' => 'blog',
31
+ 'title' => 'Test'
32
+ ]);
33
+ $node->save();
34
+
35
+ $query = $this->getQueryFromFile('untranslatable.gql');
36
+ $metadata = $this->defaultCacheMetaData();
37
+ $metadata->addCacheContexts(['user.node_grants:view']);
38
+ $metadata->addCacheTags(['node:1', 'node_list']);
39
+ $this->assertResults($query, [], [
40
+ '_loadPost' => [
41
+ 'title' => 'Test',
42
+ ],
43
+ '_queryPosts' => [
44
+ [
45
+ '_id' => $node->uuid(),
46
+ '_drupalId' => $node->uuid(),
47
+ 'title' => 'Test',
48
+ ],
49
+ ],
50
+ ], $metadata);
51
+ }
52
+
53
+ public function testTranslatableEntity() {
54
+ $node = Node::create([
55
+ 'type' => 'page',
56
+ 'title' => 'Test'
57
+ ]);
58
+ $node->save();
59
+
60
+ $query = $this->getQueryFromFile('translatable.gql');
61
+ $metadata = $this->defaultCacheMetaData();
62
+ $metadata->addCacheContexts(['user.node_grants:view', 'static:language:en']);
63
+ $metadata->addCacheTags(['node:1', 'node_list']);
64
+ $this->assertResults($query, ['id' => '1:en'], [
65
+ '_loadPage' => [
66
+ 'title' => 'Test',
67
+ ],
68
+ '_queryPages' => [
69
+ [
70
+ '_id' => $node->uuid() . ':en',
71
+ '_drupalId' => $node->uuid(),
72
+ '_translations' => [
73
+ [
74
+ '_defaultTranslation' => true,
75
+ '_langcode' => 'en',
76
+ 'title' => 'Test',
77
+ ],
78
+ ],
79
+ ],
80
+ ],
81
+ ], $metadata);
82
+ }
83
+
84
+ public function testLanguageNotApplicable() {
85
+ $node = Node::create([
86
+ 'type' => 'page',
87
+ 'title' => 'Test',
88
+ 'langcode' => 'zxx',
89
+ ]);
90
+ $node->save();
91
+
92
+ $query = $this->getQueryFromFile('translatable.gql');
93
+ $metadata = $this->defaultCacheMetaData();
94
+ $metadata->addCacheContexts(['user.node_grants:view']);
95
+ $metadata->addCacheTags(['node:1', 'node_list']);
96
+ $this->assertResults($query, ['id' => '1:zxx'], [
97
+ '_loadPage' => [
98
+ 'title' => 'Test',
99
+ ],
100
+ '_queryPages' => [
101
+ [
102
+ '_id' => $node->uuid() . ':zxx',
103
+ '_drupalId' => $node->uuid(),
104
+ '_translations' => [
105
+ [
106
+ '_defaultTranslation' => true,
107
+ '_langcode' => 'zxx',
108
+ 'title' => 'Test',
109
+ ],
110
+ ],
111
+ ],
112
+ ],
113
+ ], $metadata);
114
+ }
115
+
116
+ public function testLanguageNotSpecified() {
117
+ $node = Node::create([
118
+ 'type' => 'page',
119
+ 'title' => 'Test',
120
+ 'langcode' => 'und',
121
+ ]);
122
+ $node->save();
123
+
124
+ $query = $this->getQueryFromFile('translatable.gql');
125
+ $metadata = $this->defaultCacheMetaData();
126
+ $metadata->addCacheContexts(['user.node_grants:view']);
127
+ $metadata->addCacheTags(['node:1', 'node_list']);
128
+ $this->assertResults($query, ['id' => '1:und'], [
129
+ '_loadPage' => [
130
+ 'title' => 'Test',
131
+ ],
132
+ '_queryPages' => [
133
+ [
134
+ '_id' => $node->uuid() . ':und',
135
+ '_drupalId' => $node->uuid(),
136
+ '_translations' => [
137
+ [
138
+ '_defaultTranslation' => true,
139
+ '_langcode' => 'und',
140
+ 'title' => 'Test',
141
+ ],
142
+ ],
143
+ ],
144
+ ],
145
+ ], $metadata);
146
+ }
147
+
148
+ public function testAccessDenied() {
149
+ $node = Node::create([
150
+ 'type' => 'page',
151
+ // A custom entity access hook in silverback_gatsby_example will make
152
+ // entities with this label inaccessible.
153
+ 'title' => 'Access denied',
154
+ ]);
155
+ $node->save();
156
+
157
+ $query = $this->getQueryFromFile('translatable.gql');
158
+ $metadata = $this->defaultCacheMetaData();
159
+ $metadata->addCacheContexts(['user.node_grants:view']);
160
+ $metadata->addCacheTags(['node:1', 'node_list']);
161
+ $this->assertResults($query, ['id' => $node->uuid() . ':en'], [
162
+ '_loadPage' => NULL,
163
+ '_queryPages' => [
164
+ null
165
+ ],
166
+ ], $metadata);
167
+ }
168
+
169
+ public function testDeletedTranslation() {
170
+ $node = Node::create([
171
+ 'type' => 'page',
172
+ 'title' => 'English',
173
+ ]);
174
+ $node->save();
175
+ $node->addTranslation('de', ['title' => 'German'])->save();
176
+ $node->removeTranslation('de');
177
+ $node->save();
178
+
179
+ $query = $this->getQueryFromFile('translatable.gql');
180
+ $metadata = $this->defaultCacheMetaData();
181
+ $metadata->addCacheContexts(['user.node_grants:view', 'static:language:en']);
182
+ $metadata->addCacheTags(['node:1', 'node_list']);
183
+ $this->assertResults($query, ['id' => '1:de'], [
184
+ '_loadPage' => null,
185
+ '_queryPages' => [
186
+ [
187
+ '_id' => $node->uuid() . ':en',
188
+ '_drupalId' => $node->uuid(),
189
+ '_translations' => [
190
+ [
191
+ '_defaultTranslation' => true,
192
+ '_langcode' => 'en',
193
+ 'title' => 'English',
194
+ ],
195
+ ],
196
+ ],
197
+ ],
198
+ ], $metadata);
199
+ }
200
+
201
+ public function testUnpublishedTranslation() {
202
+ $node = Node::create([
203
+ 'type' => 'page',
204
+ 'title' => 'English',
205
+ ]);
206
+ $node->save();
207
+ $node->addTranslation('de', ['title' => 'German', 'status' => 0])->save();
208
+
209
+ $query = $this->getQueryFromFile('translatable.gql');
210
+ $metadata = $this->defaultCacheMetaData();
211
+ $metadata->addCacheContexts(['user.node_grants:view', 'static:language:en', 'static:language:de']);
212
+ $metadata->addCacheTags(['node:1', 'node_list']);
213
+ $this->assertResults($query, ['id' => $node->uuid() . ':de'], [
214
+ '_loadPage' => NULL,
215
+ '_queryPages' => [
216
+ [
217
+ '_id' => $node->uuid() . ':en',
218
+ '_drupalId' => $node->uuid(),
219
+ '_translations' => [
220
+ [
221
+ '_defaultTranslation' => true,
222
+ '_langcode' => 'en',
223
+ 'title' => 'English',
224
+ ],
225
+ ],
226
+ ],
227
+ ],
228
+ ], $metadata);
229
+ }
230
+
231
+ public function testUnpublishedSource() {
232
+ $node = Node::create([
233
+ 'type' => 'page',
234
+ 'title' => 'English',
235
+ 'status' => 0,
236
+ ]);
237
+ $node->save();
238
+ $node->addTranslation('de', ['title' => 'German', 'status' => 1])->save();
239
+
240
+ $query = $this->getQueryFromFile('translatable.gql');
241
+ $metadata = $this->defaultCacheMetaData();
242
+ $metadata->addCacheContexts(['user.node_grants:view', 'static:language:de', 'static:language:en']);
243
+ $metadata->addCacheTags(['node:1', 'node_list']);
244
+
245
+ $this->assertResults($query, ['id' => $node->uuid() . ':de'], [
246
+ '_loadPage' => [
247
+ "title" => "German"
248
+ ],
249
+ '_queryPages' => [
250
+ [
251
+ '_id' => $node->uuid() . ':de',
252
+ '_drupalId' => $node->uuid(),
253
+ '_translations' => [
254
+ [
255
+ '_defaultTranslation' => false,
256
+ '_langcode' => 'de',
257
+ 'title' => 'German',
258
+ ]
259
+ ],
260
+ ],
261
+ ],
262
+ ], $metadata);
263
+
264
+ $metadata = $this->defaultCacheMetaData();
265
+ $metadata->addCacheContexts(['user.node_grants:view', 'static:language:de', 'static:language:en']);
266
+ $metadata->addCacheTags(['node:1', 'node_list']);
267
+ $this->assertResults($query, ['id' => $node->uuid() . ':en'], [
268
+ '_loadPage' => NULL,
269
+ '_queryPages' => [
270
+ [
271
+ '_id' => $node->uuid() . ':de',
272
+ '_drupalId' => $node->uuid(),
273
+ '_translations' => [
274
+ [
275
+ '_defaultTranslation' => false,
276
+ '_langcode' => 'de',
277
+ 'title' => 'German',
278
+ ]
279
+ ],
280
+ ],
281
+ ],
282
+ ], $metadata);
283
+ }
284
+
285
+ public function testCreatePageFields() {
286
+ $regular = Node::create([
287
+ 'type' => 'blog',
288
+ 'title' => 'Regular',
289
+ 'promote' => 0,
290
+ ]);
291
+ $regular->save();
292
+ $promoted = Node::create([
293
+ 'type' => 'blog',
294
+ 'title' => 'Promoted',
295
+ 'promote' => 1,
296
+ ]);
297
+ $promoted->save();
298
+
299
+ $query = $this->getQueryFromFile('create-page-fields.gql');
300
+ $metadata = $this->defaultCacheMetaData();
301
+ $metadata->addCacheTags(['node:1', 'node:2']);
302
+ $this->assertResults($query, [], [
303
+ 'regular' => [
304
+ 'title' => 'Regular',
305
+ 'path' => '/node/1',
306
+ 'template' => null,
307
+ ],
308
+ 'promoted' => [
309
+ 'title' => 'Promoted',
310
+ 'path' => '/node/2',
311
+ 'template' => 'blog-promoted',
312
+ ],
313
+ ], $metadata);
314
+ }
315
+
316
+ public function testRevisionable() {
317
+ $node = Node::create([
318
+ 'type' => 'blog',
319
+ 'title' => 'Revision 1'
320
+ ]);
321
+ $node->save();
322
+ $node->set('title', 'Revision 2');
323
+ $node->setNewRevision();
324
+ $node->save();
325
+
326
+ $query = $this->getQueryFromFile('revisionable.gql');
327
+ $metadata = $this->defaultCacheMetaData();
328
+ $metadata->addCacheTags(['node:1']);
329
+ $this->assertResults($query, [], [
330
+ 'a' => [
331
+ 'title' => 'Revision 1',
332
+ ],
333
+ 'b' => [
334
+ 'title' => 'Revision 2',
335
+ ],
336
+ ], $metadata);
337
+ }
338
+
339
+ public function testMultilingualRevisionable() {
340
+ $node = Node::create([
341
+ 'type' => 'page',
342
+ 'title' => 'Revision 1'
343
+ ]);
344
+ $node->save();
345
+ $node->setNewRevision();
346
+ $translation = $node->addTranslation('de', ['title' => 'Revision 1 German', 'status' => 1]);
347
+ $translation->save();
348
+
349
+
350
+ $translation->set('title', 'Revision 2 German');
351
+ $translation->setNewRevision();
352
+ $translation->save();
353
+
354
+ $query = $this->getQueryFromFile('revisionable-translatable.gql');
355
+ $metadata = $this->defaultCacheMetaData();
356
+ $metadata->addCacheTags(['node:1']);
357
+ $metadata->addCacheContexts(['static:language:de']);
358
+ $this->assertResults($query, [], [
359
+ 'a' => [
360
+ 'title' => 'Revision 1',
361
+ ],
362
+ 'b' => null,
363
+ 'c' => [
364
+ 'title' => 'Revision 1 German',
365
+ ],
366
+ 'd' => [
367
+ 'title' => 'Revision 2 German',
368
+ ],
369
+ ], $metadata);
370
+ }
371
+
372
+ public function testUnpublishedRevision() {
373
+ $node = Node::create([
374
+ 'type' => 'blog',
375
+ 'title' => 'Revision 1',
376
+ 'status' => 0,
377
+ ]);
378
+ $node->save();
379
+ $node->setNewRevision();
380
+ $node->set('title', 'Revision 2');
381
+ $node->set('status', 1);
382
+ $node->save();
383
+
384
+ $query = $this->getQueryFromFile('revisionable.gql');
385
+ $metadata = $this->defaultCacheMetaData();
386
+ $metadata->addCacheTags(['node:1']);
387
+ $this->assertResults($query, [], [
388
+ 'a' => null,
389
+ 'b' => [
390
+ 'title' => 'Revision 2',
391
+ ],
392
+ ], $metadata);
393
+ }
394
+
395
+ public function testUnpublishedMultilingualRevisionable() {
396
+ $node = Node::create([
397
+ 'type' => 'page',
398
+ 'title' => 'Revision 1',
399
+ 'status' => 0,
400
+ ]);
401
+ $node->save();
402
+ $node->setNewRevision();
403
+ $translation = $node->addTranslation('de', ['title' => 'Revision 1 German', 'status' => 1]);
404
+ $translation->save();
405
+
406
+
407
+ $translation->set('title', 'Revision 2 German (Draft)');
408
+ $translation->set('status', 0);
409
+ $translation->setNewRevision();
410
+ $translation->save();
411
+
412
+ $query = $this->getQueryFromFile('revisionable-translatable.gql');
413
+ $metadata = $this->defaultCacheMetaData();
414
+ $metadata->addCacheTags(['node:1']);
415
+ $metadata->addCacheContexts(['static:language:de']);
416
+ $this->assertResults($query, [], [
417
+ 'a' => null,
418
+ 'b' => null,
419
+ 'c' => [
420
+ 'title' => 'Revision 1 German',
421
+ ],
422
+ 'd' => null,
423
+ ], $metadata);
424
+ }
425
+
426
+ public function testLoadById() {
427
+ $node = Node::create([
428
+ 'type' => 'page',
429
+ 'title' => 'Test page'
430
+ ]);
431
+ $node->save();
432
+ $metadata = $this->defaultCacheMetaData();
433
+ $metadata->addCacheTags(['node:1']);
434
+ $query = $this->getQueryFromFile('load-entity.gql');
435
+ $this->assertResults($query, ['input' => '1:en'], [
436
+ '_loadPage' => [
437
+ 'title' => 'Test page',
438
+ ],
439
+ ], $metadata);
440
+ }
441
+
442
+ public function testLoadByUuid() {
443
+ $node = Node::create([
444
+ 'type' => 'page',
445
+ 'title' => 'Test page'
446
+ ]);
447
+ $node->save();
448
+ $metadata = $this->defaultCacheMetaData();
449
+ $metadata->addCacheTags(['node:1']);
450
+ $query = $this->getQueryFromFile('load-entity.gql');
451
+ $this->assertResults($query, ['input' => $node->uuid() . ':en'], [
452
+ '_loadPage' => [
453
+ 'title' => 'Test page',
454
+ ],
455
+ ], $metadata);
456
+ }
457
+
458
+ public function testLoadByInternalPath() {
459
+ $node = Node::create([
460
+ 'type' => 'page',
461
+ 'title' => 'Test page'
462
+ ]);
463
+ $node->save();
464
+ $metadata = $this->defaultCacheMetaData();
465
+ $metadata->addCacheTags(['node:1']);
466
+ $query = $this->getQueryFromFile('load-entity.gql');
467
+ $this->assertResults($query, ['input' => '/node/1:en'], [
468
+ '_loadPage' => [
469
+ 'title' => 'Test page',
470
+ ],
471
+ ], $metadata);
472
+ }
473
+
474
+ public function testLoadByAliasedPath() {
475
+ $node = Node::create([
476
+ 'type' => 'page',
477
+ 'title' => 'Test page'
478
+ ]);
479
+ $node->save();
480
+ $this->createPathAlias('/node/1', '/test');
481
+ $metadata = $this->defaultCacheMetaData();
482
+ $metadata->addCacheTags(['node:1']);
483
+ $query = $this->getQueryFromFile('load-entity.gql');
484
+ $this->assertResults($query, ['input' => '/test:en'], [
485
+ '_loadPage' => [
486
+ 'title' => 'Test page',
487
+ ],
488
+ ], $metadata);
489
+ }
490
+ }
@@ -0,0 +1,178 @@
1
+ <?php
2
+ namespace Drupal\Tests\silverback_gatsby\Kernel;
3
+
4
+ use Drupal\field\Entity\FieldConfig;
5
+ use Drupal\field\Entity\FieldStorageConfig;
6
+ use Drupal\graphql\Entity\Server;
7
+ use Drupal\node\Entity\NodeType;
8
+ use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
9
+
10
+ abstract class EntityFeedTestBase extends GraphQLTestBase {
11
+
12
+ protected $strictConfigSchema = FALSE;
13
+
14
+ protected static $modules = [
15
+ 'text',
16
+ 'path_alias',
17
+ 'graphql_directives',
18
+ 'silverback_gatsby',
19
+ 'silverback_gutenberg',
20
+ 'silverback_gatsby_example',
21
+ ];
22
+
23
+ /**
24
+ * A GraphQL server instance triggering updates for a public build server.
25
+ * @var \Drupal\graphql\Entity\Server|\Drupal\Core\Entity\EntityBase|\Drupal\Core\Entity\EntityInterface
26
+ */
27
+ protected $serverBuild;
28
+
29
+ /**
30
+ * A GraphQL server instance triggering updates for a preview server.
31
+ * @var \Drupal\graphql\Entity\Server|\Drupal\Core\Entity\EntityBase|\Drupal\Core\Entity\EntityInterface
32
+ */
33
+ protected $serverPreview;
34
+
35
+ /**
36
+ * A GraphQL server instance triggering updates for a preview server.
37
+ * @var \Drupal\graphql\Entity\Server|\Drupal\Core\Entity\EntityBase|\Drupal\Core\Entity\EntityInterface
38
+ */
39
+ protected $serverPublic;
40
+
41
+ /**
42
+ * Switch the test case to run queries against the build server.
43
+ */
44
+ protected function useBuildServer() {
45
+ $this->server = $this->serverBuild;
46
+ }
47
+
48
+ /**
49
+ * Switch the test case to run queries against the build server.
50
+ */
51
+ protected function usePreviewServer() {
52
+ $this->server = $this->serverPreview;
53
+ }
54
+
55
+ /**
56
+ * Switch the test case to run queries against the build server.
57
+ */
58
+ protected function usePublicServer() {
59
+ $this->server = $this->serverPublic;
60
+ }
61
+
62
+ protected function setUp(): void {
63
+ parent::setUp();
64
+ $this->installConfig('graphql_directives');
65
+ $this->installSchema('silverback_gatsby', ['gatsby_update_log']);
66
+
67
+ $schemaDefinition = \Drupal::moduleHandler()->getModule('silverback_gatsby')->getPath()
68
+ . '/modules/silverback_gatsby_example/graphql/silverback_gatsby_example.graphqls';
69
+
70
+ $userPreview = $this->createUser(['bypass node access']);
71
+ $this->serverPreview = Server::create([
72
+ 'schema' => 'directable',
73
+ 'name' => 'silverback_gatsby_preview',
74
+ 'endpoint' => '/gatsby-preview',
75
+ 'schema_configuration' => [
76
+ 'directable' => [
77
+ 'extensions' => [
78
+ 'silverback_gatsby' => 'silverback_gatsby'
79
+ ],
80
+ 'schema_definition' => $schemaDefinition,
81
+ 'autoload_contexts' => 'drupal',
82
+ 'build_webhook' => 'http://localhost:8001/__refresh',
83
+ 'update_webhook' => 'http://localhost:8001/__update',
84
+ 'user' => $userPreview->uuid(),
85
+ ]
86
+ ]
87
+ ]);
88
+ $this->serverPreview->save();
89
+
90
+ $userBuild = $this->createUser(['access content']);
91
+ $this->serverBuild = Server::create([
92
+ 'schema' => 'directable',
93
+ 'name' => 'silverback_gatsby_build',
94
+ 'endpoint' => '/gatsby',
95
+ 'schema_configuration' => [
96
+ 'directable' => [
97
+ 'extensions' => [
98
+ 'silverback_gatsby' => 'silverback_gatsby'
99
+ ],
100
+ 'schema_definition' => $schemaDefinition,
101
+ 'autoload_contexts' => 'drupal',
102
+ 'build_webhook' => 'http://localhost:8000/__rebuild',
103
+ 'user' => $userBuild->uuid(),
104
+ ]
105
+ ]
106
+ ]);
107
+ $this->serverBuild->save();
108
+
109
+ $userPublic = $this->createUser(['access content']);
110
+ $this->serverPublic = Server::create([
111
+ 'schema' => 'directable',
112
+ 'name' => 'silverback_gatsby_public',
113
+ 'endpoint' => '/gatsby-public',
114
+ 'schema_configuration' => [
115
+ 'directable' => [
116
+ 'extensions' => [
117
+ 'silverback_gatsby' => 'silverback_gatsby'
118
+ ],
119
+ 'schema_definition' => $schemaDefinition,
120
+ 'autoload_contexts' => 'drupal',
121
+ 'user' => $userPublic->uuid(),
122
+ ]
123
+ ]
124
+ ]);
125
+ $this->serverPublic->save();
126
+
127
+ // By default, we use the preview server, since unpublished nodes will only
128
+ // trigger updates there.
129
+ $this->usePreviewServer();
130
+
131
+ $pageType = NodeType::create(
132
+ [
133
+ 'type' => 'page',
134
+ 'name' => 'Page',
135
+ 'translatable' => TRUE,
136
+ ]
137
+ );
138
+ $pageType->save();
139
+
140
+ FieldStorageConfig::create([
141
+ 'field_name' => 'body',
142
+ 'entity_type' => 'node',
143
+ 'type' => 'text_long',
144
+ 'cardinality' => 1,
145
+ ])->save();
146
+
147
+ FieldConfig::create([
148
+ 'field_name' => 'body',
149
+ 'entity_type' => 'node',
150
+ 'bundle' => 'page',
151
+ 'label' => 'Body',
152
+ ])->save();
153
+
154
+ NodeType::create(
155
+ [
156
+ 'type' => 'blog',
157
+ 'name' => 'Blog',
158
+ 'translatable' => FALSE,
159
+ ]
160
+ )->save();
161
+
162
+ NodeType::create(
163
+ [
164
+ 'type' => 'article',
165
+ 'name' => 'Article',
166
+ 'translatable' => FALSE,
167
+ ]
168
+ )->save();
169
+
170
+ $this->container->get('content_translation.manager')->setEnabled(
171
+ 'node',
172
+ 'page',
173
+ TRUE
174
+ );
175
+
176
+ $this->container->get('silverback_gatsby.update_handler')->schemaCache = NULL;
177
+ }
178
+ }