Skip to content

Commit

Permalink
Added a new task for fetching the UUID of the graphql_consumer. This
Browse files Browse the repository at this point in the history
UUID is used while calling the GraphQL API.
  • Loading branch information
Dresse committed Nov 5, 2024
1 parent 95b7e09 commit 1a49f4f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ tasks:
cmds:
- cmd: task dev:cli -- drush default-content:export-module dpl_example_content

dev:dpl-go:get-graphql-credentials:
desc: Get the GraphQL credentials from the site
cmds:
- cmd: task dev:cli -- drush php-eval "dpl_consumers_print_consumer_credentials()"

ci:reset:
desc: Create CI setup in a clean state
cmds:
Expand Down
40 changes: 40 additions & 0 deletions web/modules/custom/dpl_consumers/dpl_consumers.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @file
* DPL consumers module.
*/

use Drupal\dpl_consumers\DplGraphqlConsumersConstants;

/**
* Function is used for printing out the consumer credentials to the console.
*/
function dpl_consumers_print_consumer_credentials() {

Check failure on line 13 in web/modules/custom/dpl_consumers/dpl_consumers.module

View workflow job for this annotation

GitHub Actions / Analyse code using PHPStan

Function dpl_consumers_print_consumer_credentials() has no return type specified.
$graphql_consumer_client_id = DplGraphqlConsumersConstants::GRAPHQL_CONSUMER_CLIENT_ID;
$consumer_uuid = dpl_consumers_get_consumer_uuid($graphql_consumer_client_id);
print_r('Consumer UUID: ' . $consumer_uuid);
}

/**
* Get consumer by Client ID.
*
* @return string
* The consumer UUID.
*/
function dpl_consumers_get_consumer_uuid(string $client_id): string {
try {

Check failure on line 26 in web/modules/custom/dpl_consumers/dpl_consumers.module

View workflow job for this annotation

GitHub Actions / Analyse code using PHPStan

Function dpl_consumers_get_consumer_uuid() should return string but return statement is missing.
$consumer = \Drupal::entityTypeManager()
->getStorage('consumer')
->loadByProperties(['client_id' => $client_id]);

if (!empty($consumer)) {
$consumer = reset($consumer);
return $consumer->uuid();

Check failure on line 33 in web/modules/custom/dpl_consumers/dpl_consumers.module

View workflow job for this annotation

GitHub Actions / Analyse code using PHPStan

Function dpl_consumers_get_consumer_uuid() should return string but returns string|null.
}
}
catch (\Exception $e) {
\Drupal::logger('dpl_consumers')->error($e->getMessage());
return 'Consumer not found.';
}
}

0 comments on commit 1a49f4f

Please sign in to comment.