|
@@ -7,7 +7,7 @@ use Drupal\graphql\GraphQL\ResolverRegistryInterface;
|
|
|
use Drupal\graphql\GraphQL\Response\ResponseInterface;
|
|
|
use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase;
|
|
|
use Drupal\materio_graphql\GraphQL\Response\MaterioResponse;
|
|
|
-
|
|
|
+use Drupal\Core\Url;
|
|
|
/**
|
|
|
* @SchemaExtension(
|
|
|
* id = "materio_extension",
|
|
@@ -24,30 +24,47 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
public function registerResolvers(ResolverRegistryInterface $registry) {
|
|
|
$builder = new ResolverBuilder();
|
|
|
|
|
|
- // Materiau
|
|
|
+
|
|
|
+ // __ __ _ _
|
|
|
+ // | \/ |__ _| |_ ___ _ _(_)__ _ _ _
|
|
|
+ // | |\/| / _` | _/ -_) '_| / _` | || |
|
|
|
+ // |_| |_\__,_|\__\___|_| |_\__,_|\_,_|
|
|
|
$registry->addFieldResolver('Query', 'materiau',
|
|
|
$builder->produce('entity_load')
|
|
|
->map('type', $builder->fromValue('node'))
|
|
|
->map('bundles', $builder->fromValue(['materiau']))
|
|
|
->map('id', $builder->fromArgument('id'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Materiau', 'id',
|
|
|
$builder->produce('entity_id')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Materiau', 'uuid',
|
|
|
$builder->produce('entity_uuid')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Materiau', 'title',
|
|
|
$builder->compose(
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- )
|
|
|
- );
|
|
|
+ ));
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Materiau', 'body',
|
|
|
+ $builder->produce('property_path')
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('body.value'))
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Materiau', 'short_description',
|
|
|
+ $builder->produce('property_path')
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('field_short_description.value'))
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Materiau', 'author',
|
|
|
$builder->compose(
|
|
@@ -55,8 +72,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('entity', $builder->fromParent()),
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- )
|
|
|
- );
|
|
|
+ ));
|
|
|
|
|
|
// https://github.com/drupal-graphql/graphql/blob/8.x-4.x/doc/SUMMARY.md
|
|
|
// https://blog.chrismitchellonline.com/posts/custom_graphql_data/
|
|
@@ -66,8 +82,14 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('field', $builder->fromValue('field_linked_materials'))
|
|
|
- )
|
|
|
- );
|
|
|
+ ));
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Materiau', 'linked_articles',
|
|
|
+ $builder->compose(
|
|
|
+ $builder->produce('entity_reference')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('field', $builder->fromValue('field_linked_articles'))
|
|
|
+ ));
|
|
|
|
|
|
$registry->addFieldResolver('Materiau', 'memo',
|
|
|
$builder->produce('property_path')
|
|
@@ -80,37 +102,70 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('field', $builder->fromValue('field_materiau_images'))
|
|
|
- );
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Materiau', 'attachments',
|
|
|
+ $builder->produce('property_path')
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('field_attachments'))
|
|
|
+ // $builder->produce('entity_reference')
|
|
|
+ // ->map('entity', $builder->fromParent())
|
|
|
+ // ->map('field', $builder->fromValue('field_attachments'))
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Materiau', 'videos',
|
|
|
+ $builder->produce('property_path')
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('field_video'))
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Materiau', 'tags',
|
|
|
+ $builder->produce('entity_reference')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('field', $builder->fromValue('field_tags'))
|
|
|
+ );
|
|
|
|
|
|
- // Article
|
|
|
+ $registry->addFieldResolver('Materiau', 'thesaurus',
|
|
|
+ $builder->produce('entity_reference')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('field', $builder->fromValue('field_thesaurus'))
|
|
|
+ );
|
|
|
+
|
|
|
+ // field_distributor
|
|
|
+ // field_famille
|
|
|
+ // field_index
|
|
|
+ // field_manufacturer
|
|
|
+ // field_reference
|
|
|
+ // field_samples
|
|
|
+
|
|
|
+ // _ _ _ _
|
|
|
+ // /_\ _ _| |_(_)__| |___
|
|
|
+ // / _ \| '_| _| / _| / -_)
|
|
|
+ // /_/ \_\_| \__|_\__|_\___|
|
|
|
$registry->addFieldResolver('Query', 'article',
|
|
|
$builder->produce('entity_load')
|
|
|
->map('type', $builder->fromValue('node'))
|
|
|
->map('bundles', $builder->fromValue(['article']))
|
|
|
->map('id', $builder->fromArgument('id'))
|
|
|
- );
|
|
|
- // $registry->addFieldResolver('ArticleResponse', 'article',
|
|
|
- // $builder->callback(function (ArticleResponse $response) {
|
|
|
- // return $response->article();
|
|
|
- // })
|
|
|
- // );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'id',
|
|
|
$builder->produce('entity_id')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'uuid',
|
|
|
$builder->produce('entity_uuid')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'title',
|
|
|
$builder->compose(
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- )
|
|
|
- );
|
|
|
+ ));
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'author',
|
|
|
$builder->compose(
|
|
@@ -118,75 +173,139 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
->map('entity', $builder->fromParent()),
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- )
|
|
|
- );
|
|
|
+ ));
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'body',
|
|
|
$builder->produce('property_path')
|
|
|
- ->map('type', $builder->fromValue('entity:node'))
|
|
|
- ->map('value', $builder->fromParent())
|
|
|
- ->map('path', $builder->fromValue('body.value'))
|
|
|
- );
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('body.value'))
|
|
|
+ );
|
|
|
|
|
|
+ $registry->addFieldResolver('Article', 'memo',
|
|
|
+ $builder->produce('property_path')
|
|
|
+ ->map('type', $builder->fromValue('entity:node'))
|
|
|
+ ->map('value', $builder->fromParent())
|
|
|
+ ->map('path', $builder->fromValue('field_memo.value'))
|
|
|
+ );
|
|
|
// https://github.com/drupal-graphql/graphql/blob/8.x-4.x/doc/SUMMARY.md
|
|
|
// https://blog.chrismitchellonline.com/posts/custom_graphql_data/
|
|
|
$registry->addFieldResolver('Article', 'linked_materials',
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('field', $builder->fromValue('field_linked_materials'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'images',
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('field', $builder->fromValue('field_visuel'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'videos',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('entity:node'))
|
|
|
->map('value', $builder->fromParent())
|
|
|
->map('path', $builder->fromValue('field_video'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'tags',
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('field', $builder->fromValue('field_tags'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'thesaurus',
|
|
|
$builder->produce('entity_reference')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('field', $builder->fromValue('field_thesaurus'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'showroom',
|
|
|
$builder->compose(
|
|
|
$builder->produce('entity_reference')
|
|
|
- ->map('entity', $builder->fromParent())
|
|
|
- ->map('field', $builder->fromValue('field_showroom')),
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('field', $builder->fromValue('field_showroom')),
|
|
|
$builder->callback(function ($items) {
|
|
|
- return $items[0];
|
|
|
- })
|
|
|
- )
|
|
|
- );
|
|
|
+ return $items[0];
|
|
|
+ })
|
|
|
+ ));
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'source',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('entity:node'))
|
|
|
->map('value', $builder->fromParent())
|
|
|
->map('path', $builder->fromValue('field_source'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Article', 'date',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('entity:node'))
|
|
|
->map('value', $builder->fromParent())
|
|
|
->map('path', $builder->fromValue('field_date'))
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ // ___ _ _
|
|
|
+ // | __(_) |___
|
|
|
+ // | _|| | / -_)
|
|
|
+ // |_| |_|_\___|
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Filefield', 'description',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent['description'];
|
|
|
+ })
|
|
|
+ );
|
|
|
+ $registry->addFieldResolver('Filefield', 'file',
|
|
|
+ // $builder->produce('entity_reference')
|
|
|
+ // ->map('entity', $builder->fromParent())
|
|
|
+ // ->map('field', $builder->fromValue('field_showroom'))
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return \Drupal\file\Entity\File::load($parent['target_id']);
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('File', 'url',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent->url();
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('File', 'filesize',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent->getSize();
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('File', 'filemime',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent->getMimeType();
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('File', 'filename',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent->getFilename();
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('File', 'fid',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent->id();
|
|
|
+ })
|
|
|
);
|
|
|
|
|
|
- // Date
|
|
|
+ $registry->addFieldResolver('File', 'uuid',
|
|
|
+ $builder->callback(function ($parent, $args) {
|
|
|
+ return $parent->uuid();
|
|
|
+ })
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ // ___ _
|
|
|
+ // | \ __ _| |_ ___
|
|
|
+ // | |) / _` | _/ -_)
|
|
|
+ // |___/\__,_|\__\___|
|
|
|
$registry->addFieldResolver('Date', 'start',
|
|
|
$builder->callback(function ($parent, $args) {
|
|
|
return $parent[0]['value'];
|
|
@@ -198,119 +317,162 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
|
|
|
})
|
|
|
);
|
|
|
|
|
|
- // Link
|
|
|
+
|
|
|
+ // _ _ _
|
|
|
+ // | | (_)_ _ | |__
|
|
|
+ // | |__| | ' \| / /
|
|
|
+ // |____|_|_||_|_\_\
|
|
|
$registry->addFieldResolver('Link', 'url',
|
|
|
$builder->callback(function ($parent, $args) {
|
|
|
return $parent[0]['uri'];
|
|
|
})
|
|
|
);
|
|
|
-
|
|
|
$registry->addFieldResolver('Link', 'title',
|
|
|
$builder->callback(function ($parent, $args) {
|
|
|
return $parent[0]['title'];
|
|
|
})
|
|
|
);
|
|
|
|
|
|
- // Showroom
|
|
|
+
|
|
|
+ // ___ _
|
|
|
+ // / __| |_ _____ __ ___ _ ___ ___ _ __
|
|
|
+ // \__ \ ' \/ _ \ V V / '_/ _ \/ _ \ ' \
|
|
|
+ // |___/_||_\___/\_/\_/|_| \___/\___/_|_|_|
|
|
|
$registry->addFieldResolver('Query', 'showroom',
|
|
|
$builder->produce('entity_load')
|
|
|
->map('type', $builder->fromValue('taxonomy_term'))
|
|
|
->map('bundles', $builder->fromValue(['showroom']))
|
|
|
->map('id', $builder->fromArgument('id'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Showroom', 'id',
|
|
|
$builder->produce('entity_id')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Showroom', 'uuid',
|
|
|
$builder->produce('entity_uuid')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Showroom', 'name',
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
- // Tag
|
|
|
+
|
|
|
+ // _____
|
|
|
+ // |_ _|_ _ __ _
|
|
|
+ // | |/ _` / _` |
|
|
|
+ // |_|\__,_\__, |
|
|
|
+ // |___/
|
|
|
$registry->addFieldResolver('Query', 'tag',
|
|
|
$builder->produce('entity_load')
|
|
|
->map('type', $builder->fromValue('taxonomy_term'))
|
|
|
->map('bundles', $builder->fromValue(['tags']))
|
|
|
->map('id', $builder->fromArgument('id'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Tag', 'id',
|
|
|
$builder->produce('entity_id')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Tag', 'uuid',
|
|
|
$builder->produce('entity_uuid')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Tag', 'name',
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
- // Thesaurus
|
|
|
+
|
|
|
+ // _____ _
|
|
|
+ // |_ _| |_ ___ ___ __ _ _ _ _ _ _ _ ___
|
|
|
+ // | | | ' \/ -_|_-</ _` | || | '_| || (_-<
|
|
|
+ // |_| |_||_\___/__/\__,_|\_,_|_| \_,_/__/
|
|
|
$registry->addFieldResolver('Query', 'thesaurus',
|
|
|
$builder->produce('entity_load')
|
|
|
->map('type', $builder->fromValue('taxonomy_term'))
|
|
|
->map('bundles', $builder->fromValue(['thesaurus']))
|
|
|
->map('id', $builder->fromArgument('id'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Thesaurus', 'id',
|
|
|
$builder->produce('entity_id')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Thesaurus', 'uuid',
|
|
|
$builder->produce('entity_uuid')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Thesaurus', 'name',
|
|
|
$builder->produce('entity_label')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
+
|
|
|
|
|
|
- // VideoLink
|
|
|
+ // __ ___ _ _ _ _
|
|
|
+ // \ \ / (_)__| |___ ___| | (_)_ _ | |__
|
|
|
+ // \ V /| / _` / -_) _ \ |__| | ' \| / /
|
|
|
+ // \_/ |_\__,_\___\___/____|_|_||_|_\_\
|
|
|
$registry->addFieldResolver('VideoLink', 'url',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('field_item:video_embed_field'))
|
|
|
->map('value', $builder->fromParent())
|
|
|
->map('path', $builder->fromValue('value'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
- // Image
|
|
|
+
|
|
|
+ // ___
|
|
|
+ // |_ _|_ __ __ _ __ _ ___
|
|
|
+ // | || ' \/ _` / _` / -_)
|
|
|
+ // |___|_|_|_\__,_\__, \___|
|
|
|
+ // |___/
|
|
|
$registry->addFieldResolver('Image', 'id',
|
|
|
$builder->produce('entity_id')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Image', 'url',
|
|
|
$builder->produce('image_url')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Image', 'alt',
|
|
|
$builder->produce('property_path')
|
|
|
->map('type', $builder->fromValue('entity:node'))
|
|
|
->map('value', $builder->fromParent())
|
|
|
->map('path', $builder->fromValue('field_image.alt'))
|
|
|
- );
|
|
|
+ );
|
|
|
|
|
|
$registry->addFieldResolver('Image', 'style_minicard',
|
|
|
$builder->produce('image_derivative')
|
|
|
->map('entity', $builder->fromParent())
|
|
|
->map('style', $builder->fromValue('card_medium_half'))
|
|
|
- );
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Image', 'style_cardmedium',
|
|
|
+ $builder->produce('image_derivative')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('style', $builder->fromValue('card_medium'))
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Image', 'style_cardfull',
|
|
|
+ $builder->produce('image_derivative')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('style', $builder->fromValue('card_full'))
|
|
|
+ );
|
|
|
+
|
|
|
+ $registry->addFieldResolver('Image', 'style_articlecardmedium',
|
|
|
+ $builder->produce('image_derivative')
|
|
|
+ ->map('entity', $builder->fromParent())
|
|
|
+ ->map('style', $builder->fromValue('article_card_medium'))
|
|
|
+ );
|
|
|
|
|
|
// Response type resolver.
|
|
|
$registry->addTypeResolver('Response', [
|