-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1685 from danskernesdigitalebibliotek/DDFBRA-96-e…
…xtend-graphql-schema-with-go-config DDFBRA-96 extend GraphQL schema with go config
- Loading branch information
Showing
17 changed files
with
489 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
unilogin_api_endpoint: null | ||
unilogin_api_wellknown_endpoint: null | ||
unilogin_api_client_id: null | ||
unilogin_api_client_secret: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: "DPL GraphQL" | ||
type: module | ||
description: "Module used for handling graphql functionality." | ||
package: DPL | ||
core_version_requirement: ^10 || ^11 | ||
dependencies: | ||
- graphql:graphql | ||
- graphql_compose:graphql_compose | ||
- dpl_unilogin:dpl_unilogin |
136 changes: 136 additions & 0 deletions
136
...custom/dpl_graphql/src/Plugin/GraphQL/SchemaExtension/DplConfigurationSchemaExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_graphql\Plugin\GraphQL\SchemaExtension; | ||
|
||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
use Drupal\Core\Entity\EntityFieldManagerInterface; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Core\Extension\ModuleHandlerInterface; | ||
use Drupal\Core\Language\LanguageManagerInterface; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\dpl_unilogin\UniloginConfiguration; | ||
use Drupal\graphql\GraphQL\ResolverBuilder; | ||
use Drupal\graphql\GraphQL\ResolverRegistryInterface; | ||
use Drupal\graphql_compose\Plugin\GraphQL\SchemaExtension\ResolverOnlySchemaExtensionPluginBase; | ||
use Drupal\graphql_compose\Plugin\GraphQLComposeEntityTypeManager; | ||
use Drupal\graphql_compose\Plugin\GraphQLComposeFieldTypeManager; | ||
use Drupal\graphql_compose\Plugin\GraphQLComposeSchemaTypeManager; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* DPL configuration GraphQL schema extension. | ||
* | ||
* @SchemaExtension( | ||
* id = "dpl_configuration", | ||
* name = "DPL Configuration", | ||
* description = @Translation("DPL configuration schema extensions for GraphQL Compose."), | ||
* schema = "graphql_compose", | ||
* ) | ||
*/ | ||
class DplConfigurationSchemaExtension extends ResolverOnlySchemaExtensionPluginBase implements ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* DplConfigurationSchemaExtension constructor. | ||
* | ||
* @param array $configuration | ||
* The plugin configuration array. | ||
* @param string $pluginId | ||
* The plugin id. | ||
* @param array $pluginDefinition | ||
* The plugin definition array. | ||
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory | ||
* The config factory service. | ||
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager | ||
* The entity field manager service. | ||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager | ||
* The entity type manager service. | ||
* @param \Drupal\graphql_compose\Plugin\GraphQLComposeEntityTypeManager $gqlEntityTypeManager | ||
* The entity type plugin manager service. | ||
* @param \Drupal\graphql_compose\Plugin\GraphQLComposeFieldTypeManager $gqlFieldTypeManager | ||
* The field type plugin manager service. | ||
* @param \Drupal\graphql_compose\Plugin\GraphQLComposeSchemaTypeManager $gqlSchemaTypeManager | ||
* The schema type plugin manager service. | ||
* @param \Drupal\Core\Language\LanguageManagerInterface $languageManager | ||
* The language manager service. | ||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler | ||
* The module handler service. | ||
* @param \Drupal\dpl_unilogin\UniloginConfiguration $uniloginConfiguration | ||
* Unilogin configuration. | ||
*/ | ||
public function __construct( | ||
array $configuration, | ||
$pluginId, | ||
$pluginDefinition, | ||
protected ConfigFactoryInterface $configFactory, | ||
protected EntityFieldManagerInterface $entityFieldManager, | ||
protected EntityTypeManagerInterface $entityTypeManager, | ||
protected GraphQLComposeEntityTypeManager $gqlEntityTypeManager, | ||
protected GraphQLComposeFieldTypeManager $gqlFieldTypeManager, | ||
protected GraphQLComposeSchemaTypeManager $gqlSchemaTypeManager, | ||
protected LanguageManagerInterface $languageManager, | ||
protected ModuleHandlerInterface $moduleHandler, | ||
private UniloginConfiguration $uniloginConfiguration, | ||
) { | ||
parent::__construct( | ||
$configuration, | ||
$pluginId, | ||
$pluginDefinition, | ||
$configFactory, | ||
$entityFieldManager, | ||
$entityTypeManager, | ||
$gqlEntityTypeManager, | ||
$gqlFieldTypeManager, | ||
$gqlSchemaTypeManager, | ||
$languageManager, | ||
$moduleHandler | ||
); | ||
$this->configuration = $configuration; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('config.factory'), | ||
$container->get('entity_field.manager'), | ||
$container->get('entity_type.manager'), | ||
$container->get('graphql_compose.entity_type_manager'), | ||
$container->get('graphql_compose.field_type_manager'), | ||
$container->get('graphql_compose.schema_type_manager'), | ||
$container->get('language_manager'), | ||
$container->get('module_handler'), | ||
$container->get('dpl_unilogin.settings') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerResolvers(ResolverRegistryInterface $registry): void { | ||
|
||
$unilogin_config = [ | ||
'unilogin_api_url' => $this->uniloginConfiguration->getUniloginApiEndpoint(), | ||
'unilogin_api_wellknown_url' => $this->uniloginConfiguration->getUniloginApiWellknownEndpoint(), | ||
'unilogin_api_client_id' => $this->uniloginConfiguration->getUniloginApiClientId(), | ||
'unilogin_api_client_secret' => $this->uniloginConfiguration->getUniloginApiClientSecret(), | ||
]; | ||
|
||
// Check if UniLogin configuration is empty, and return NULL if it is. | ||
$unilogin_config_is_empty = (bool) array_filter(array_values($unilogin_config)); | ||
|
||
$builder = new ResolverBuilder(); | ||
|
||
$registry->addFieldResolver( | ||
type: 'Query', | ||
field: 'dplConfiguration', | ||
resolver: $builder->callback(fn() => [ | ||
'unilogin' => $unilogin_config_is_empty ? $unilogin_config : NULL, | ||
]) | ||
); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
web/modules/custom/dpl_graphql/src/Plugin/GraphQLCompose/SchemaType/DplConfigurationType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\dpl_graphql\Plugin\GraphQLCompose\SchemaType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeSchemaTypeBase; | ||
use GraphQL\Type\Definition\ObjectType; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeSchemaType( | ||
* id = "DplConfiguration", | ||
* ) | ||
*/ | ||
class DplConfigurationType extends GraphQLComposeSchemaTypeBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTypes(): array { | ||
$types = []; | ||
$types[] = new ObjectType([ | ||
'name' => $this->getPluginId(), | ||
'description' => (string) $this->t('DPL Configuration.'), | ||
'fields' => fn () => [ | ||
'unilogin' => ['type' => static::type('UniloginConfiguration')], | ||
], | ||
]); | ||
|
||
return $types; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getExtensions(): array { | ||
$extensions = parent::getExtensions(); | ||
$extensions[] = new ObjectType([ | ||
'name' => 'Query', | ||
'fields' => fn () => [ | ||
'dplConfiguration' => [ | ||
'type' => static::type($this->getPluginId()), | ||
'description' => (string) $this->t('DPL Configuration'), | ||
], | ||
], | ||
]); | ||
|
||
return $extensions; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...les/custom/dpl_graphql/src/Plugin/GraphQLCompose/SchemaType/UniloginConfigurationType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\dpl_graphql\Plugin\GraphQLCompose\SchemaType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeSchemaTypeBase; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeSchemaType( | ||
* id = "UniloginConfiguration", | ||
* ) | ||
*/ | ||
class UniloginConfigurationType extends GraphQLComposeSchemaTypeBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTypes(): array { | ||
$types = []; | ||
|
||
$types[] = new ObjectType([ | ||
'name' => $this->getPluginId(), | ||
'description' => (string) $this->t('List of DPL-Go Unilogin configuration.'), | ||
'fields' => fn () => [ | ||
'unilogin_api_url' => ['type' => Type::string()], | ||
'unilogin_api_wellknown_url' => ['type' => Type::string()], | ||
'unilogin_api_client_id' => ['type' => Type::string()], | ||
'unilogin_api_client_secret' => ['type' => Type::string()], | ||
], | ||
]); | ||
|
||
return $types; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: "DPL UniLogin" | ||
type: module | ||
description: "Module containing unilogin configuration" | ||
package: DPL | ||
core_version_requirement: ^10 || ^11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dpl_unilogin.settings_form: | ||
title: "UniLogin configuration" | ||
route_name: dpl_unilogin.settings | ||
description: "Change UniLogin configuration" | ||
parent: system.admin_config_services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
dpl_unilogin.settings: | ||
path: "/admin/config/services/unilogin-configuration" | ||
defaults: | ||
_form: '\Drupal\dpl_unilogin\Form\UniloginConfigurationForm' | ||
_title: "Unilogin configuration" | ||
requirements: | ||
_permission: "administer site configuration" | ||
options: | ||
_admin_route: TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
dpl_unilogin.settings: | ||
class: Drupal\dpl_unilogin\UniloginConfiguration | ||
arguments: ["@config.manager"] |
Oops, something went wrong.