@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,180 @@
1
+ <?php
2
+ /**
3
+ * Implements hook_schema().
4
+ */
5
+ function silverback_gatsby_schema() {
6
+ $schema['gatsby_update_log'] = [
7
+ 'description' => 'Table that contains logs of all system events.',
8
+ 'fields' => [
9
+ 'id' => [
10
+ 'type' => 'serial',
11
+ 'not null' => TRUE,
12
+ 'description' => 'Primary Key: Unique update id.',
13
+ ],
14
+ 'server' => [
15
+ 'type' => 'varchar_ascii',
16
+ 'length' => 64,
17
+ 'not null' => TRUE,
18
+ 'default' => '',
19
+ 'description' => 'The id of the related GraphQL server.',
20
+ ],
21
+ 'type' => [
22
+ 'type' => 'varchar_ascii',
23
+ 'length' => 64,
24
+ 'not null' => TRUE,
25
+ 'default' => '',
26
+ 'description' => 'The GraphQL type that changed.',
27
+ ],
28
+ 'object_id' => [
29
+ 'type' => 'varchar_ascii',
30
+ 'length' => 64,
31
+ 'not null' => TRUE,
32
+ 'default' => '',
33
+ 'description' => 'The id of the Graph object that changed.',
34
+ ],
35
+ 'uid' => [
36
+ 'type' => 'int',
37
+ 'unsigned' => TRUE,
38
+ 'not null' => TRUE,
39
+ 'default' => 0,
40
+ 'description' => 'The {users}.uid of the user who triggered the update.',
41
+ ],
42
+ 'timestamp' => [
43
+ 'type' => 'int',
44
+ 'not null' => TRUE,
45
+ 'default' => 0,
46
+ 'description' => 'Unix timestamp when the update happened.',
47
+ ],
48
+ ],
49
+ 'primary key' => ['id'],
50
+ 'indexes' => [
51
+ 'server' => ['server'],
52
+ 'object_id' => ['object_id'],
53
+ ],
54
+ ];
55
+
56
+ return $schema;
57
+ }
58
+
59
+ /**
60
+ * Add index to "server" field on the "gatsby_update_log" database table.
61
+ */
62
+ function silverback_gatsby_update_8001() {
63
+ $table = 'gatsby_update_log';
64
+ $tableSpec = [
65
+ 'description' => 'Table that contains logs of all system events.',
66
+ 'fields' => [
67
+ 'id' => [
68
+ 'type' => 'serial',
69
+ 'not null' => TRUE,
70
+ 'description' => 'Primary Key: Unique update id.',
71
+ ],
72
+ 'server' => [
73
+ 'type' => 'varchar_ascii',
74
+ 'length' => 64,
75
+ 'not null' => TRUE,
76
+ 'default' => '',
77
+ 'description' => 'The id of the related GraphQL server.',
78
+ ],
79
+ 'type' => [
80
+ 'type' => 'varchar_ascii',
81
+ 'length' => 64,
82
+ 'not null' => TRUE,
83
+ 'default' => '',
84
+ 'description' => 'The GraphQL type that changed.',
85
+ ],
86
+ 'object_id' => [
87
+ 'type' => 'varchar_ascii',
88
+ 'length' => 64,
89
+ 'not null' => TRUE,
90
+ 'default' => '',
91
+ 'description' => 'The id of the Graph object that changed.',
92
+ ],
93
+ 'uid' => [
94
+ 'type' => 'int',
95
+ 'unsigned' => TRUE,
96
+ 'not null' => TRUE,
97
+ 'default' => 0,
98
+ 'description' => 'The {users}.uid of the user who triggered the update.',
99
+ ],
100
+ 'timestamp' => [
101
+ 'type' => 'int',
102
+ 'not null' => TRUE,
103
+ 'default' => 0,
104
+ 'description' => 'Unix timestamp when the update happened.',
105
+ ],
106
+ ],
107
+ 'primary key' => ['id'],
108
+ 'indexes' => [
109
+ 'server' => ['server'],
110
+ ],
111
+ ];
112
+ $index = 'server';
113
+ $indexFields = ['server'];
114
+ $schema = \Drupal::database()->schema();
115
+ if (!$schema->indexExists($table, $index)) {
116
+ $schema->addIndex($table, $index, $indexFields, $tableSpec);
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Add index to "object_id" field on the "gatsby_update_log" database table.
122
+ */
123
+ function silverback_gatsby_update_8002() {
124
+ $table = 'gatsby_update_log';
125
+ $tableSpec = [
126
+ 'description' => 'Table that contains logs of all system events.',
127
+ 'fields' => [
128
+ 'id' => [
129
+ 'type' => 'serial',
130
+ 'not null' => TRUE,
131
+ 'description' => 'Primary Key: Unique update id.',
132
+ ],
133
+ 'server' => [
134
+ 'type' => 'varchar_ascii',
135
+ 'length' => 64,
136
+ 'not null' => TRUE,
137
+ 'default' => '',
138
+ 'description' => 'The id of the related GraphQL server.',
139
+ ],
140
+ 'type' => [
141
+ 'type' => 'varchar_ascii',
142
+ 'length' => 64,
143
+ 'not null' => TRUE,
144
+ 'default' => '',
145
+ 'description' => 'The GraphQL type that changed.',
146
+ ],
147
+ 'object_id' => [
148
+ 'type' => 'varchar_ascii',
149
+ 'length' => 64,
150
+ 'not null' => TRUE,
151
+ 'default' => '',
152
+ 'description' => 'The id of the Graph object that changed.',
153
+ ],
154
+ 'uid' => [
155
+ 'type' => 'int',
156
+ 'unsigned' => TRUE,
157
+ 'not null' => TRUE,
158
+ 'default' => 0,
159
+ 'description' => 'The {users}.uid of the user who triggered the update.',
160
+ ],
161
+ 'timestamp' => [
162
+ 'type' => 'int',
163
+ 'not null' => TRUE,
164
+ 'default' => 0,
165
+ 'description' => 'Unix timestamp when the update happened.',
166
+ ],
167
+ ],
168
+ 'primary key' => ['id'],
169
+ 'indexes' => [
170
+ 'server' => ['server'],
171
+ 'object_id' => ['object_id'],
172
+ ],
173
+ ];
174
+ $index = 'object_id';
175
+ $indexFields = ['object_id'];
176
+ $schema = \Drupal::database()->schema();
177
+ if (!$schema->indexExists($table, $index)) {
178
+ $schema->addIndex($table, $index, $indexFields, $tableSpec);
179
+ }
180
+ }
@@ -0,0 +1,6 @@
1
+ entity.graphql_server.build_form:
2
+ route_name: entity.graphql_server.build_form
3
+ base_route: entity.graphql_server.edit_form
4
+ title: Build
5
+ title_context: silverback_gatsby
6
+ weight: -1
@@ -0,0 +1,119 @@
1
+ <?php
2
+
3
+ use Drupal\Core\Entity\EntityInterface;
4
+ use Drupal\silverback_gatsby\Plugin\Gatsby\Feed\EntityFeed;
5
+ use Drupal\user\UserInterface;
6
+
7
+
8
+ function _silverback_gatsby_entity_event(EntityInterface $entity) {
9
+ /** @var \Drupal\silverback_gatsby\GatsbyUpdateHandler $updateHandler */
10
+ $updateHandler = \Drupal::service('silverback_gatsby.update_handler');
11
+ $updateHandler->handle(EntityFeed::class, $entity);
12
+
13
+ if (\Drupal::hasService('entity_usage.usage')) {
14
+ /** @var \Drupal\entity_usage\EntityUsage $entityUsage */
15
+ $entityUsage = \Drupal::service('entity_usage.usage');
16
+ foreach ($entityUsage->listSources($entity) as $sourceEntityType => $sources) {
17
+ $entities = \Drupal::entityTypeManager()
18
+ ->getStorage($sourceEntityType)
19
+ ->loadMultiple(array_keys($sources));
20
+ foreach ($entities as $source) {
21
+ $updateHandler->handle(EntityFeed::class, $source);
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Implements hook_entity_insert().
29
+ */
30
+ function silverback_gatsby_entity_insert(EntityInterface $entity) {
31
+ _silverback_gatsby_entity_event($entity);
32
+ }
33
+
34
+ /**
35
+ * Implements hook_entity_presave().
36
+ */
37
+ function silverback_gatsby_entity_presave(EntityInterface $entity) {
38
+ if (!empty($entity->original)) {
39
+ _silverback_gatsby_entity_event($entity->original);
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Implements hook_entity_update().
45
+ */
46
+ function silverback_gatsby_entity_update(EntityInterface $entity) {
47
+ \Drupal::entityTypeManager()
48
+ ->getAccessControlHandler($entity->getEntityTypeId())
49
+ ->resetCache();
50
+ _silverback_gatsby_entity_event($entity);
51
+ }
52
+
53
+ /**
54
+ * Implements hook_entity_predelete().
55
+ */
56
+ function silverback_gatsby_entity_predelete(EntityInterface $entity) {
57
+ _silverback_gatsby_entity_event($entity);
58
+ }
59
+
60
+ /**
61
+ * Implements hook_module_implements_alter().
62
+ */
63
+ function silverback_gatsby_module_implements_alter(&$implementations, $hook) {
64
+ // Act before entity_usage module.
65
+ if (in_array($hook, ['entity_insert', 'entity_update', 'entity_predelete'], TRUE)) {
66
+ $implementations = [
67
+ 'silverback_gatsby' => $implementations['silverback_gatsby'],
68
+ ] + $implementations;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Implements hook_entity_type_alter().
74
+ */
75
+ function silverback_gatsby_entity_type_alter(array &$entity_types) {
76
+ /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
77
+ foreach ($entity_types as $entity_type) {
78
+ if ($entity_type->id() === 'graphql_server') {
79
+ if (!$entity_type->hasHandlerClass('build')) {
80
+ $entity_type->setHandlerClass(
81
+ 'build',
82
+ Drupal\silverback_gatsby\GraphQL\Build::class
83
+ );
84
+ }
85
+ if (!$entity_type->getFormClass('build')) {
86
+ $entity_type->setFormClass(
87
+ 'build',
88
+ Drupal\silverback_gatsby\GraphQL\Build::class
89
+ );
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Implements hook_user_login().
97
+ */
98
+ function silverback_gatsby_user_login(UserInterface $account) {
99
+ // Write a javascript-accessible cookie that tells the frontend if the user is
100
+ // authenticated, so it can make additional requests based on that information.
101
+ $opts = \Drupal::getContainer()->getParameter('session.storage.options');
102
+ if (isset($opts['cookie_domain'])) {
103
+ $expires = isset($opts['cookie_lifetime'])
104
+ ? \Drupal::time()->getRequestTime() + $opts['cookie_lifetime']
105
+ : 0;
106
+ setcookie('drupal_user', $account->id(), $expires, '/', $opts['cookie_domain'], false, false);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Implements hook_user_logout().
112
+ */
113
+ function silverback_gatsby_user_logout() {
114
+ // Unset the frontend user-indicator cookie.
115
+ unset($_COOKIE['drupal_user']);
116
+ $opts = \Drupal::getContainer()->getParameter('session.storage.options');
117
+ $expires = \Drupal::time()->getRequestTime() - 3600;
118
+ setcookie('drupal_user', '', $expires, '/', $opts['cookie_domain'] ?? '', false, false);
119
+ }
@@ -0,0 +1,8 @@
1
+ view publisher status:
2
+ title: 'View Publisher status'
3
+ trigger a gatsby build:
4
+ title: 'Trigger a Gatsby Build'
5
+ access publisher:
6
+ title: 'Access Publisher'
7
+ fetch any autosaved entity:
8
+ title: 'Fetch any autosaved entity'
@@ -0,0 +1,15 @@
1
+ <?php
2
+
3
+ use Drupal\user\Entity\Role;
4
+
5
+ /**
6
+ * Introduce "view publisher status" permission.
7
+ */
8
+ function silverback_gatsby_post_update_introduce_view_publisher_status_permission(&$sandbox): void {
9
+ foreach (Role::loadMultiple() as $role) {
10
+ // The status was visible for everyone who could see the toolbar.
11
+ if ($role->hasPermission('access toolbar')) {
12
+ $role->grantPermission('view publisher status')->save();
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,28 @@
1
+ entity.graphql_server.build_form:
2
+ path: '/admin/config/graphql/servers/build/{graphql_server}'
3
+ defaults:
4
+ _entity_form: 'graphql_server.build'
5
+ _title: 'Build'
6
+ _title_context: silverback_gatsby
7
+ requirements:
8
+ _permission: 'administer graphql configuration+trigger a gatsby build'
9
+ options:
10
+ _admin_route: TRUE
11
+ silverback_gatsby.build:
12
+ path: '/silverback_gatsby/ajax/build'
13
+ defaults:
14
+ _controller: '\Drupal\silverback_gatsby\Controller\BuildController::build'
15
+ requirements:
16
+ _permission: 'trigger a gatsby build'
17
+ publisher.access:
18
+ path: '/publisher/access'
19
+ defaults:
20
+ _controller: '\Drupal\silverback_gatsby\Controller\PublisherController::hasAccess'
21
+ methods: [POST]
22
+ requirements:
23
+ # Required for the refresh token.
24
+ _access: 'TRUE'
25
+ _format: 'json'
26
+ options:
27
+ _auth: ['oauth2']
28
+ no_cache: TRUE
@@ -0,0 +1,50 @@
1
+ services:
2
+ silverback_gatsby.feed_manager:
3
+ class: Drupal\silverback_gatsby\Plugin\FeedPluginManager
4
+ arguments:
5
+ - 'Plugin/Gatsby/Feed'
6
+ - '@container.namespaces'
7
+ - '@module_handler'
8
+ - '\Drupal\silverback_gatsby\Plugin\FeedInterface'
9
+ - '\Drupal\silverback_gatsby\Annotation\GatsbyFeed'
10
+
11
+ silverback_gatsby.build_trigger:
12
+ class: Drupal\silverback_gatsby\GatsbyBuildTrigger
13
+ arguments:
14
+ - '@http_client'
15
+ - '@messenger'
16
+ - '@entity_type.manager'
17
+
18
+ silverback_gatsby.update_trigger:
19
+ class: Drupal\silverback_gatsby\GatsbyUpdateTrigger
20
+ arguments:
21
+ - '@http_client'
22
+ - '@messenger'
23
+ - '@entity_type.manager'
24
+
25
+ silverback_gatsby.update_tracker:
26
+ class: Drupal\silverback_gatsby\GatsbyUpdateTracker
27
+ arguments:
28
+ ['@database', '@current_user', '@silverback_gatsby.build_trigger']
29
+
30
+ silverback_gatsby.update_handler:
31
+ class: Drupal\silverback_gatsby\GatsbyUpdateHandler
32
+ arguments:
33
+ - '@entity_type.manager'
34
+ - '@silverback_gatsby.update_tracker'
35
+ - '@silverback_gatsby.update_trigger'
36
+
37
+ silverback_gatsby.menu_tree_storage:
38
+ class: Drupal\silverback_gatsby\MenuTreeStorageDecorator
39
+ decorates: menu.tree_storage
40
+ public: false
41
+ arguments:
42
+ [
43
+ '@silverback_gatsby.menu_tree_storage.inner',
44
+ '@silverback_gatsby.update_handler',
45
+ ]
46
+
47
+ silverback_gatsby.reverse_proxy_middleware:
48
+ class: Drupal\silverback_gatsby\SilverbackReverseProxyMiddleware
49
+ tags:
50
+ - { name: http_middleware, priority: 500 }
@@ -0,0 +1,41 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_gatsby\Annotation;
4
+
5
+ use Doctrine\Common\Annotations\AnnotationException;
6
+ use Drupal\Component\Annotation\Plugin;
7
+
8
+ /**
9
+ * Annotation for Gatsby GraphQL data feeds.
10
+ *
11
+ * @Annotation
12
+ * @codeCoverageIgnore
13
+ */
14
+ class GatsbyFeed extends Plugin {
15
+
16
+ /**
17
+ * The plugin ID.
18
+ *
19
+ * It also serves as the handle for the GraphQL directive.
20
+ *
21
+ * @var string
22
+ */
23
+ public $id;
24
+
25
+ /**
26
+ * Feed constructor.
27
+ *
28
+ * @param mixed $values
29
+ * The plugin annotation values.
30
+ *
31
+ * @throws \Doctrine\Common\Annotations\AnnotationException
32
+ * In case of missing required values.
33
+ */
34
+ public function __construct($values) {
35
+ if (!array_key_exists('id', $values) || !$values['id']) {
36
+ throw new AnnotationException('The plugin is missing an "id" property.');
37
+ }
38
+ parent::__construct($values);
39
+ }
40
+
41
+ }
@@ -0,0 +1,102 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_gatsby\Commands;
4
+
5
+ use Drupal\Component\Plugin\PluginManagerInterface;
6
+ use Drupal\Core\Entity\EntityTypeManagerInterface;
7
+ use Drupal\graphql_directives\Plugin\GraphQL\Schema\DirectableSchema;
8
+ use Drupal\silverback_gatsby\GatsbyBuildTriggerInterface;
9
+ use Drush\Commands\DrushCommands;
10
+ use GraphQL\Language\Printer;
11
+
12
+ /**
13
+ * A Drush commandfile.
14
+ *
15
+ * In addition to this file, you need a drush.services.yml
16
+ * in root of your module, and a composer.json file that provides the name
17
+ * of the services file to use.
18
+ *
19
+ * See these files for an example of injecting Drupal services:
20
+ * - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
21
+ * - http://cgit.drupalcode.org/devel/tree/drush.services.yml
22
+ */
23
+ class SilverbackGatsbyCommands extends DrushCommands {
24
+
25
+ protected EntityTypeManagerInterface $entityTypeManager;
26
+ protected PluginManagerInterface $schemaPluginManager;
27
+ protected GatsbyBuildTriggerInterface $buildTrigger;
28
+
29
+ public function __construct(
30
+ EntityTypeManagerInterface $entityTypeManager,
31
+ PluginManagerInterface $schemaPluginManager,
32
+ GatsbyBuildTriggerInterface $buildTrigger
33
+ ) {
34
+ parent::__construct();
35
+ $this->entityTypeManager = $entityTypeManager;
36
+ $this->schemaPluginManager = $schemaPluginManager;
37
+ $this->buildTrigger = $buildTrigger;
38
+ }
39
+
40
+ /**
41
+ * Export composable schema definitions.
42
+ *
43
+ * @param string $folder
44
+ * Folder path to store the exported schema in.
45
+ *
46
+ * @command silverback-gatsby:schema-export
47
+ * @aliases sgse
48
+ */
49
+ public function schemaExport($folder = '../generated') {
50
+ if (!is_dir($folder)) {
51
+ mkdir($folder, 0777, true);
52
+ }
53
+ $servers = $this->entityTypeManager->getStorage('graphql_server')->loadMultiple();
54
+ foreach ($servers as $server) {
55
+ /** @var $server \Drupal\graphql\Entity\Server */
56
+ $config = $server->get('schema_configuration');
57
+ /** @var \Drupal\graphql\Plugin\SchemaPluginInterface $schema */
58
+ $schema = $this->schemaPluginManager->createInstance($server->schema, $config[$server->schema]);
59
+ if (!$schema instanceof DirectableSchema) {
60
+ continue;
61
+ }
62
+ $path = $folder . '/' . $server->id() . '.composed.graphqls';
63
+ $this->logger->success(dt('Writing definition of %id to %path', [
64
+ '%id' => $server->id(),
65
+ '%path' => $path,
66
+ ]));
67
+ $extensions = $schema->getExtensions();
68
+ $schemaDocument = $schema->getSchemaDocument($extensions);
69
+ $extensionDocument = $schema->getExtensionDocument($extensions);
70
+ file_put_contents($path, implode("\n", [
71
+ Printer::doPrint($schemaDocument),
72
+ Printer::doPrint($extensionDocument),
73
+ ]));
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Trigger a Gatsby build for a given GraphQL server.
79
+ *
80
+ * @param string $server
81
+ * The server id.
82
+ *
83
+ * @option force
84
+ * Force a build even if the frontend is already up-to-date.
85
+ *
86
+ * @command silverback-gatsby:build
87
+ * @aliases sgb
88
+ * @usage silverback-gatsby:build [server_id]
89
+ */
90
+ public function triggerBuild($server, $options = ['force' => FALSE]) {
91
+ if ($options['force']) {
92
+ /** @var \Drupal\silverback_gatsby\GatsbyUpdateTrackerInterface $updateTracker */
93
+ $updateTracker = \Drupal::service('silverback_gatsby.update_tracker');
94
+ $latestBuildId = $updateTracker->latestBuild($server);
95
+ $this->buildTrigger->trigger($server, $latestBuildId);
96
+ }
97
+ else {
98
+ $this->buildTrigger->triggerLatestBuild($server);
99
+ }
100
+ }
101
+
102
+ }
@@ -0,0 +1,45 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_gatsby\Controller;
4
+
5
+ use Drupal\Core\Controller\ControllerBase;
6
+ use Drupal\Core\Ajax\AjaxResponse;
7
+ use Drupal\Core\Ajax\AlertCommand;
8
+ use Drupal\silverback_gatsby\GatsbyBuildTriggerInterface;
9
+ use Symfony\Component\DependencyInjection\ContainerInterface;
10
+
11
+ class BuildController extends ControllerBase {
12
+
13
+ protected GatsbyBuildTriggerInterface $buildTrigger;
14
+
15
+ /**
16
+ * Constructs a BuildController object.
17
+ *
18
+ * @param \Drupal\silverback_gatsby\GatsbyBuildTriggerInterface $buildTrigger
19
+ */
20
+ public function __construct(GatsbyBuildTriggerInterface $buildTrigger) {
21
+ $this->buildTrigger = $buildTrigger;
22
+ }
23
+
24
+ /**
25
+ * {@inheritdoc}
26
+ */
27
+ public static function create(ContainerInterface $container) {
28
+ return new static(
29
+ $container->get('silverback_gatsby.build_trigger'),
30
+ );
31
+ }
32
+
33
+ /**
34
+ * Triggers a Gatsby build for the default GraphQL server.
35
+ *
36
+ * @return \Drupal\Core\Ajax\AjaxResponse
37
+ */
38
+ public function build() {
39
+ $response = new AjaxResponse();
40
+ $message = $this->buildTrigger->triggerDefaultServerLatestBuild();
41
+ $response->addCommand(new AlertCommand($message));
42
+ return $response;
43
+ }
44
+
45
+ }
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_gatsby\Controller;
4
+
5
+ use Drupal\Core\Controller\ControllerBase;
6
+ use Drupal\user\Entity\User;
7
+ use Symfony\Component\HttpFoundation\JsonResponse;
8
+
9
+ class PublisherController extends ControllerBase {
10
+
11
+ /**
12
+ * Checks if the current user has access to Publisher.
13
+ */
14
+ public function hasAccess() {
15
+ // This is the TokenAuthUser.
16
+ // The Publisher role is not assigned to the user,
17
+ // it is only used to scope the consumer.
18
+ /** @var \Drupal\Core\Session\AccountProxyInterface $user */
19
+ $userAccount = $this->currentUser();
20
+ // Verify permission against User entity.
21
+ $userEntity = User::load($userAccount->id());
22
+ if ($userEntity->hasPermission('access publisher')) {
23
+ return new JsonResponse([
24
+ 'access' => TRUE,
25
+ ], 200);
26
+ }
27
+ else {
28
+ return new JsonResponse([
29
+ 'access' => FALSE,
30
+ ], 403);
31
+ }
32
+ }
33
+
34
+ }
@@ -0,0 +1,51 @@
1
+ <?php
2
+
3
+ namespace Drupal\silverback_gatsby;
4
+
5
+ use Drupal\graphql\GraphQL\Resolver\ResolverInterface;
6
+ use Drupal\graphql\GraphQL\ResolverBuilder;
7
+
8
+ /**
9
+ * Custom directives for silverback compatibility.
10
+ */
11
+ class Directives {
12
+
13
+ /**
14
+ * Retrieve image properties.
15
+ */
16
+ public static function imageProps(ResolverBuilder $builder) : ResolverInterface {
17
+ return $builder->produce('image_props')
18
+ ->map('entity', $builder->fromParent());
19
+ }
20
+
21
+ /**
22
+ * Attach focal point information to image properties.
23
+ */
24
+ public static function focalPoint(ResolverBuilder $builder) : ResolverInterface {
25
+ return $builder->produce('focal_point')
26
+ ->map('image_props', $builder->fromParent());
27
+ }
28
+
29
+ /**
30
+ * Fetch an entity.
31
+ */
32
+ public static function fetchEntity(ResolverBuilder $builder): ResolverInterface {
33
+ $resolver = $builder->produce('fetch_entity')
34
+ ->map('type', $builder->fromArgument('type'))
35
+ ->map('id', $builder->fromArgument('id'));
36
+
37
+ $argsMap = [
38
+ 'revision_id' => 'rid',
39
+ 'language' => 'language',
40
+ 'access_operation' => 'operation',
41
+ 'load_latest_revision' => 'loadLatestRevision',
42
+ ];
43
+ foreach ($argsMap as $argParameter => $argField) {
44
+ if ($op = $builder->fromArgument($argField)) {
45
+ $resolver->map($argParameter, $op);
46
+ }
47
+ }
48
+ return $resolver;
49
+ }
50
+
51
+ }