created thematique page

This commit is contained in:
2020-12-25 17:37:15 +01:00
parent f65e8fb140
commit 144ab7db26
13 changed files with 589 additions and 67 deletions

View File

@@ -2,12 +2,14 @@ scalar Violation
interface NodeInterface {
id: Int!
path: String!
}
type Materiau implements NodeInterface {
id: Int!
uuid: String!
title: String!
path: String!
author: String
body: String
short_description: String
@@ -31,6 +33,7 @@ type Article implements NodeInterface {
id: Int!
uuid: String!
title: String!
path: String!
author: String
body: String
linked_materials: [Materiau]
@@ -44,11 +47,25 @@ type Article implements NodeInterface {
memo: String
}
type Thematique implements NodeInterface {
id: Int!
uuid: String!
title: String!
path: String!
author: String
body: String
linked_materials: [Materiau]
images: [Image]
tags: [Tag]
memo: String
}
type SearchResult {
id: Int!
uuid: String!
title: String!
bundle: String
bundle: String!
path: String!
short_description: String
images: [Image]
visuels: [Image]

View File

@@ -18,6 +18,10 @@ extend type Query {
article(id: Int!): Article
}
extend type Query {
thematique(id: Int!): Thematique
}
extend type Query {
showroom(id: Int!): Showroom
}

View File

@@ -27,29 +27,7 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
public function registerResolvers(ResolverRegistryInterface $registry) {
$builder = new ResolverBuilder();
// Tell GraphQL how to resolve types of a common interface.
$registry->addTypeResolver('NodeInterface', function ($value) {
$path = explode('\\', get_class($value));
$class = array_pop($path);
if ($class === 'Node') {
switch ($value->bundle()) {
case 'article': return 'Article';
case 'materiau': return 'Materiau';
}
}
throw new Error('Could not resolve content type.');
});
$registry->addFieldResolver('Query', 'route',
$builder->compose(
$builder->produce('route_load')
->map('path', $builder->fromArgument('path')),
$builder->produce('route_entity')
->map('url', $builder->fromParent())
));
$this->addRouteResolver($registry, $builder);
$this->addMateriau($registry, $builder);
@@ -59,6 +37,8 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
$this->addArticle($registry, $builder);
$this->addThematique($registry, $builder);
$this->addCompany($registry, $builder);
$this->addAddress($registry, $builder);
@@ -88,6 +68,36 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
]);
}
// ___ _
// | _ \___ _ _| |_ ___
// | / _ \ || | _/ -_)
// |_|_\___/\_,_|\__\___|
protected function addRouteResolver(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
// Tell GraphQL how to resolve types of a common interface.
$registry->addTypeResolver('NodeInterface', function ($value) {
$path = explode('\\', get_class($value));
$class = array_pop($path);
if ($class === 'Node') {
switch ($value->bundle()) {
case 'article': return 'Article';
case 'materiau': return 'Materiau';
case 'thematique': return 'Thematique';
}
}
throw new Error('Could not resolve content type.');
});
$registry->addFieldResolver('Query', 'route',
$builder->compose(
$builder->produce('route_load')
->map('path', $builder->fromArgument('path')),
$builder->produce('route_entity')
->map('url', $builder->fromParent())
));
}
// __ __ _ _
// | \/ |__ _| |_ ___ _ _(_)__ _ _ _
// | |\/| / _` | _/ -_) '_| / _` | || |
@@ -117,6 +127,15 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Materiau', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
$registry->addFieldResolver('Materiau', 'title',
$builder->compose(
$builder->produce('entity_label')
@@ -269,6 +288,15 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('SearchResult', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
$registry->addFieldResolver('SearchResult', 'title',
$builder->compose(
$builder->produce('entity_label')
@@ -343,6 +371,15 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Article', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
$registry->addFieldResolver('Article', 'title',
$builder->compose(
$builder->produce('entity_label')
@@ -428,6 +465,87 @@ class MaterioSchemaExtension extends SdlSchemaExtensionPluginBase {
);
}
// _____ _ _ _
// |_ _| |_ ___ _ __ __ _| |_(_)__ _ _ _ ___
// | | | ' \/ -_) ' \/ _` | _| / _` | || / -_)
// |_| |_||_\___|_|_|_\__,_|\__|_\__, |\_,_\___|
// |_|
protected function addThematique(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'Thematique',
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['thematique']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Thematique', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Thematique', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Thematique', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
$registry->addFieldResolver('Thematique', 'title',
$builder->compose(
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Thematique', 'author',
$builder->compose(
$builder->produce('entity_owner')
->map('entity', $builder->fromParent()),
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Thematique', 'body',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('body.value'))
);
$registry->addFieldResolver('Thematique', '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('Thematique', 'linked_materials',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_linked_materials'))
);
$registry->addFieldResolver('Thematique', 'images',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_visuel'))
);
$registry->addFieldResolver('Thematique', 'tags',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_tags'))
);
}
// ___
// |_ _|_ __ __ _ __ _ ___
// | || ' \/ _` / _` / -_)