-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide some plugins for GraphQL Compose module
- Loading branch information
Showing
9 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
modules/stanford_graphql/src/Plugin/GraphQLCompose/EntityType/Citation.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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\EntityType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeEntityTypeBase; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeEntityType( | ||
* id = "citation" | ||
* ) | ||
*/ | ||
class Citation extends GraphQLComposeEntityTypeBase { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
modules/stanford_graphql/src/Plugin/GraphQLCompose/EntityType/ConfigPage.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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\EntityType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeEntityTypeBase; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeEntityType( | ||
* id = "config_pages" | ||
* ) | ||
*/ | ||
class ConfigPage extends GraphQLComposeEntityTypeBase { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
modules/stanford_graphql/src/Plugin/GraphQLCompose/EntityType/LayoutLibrary.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\EntityType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeEntityTypeBase; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeEntityType( | ||
* id = "layout", | ||
* type_sdl = "LayoutLibrary" | ||
* ) | ||
*/ | ||
class LayoutLibrary extends GraphQLComposeEntityTypeBase { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
modules/stanford_graphql/src/Plugin/GraphQLCompose/EntityType/PolicyLog.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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\EntityType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeEntityTypeBase; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeEntityType( | ||
* id = "su_policy_log" | ||
* ) | ||
*/ | ||
class PolicyLog extends GraphQLComposeEntityTypeBase { | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
modules/stanford_graphql/src/Plugin/GraphQLCompose/FieldType/SmartDateItem.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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\FieldType; | ||
|
||
use Drupal\Core\Field\FieldItemInterface; | ||
use Drupal\graphql\GraphQL\Execution\FieldContext; | ||
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerItemInterface; | ||
use Drupal\graphql_compose\Plugin\GraphQL\DataProducer\FieldProducerTrait; | ||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeBase; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @GraphQLComposeFieldType( | ||
* id = "smartdate", | ||
* type_sdl = "SmartDateType", | ||
* ) | ||
*/ | ||
class SmartDateItem extends GraphQLComposeFieldTypeBase implements FieldProducerItemInterface{ | ||
|
||
use FieldProducerTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolveFieldItem(FieldItemInterface $item, FieldContext $context) { | ||
return [ | ||
'value' => $item->get('value')->getValue(), | ||
'end_value' => $item->get('end_value')->getValue(), | ||
'duration' => $item->get('duration')->getValue(), | ||
'rrule' => $item->get('rrule')->getValue(), | ||
'rrule_index' => $item->get('rrule_index')->getValue(), | ||
'timezone' => $item->get('timezone')->getValue(), | ||
]; | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
modules/stanford_graphql/src/Plugin/GraphQLCompose/SchemaType/LayoutLibrary.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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\SchemaType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeSchemaTypeBase; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeSchemaType( | ||
* id = "LayoutLibrary" | ||
* ) | ||
*/ | ||
class LayoutLibrary extends GraphQLComposeSchemaTypeBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTypes(): array { | ||
$types = []; | ||
|
||
$types[] = new ObjectType([ | ||
'name' => $this->getPluginId(), | ||
'description' => (string) $this->t('Layout Library entity.'), | ||
'fields' => fn() => [ | ||
'id' => [ | ||
'type' => Type::nonNull(Type::id()), | ||
'description' => (string) $this->t('Machine name of the layout definition.'), | ||
], | ||
'label' => [ | ||
'type' => Type::nonNull(Type::string()), | ||
'description' => (string) $this->t('Human readable name of the layout definition.'), | ||
], | ||
], | ||
]); | ||
|
||
return $types; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
modules/stanford_graphql/src/Plugin/GraphQLCompose/SchemaType/SmartDateType.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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\stanford_graphql\Plugin\GraphQLCompose\SchemaType; | ||
|
||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeSchemaTypeBase; | ||
use GraphQL\Type\Definition\ObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @GraphQLComposeSchemaType( | ||
* id = "SmartDateType" | ||
* ) | ||
*/ | ||
class SmartDateType extends GraphQLComposeSchemaTypeBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTypes(): array { | ||
$types = []; | ||
|
||
if (!$this->moduleHandler->moduleExists('smart_date')) { | ||
return []; | ||
} | ||
|
||
$types[] = new ObjectType([ | ||
'name' => $this->getPluginId(), | ||
'description' => (string) $this->t('Smart Date data.'), | ||
'fields' => fn() => [ | ||
'value' => [ | ||
'type' => Type::nonNull(static::type('Timestamp')), | ||
'description' => 'Start timestamp value', | ||
], | ||
'end_value' => [ | ||
'type' => Type::nonNull(static::type('Timestamp')), | ||
'description' => 'End timestamp value', | ||
], | ||
'duration' => [ | ||
'type' => Type::int(), | ||
'description' => 'Duration, in minutes', | ||
], | ||
'rrule' => [ | ||
'type' => Type::int(), | ||
'description' => 'RRule ID', | ||
], | ||
'rrule_index' => [ | ||
'type' => Type::int(), | ||
'description' => 'RRule Index', | ||
], | ||
'timezone' => [ | ||
'type' => Type::string(), | ||
'description' => 'Timezone', | ||
], | ||
], | ||
]); | ||
|
||
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,10 @@ | ||
name: 'Stanford GraphQL' | ||
type: module | ||
description: 'GraphQL helper.' | ||
core_version_requirement: ^9 || ^10 | ||
package: Stanford | ||
version: 9.4.1 | ||
dependencies: | ||
- graphql_compose:graphql_compose_layout_paragraphs | ||
- graphql_compose:graphql_compose_menus | ||
- graphql_compose:graphql_compose_views |
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,19 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* stanford_graphql.module | ||
*/ | ||
|
||
use Drupal\graphql\GraphQL\Execution\FieldContext; | ||
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeFieldTypeInterface; | ||
|
||
/** | ||
* Implements hook_graphql_compose_field_results_alter(). | ||
*/ | ||
function stanford_graphql_graphql_compose_field_results_alter(array &$results, $entity, GraphQLComposeFieldTypeInterface $plugin, FieldContext $context) { | ||
$field_definition = $plugin->getFieldDefinition(); | ||
if ($field_definition->getName() == 'layout_selection' && isset($results[0])) { | ||
$results = [['id' => $results[0]?->id(), 'label' => $results[0]?->label()]]; | ||
} | ||
} |