-
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 #1994 from danskernesdigitalebibliotek/DDFBRA-354-…
…graphql-query-i-dpl-cms-til-at-hente-library-user-tokens Add graphql query ro aquire tokens from Adgangsplatformen
- Loading branch information
Showing
10 changed files
with
206 additions
and
0 deletions.
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
1 change: 1 addition & 0 deletions
1
web/modules/custom/dpl_library_token/graphql/dpl_library_token.base.graphqls
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 @@ | ||
|
3 changes: 3 additions & 0 deletions
3
web/modules/custom/dpl_library_token/graphql/dpl_library_token.extension.graphqls
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,3 @@ | ||
extend type Adgangsplatformen { | ||
library: String | ||
} |
61 changes: 61 additions & 0 deletions
61
...l_library_token/src/Plugin/GraphQL/DataProducer/AdgangsplatformenLibraryTokenProducer.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,61 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_library_token\Plugin\GraphQL\DataProducer; | ||
|
||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\dpl_library_token\LibraryTokenHandler; | ||
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Exposes an Adgangsplatformen library token. | ||
* | ||
* If a token has been generated, it will be returned. Otherwise, | ||
* NULL is returned. | ||
* | ||
* @DataProducer( | ||
* id = "adgangsplatformen_library_token_producer", | ||
* name = "Adgangsplatformen Library Token Producer", | ||
* description = "Exposes access tokens.", | ||
* produces = @ContextDefinition("any", | ||
* label = "Request Response" | ||
* ) | ||
* ) | ||
*/ | ||
class AdgangsplatformenLibraryTokenProducer extends DataProducerPluginBase implements ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* Creates an instance of the producer using dependency injection. | ||
* | ||
* This method ensures the necessary services, such as the logger and importer | ||
* are available for processing the import request. | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get(id: 'dpl_library_token.handler'), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct( | ||
array $configuration, | ||
string $pluginId, | ||
mixed $pluginDefinition, | ||
protected LibraryTokenHandler $libraryTokenHandler, | ||
) { | ||
parent::__construct($configuration, $pluginId, $pluginDefinition); | ||
} | ||
|
||
/** | ||
* Resolves the library access token. | ||
*/ | ||
public function resolve(): string | null { | ||
return $this->libraryTokenHandler->getToken(); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
.../custom/dpl_library_token/src/Plugin/GraphQL/SchemaExtension/DplLibraryTokenExtension.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,31 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_library_token\Plugin\GraphQL\SchemaExtension; | ||
|
||
use Drupal\graphql\GraphQL\ResolverBuilder; | ||
use Drupal\graphql\GraphQL\ResolverRegistryInterface; | ||
use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase; | ||
|
||
/** | ||
* Dpl Token functionality. | ||
* | ||
* @SchemaExtension( | ||
* id = "dpl_library_token", | ||
* name = "Dpl Library Token extension", | ||
* description = "Adding library token to the Dpl Token query.", | ||
* schema = "graphql_compose" | ||
* ) | ||
*/ | ||
class DplLibraryTokenExtension extends SdlSchemaExtensionPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerResolvers(ResolverRegistryInterface $registry): void { | ||
$builder = new ResolverBuilder(); | ||
$registry->addFieldResolver('Adgangsplatformen', 'library', | ||
$builder->produce('adgangsplatformen_library_token_producer') | ||
); | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
web/modules/custom/dpl_login/graphql/dpl_tokens.base.graphqls
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,8 @@ | ||
|
||
type Adgangsplatformen { | ||
user: String | ||
} | ||
|
||
type DplTokens { | ||
adgangsplatformen: Adgangsplatformen | ||
} |
4 changes: 4 additions & 0 deletions
4
web/modules/custom/dpl_login/graphql/dpl_tokens.extension.graphqls
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 @@ | ||
|
||
extend type Query { | ||
dplTokens: DplTokens | ||
} |
61 changes: 61 additions & 0 deletions
61
...s/custom/dpl_login/src/Plugin/GraphQL/DataProducer/AdgangsplatformenUserTokenProducer.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,61 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_login\Plugin\GraphQL\DataProducer; | ||
|
||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Drupal\dpl_login\UserTokens; | ||
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Exposes an Adgangsplatformen user token. | ||
* | ||
* If a patron has been authenticated an access token should be available. | ||
* Otherwise NULL is returned. | ||
* | ||
* @DataProducer( | ||
* id = "adgangsplatformen_user_token_producer", | ||
* name = "Adgangsplatformen User Token Producer", | ||
* description = "Exposes user access tokens.", | ||
* produces = @ContextDefinition("any", | ||
* label = "Request Response" | ||
* ) | ||
* ) | ||
*/ | ||
class AdgangsplatformenUserTokenProducer extends DataProducerPluginBase implements ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* Creates an instance of the producer using dependency injection. | ||
* | ||
* This method ensures the necessary services, such as the logger and importer | ||
* are available for processing the import request. | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('dpl_login.user_tokens'), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct( | ||
array $configuration, | ||
string $pluginId, | ||
mixed $pluginDefinition, | ||
protected UserTokens $userTokens, | ||
) { | ||
parent::__construct($configuration, $pluginId, $pluginDefinition); | ||
} | ||
|
||
/** | ||
* Resolves the access token based on the token type. | ||
*/ | ||
public function resolve(): string | null { | ||
return $this->userTokens->getCurrent()?->token; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
web/modules/custom/dpl_login/src/Plugin/GraphQL/SchemaExtension/DplTokensExtension.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,34 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_login\Plugin\GraphQL\SchemaExtension; | ||
|
||
use Drupal\graphql\GraphQL\ResolverBuilder; | ||
use Drupal\graphql\GraphQL\ResolverRegistryInterface; | ||
use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase; | ||
|
||
/** | ||
* Dpl Token functionality. | ||
* | ||
* @SchemaExtension( | ||
* id = "dpl_tokens", | ||
* name = "Dpl Tokens extension", | ||
* description = "Adding Dpl Token functionality.", | ||
* schema = "graphql_compose" | ||
* ) | ||
*/ | ||
class DplTokensExtension extends SdlSchemaExtensionPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function registerResolvers(ResolverRegistryInterface $registry): void { | ||
$builder = new ResolverBuilder(); | ||
$registry->addFieldResolver('Query', 'dplTokens', $builder->callback(fn () => TRUE)); | ||
$registry->addFieldResolver('DplTokens', 'adgangsplatformen', $builder->callback(fn () => TRUE)); | ||
$registry->addFieldResolver('Adgangsplatformen', 'user', | ||
$builder->produce('adgangsplatformen_user_token_producer') | ||
); | ||
|
||
} | ||
|
||
} |