Skip to content

Commit

Permalink
Merge pull request #1685 from danskernesdigitalebibliotek/DDFBRA-96-e…
Browse files Browse the repository at this point in the history
…xtend-graphql-schema-with-go-config

DDFBRA-96 extend GraphQL schema with go config
  • Loading branch information
Dresse authored Oct 31, 2024
2 parents dab077e + c66a1e4 commit 4ac2ab4
Show file tree
Hide file tree
Showing 17 changed files with 489 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ tasks:
drush user:create patron --password="$PR_DRUPAL_PWD"
drush user:role:add 'patron' patron
drush user:create graphql_consumer --password="$PR_DRUPAL_PWD"
drush user:role:add 'graphql_consumer' graphql_consumer
else
echo "Test users already exist. Skipping creation..."
fi
Expand Down
4 changes: 4 additions & 0 deletions assets/all.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
// because the user pulling in the changes won't have permissions to modify
// files in the directory.
$settings['skip_permissions_hardening'] = TRUE;

// Set default Unilogin configuration on non-production environments.
$config['dpl_unilogin.settings']['unilogin_api_endpoint'] = 'https://et-broker.unilogin.dk';
$config['dpl_unilogin.settings']['unilogin_api_wellknown_endpoint'] = 'https://et-broker.unilogin.dk/auth/realms/broker/.well-known/openid-configuration';
}

// Setup Redis.
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/sync/config_ignore.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ignored_config_entities:
- dpl_publizon.settings
- dpl_recommender.settings
- dpl_reservations.settings
- dpl_unilogin.settings
- dpl_url_proxy.settings
- novel.settings
- openid_connect.settings.adgangsplatformen
Expand Down
2 changes: 2 additions & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module:
dpl_fees: 0
dpl_filter_paragraphs: 0
dpl_footer: 0
dpl_graphql: 0
dpl_instant_loan: 0
dpl_library_agency: 0
dpl_library_token: 0
Expand Down Expand Up @@ -77,6 +78,7 @@ module:
dpl_static_content_20240404_opening_hours: 0
dpl_static_content_20240418_views_aliases: 0
dpl_static_content_20240422_contact_page: 0
dpl_unilogin: 0
dpl_update: 0
dpl_url_proxy: 0
dpl_webform: 0
Expand Down
4 changes: 4 additions & 0 deletions config/sync/dpl_unilogin.settings.yml
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
9 changes: 9 additions & 0 deletions web/modules/custom/dpl_graphql/dpl_graphql.info.yml
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
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,
])
);
}

}
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;
}

}
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;
}

}
5 changes: 5 additions & 0 deletions web/modules/custom/dpl_unilogin/dpl_unilogin.info.yml
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
5 changes: 5 additions & 0 deletions web/modules/custom/dpl_unilogin/dpl_unilogin.links.menu.yml
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
9 changes: 9 additions & 0 deletions web/modules/custom/dpl_unilogin/dpl_unilogin.routing.yml
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
4 changes: 4 additions & 0 deletions web/modules/custom/dpl_unilogin/dpl_unilogin.services.yml
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"]
Loading

0 comments on commit 4ac2ab4

Please sign in to comment.