completed graphql definitions, all field are available now

This commit is contained in:
2021-03-02 13:09:39 +01:00
parent 88436cfc82
commit 703619955c
3 changed files with 280 additions and 19 deletions
@@ -15,7 +15,11 @@ interface TextInterface {
texte: String
images: [Image]
videos: [VideoLink]
fichiers: [File]
familles: [Taxoterm]
field_titre: String
auteurs: [Taxoterm]
edition: Taxoterm
}
type Textref implements NodeInterface & TextInterface{
@@ -28,17 +32,17 @@ type Textref implements NodeInterface & TextInterface{
texte: String
images: [Image]
videos: [VideoLink]
fichiers: [File]
familles: [Taxoterm]
field_titre: String
auteurs: [Taxoterm]
edition: Taxoterm
#
text_produits: [Textprod]
text_en_rebond: [Textref]
tags: [Taxoterm]
# field_degres_detrangement
# notes: [Note]
# field_titre
# auteur: Auteur
# edition: Edition
# file: Filefield
degres_detrangement: Int
notes: [Noteref]
}
type Textprod implements NodeInterface & TextInterface {
@@ -51,15 +55,45 @@ type Textprod implements NodeInterface & TextInterface {
texte: String
images: [Image]
videos: [VideoLink]
fichiers: [File]
familles: [Taxoterm]
field_titre: String
auteurs: [Taxoterm]
edition: Taxoterm
#
text_de_depart: [Textref]
tagsprod: [Taxoterm]
# notes: [Note]
# field_titre
# auteur: Auteur
# edition: Edition
# file: Filefield
notes: [Noteprod]
}
type Creation implements NodeInterface {
id: Int!
uuid: String!
bundle: String!
title: String!
path: String!
author: String
texte: String
auteurs: [Taxoterm]
oeuvre: Link
}
interface NoteInterface {
note: String
numero: Int
}
type Noteref implements NoteInterface {
note: String
numero: Int
}
type Noteprod implements NoteInterface {
note: String
numero: Int
#
liens: [TextInterface]
}
type Filefield {
@@ -82,11 +116,6 @@ type Taxoterm {
name: String!
}
type Date {
start: String
end: String
}
type VideoLink {
url: String
}
@@ -114,3 +143,8 @@ type ImageStyle {
height: Int
url: String
}
type Link {
url: String
title: String
}
@@ -26,6 +26,18 @@ extend type Query {
textsprod(ids: [Int]): [Textprod]
}
extend type Query {
allcreations: [Creation]
}
extend type Query {
creations(ids: [Int]): [Creation]
}
extend type Query {
creation(id: Int!): Creation
}
extend type Query {
famille(id: Int!): Taxoterm
}
@@ -36,6 +36,12 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
$this->addTextref($registry, $builder);
$this->addTextprod($registry, $builder);
$this->addNote($registry, $builder);
$this->addNoteProd($registry, $builder);
$this->addCreation($registry, $builder);
//
$this->addFilefield($registry, $builder);
//
@@ -107,6 +113,10 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
));
}
// _____ _
// |_ _|____ _| |_ ___
// | |/ -_) \ / _(_-<
// |_|\___/_\_\\__/__/
protected function addTexts(ResolverRegistryInterface $registry, ResolverBuilder $builder){
// Tell GraphQL how to resolve types of a common interface.
$registry->addTypeResolver('TextInterface', function ($value) {
@@ -134,7 +144,6 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
);
}
// _____ _ ___ _
// |_ _|____ _| |_ ___ | \ ___ _ __ __ _ _ _| |_
// | |/ -_) \ / _(_-< | |) / -_) '_ \/ _` | '_| _|
@@ -273,8 +282,45 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_famille'))
);
}
$registry->addFieldResolver('Textref', 'degres_detrangement',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('degres_detrangement'))
);
$registry->addFieldResolver('Textref', 'field_titre',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_titre'))
);
$registry->addFieldResolver('Textref', 'auteurs',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_autheurs'))
);
$registry->addFieldResolver('Textref', 'edition',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_edition'))
);
$registry->addFieldResolver('Textref', 'fichiers',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_fichier'))
);
$registry->addFieldResolver('Textref', 'notes',
$builder->produce('entity_reference_revisions')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_notes'))
);
}
// _____ _ ___ _
// |_ _|____ _| |_| _ \_ _ ___ __| |
@@ -374,6 +420,172 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_famille'))
);
$registry->addFieldResolver('Textprod', 'field_titre',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_titre'))
);
$registry->addFieldResolver('Textprod', 'auteurs',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_autheurs'))
);
$registry->addFieldResolver('Textprod', 'edition',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_edition'))
);
$registry->addFieldResolver('Textprod', 'notes',
$builder->produce('entity_reference_revisions')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_notes_prod'))
);
}
// _ _ _
// | \| |___| |_ ___
// | .` / _ \ _/ -_)
// |_|\_\___/\__\___|
protected function addNote(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Noteref', 'note',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:paragraph'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_note.value'))
);
$registry->addFieldResolver('Noteref', 'numero',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:paragraph'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_numero.value'))
);
}
protected function addNoteProd(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Noteprod', 'note',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:paragraph'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_note.value'))
);
$registry->addFieldResolver('Noteprod', 'numero',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:paragraph'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_numero.value'))
);
$registry->addFieldResolver('Noteprod', 'liens',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_text_lien'))
);
}
// ___ _ _
// / __|_ _ ___ __ _| |_(_)___ _ _
// | (__| '_/ -_) _` | _| / _ \ ' \
// \___|_| \___\__,_|\__|_\___/_||_|
protected function addCreation(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'allcreations',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['creation'], 'IN')
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromParent())
)
);
$registry->addFieldResolver('Query', 'creations',
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromArgument('ids'))
);
$registry->addFieldResolver('Query', 'creation',
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('bundles', $builder->fromValue(['texte_prod']))
->map('id', $builder->fromArgument('id'))
);
$registry->addFieldResolver('Creation', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Creation', 'uuid',
$builder->produce('entity_uuid')
->map('entity', $builder->fromParent())
);
$registry->addFieldResolver('Creation', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
$registry->addFieldResolver('Creation', 'title',
$builder->compose(
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Creation', 'bundle',
$builder->compose(
$builder->produce('entity_bundle')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Creation', 'description',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('body.value'))
);
$registry->addFieldResolver('Creation', 'author',
$builder->compose(
$builder->produce('entity_owner')
->map('entity', $builder->fromParent()),
$builder->produce('entity_label')
->map('entity', $builder->fromParent())
));
$registry->addFieldResolver('Creation', 'auteurs',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_autheurs'))
);
$registry->addFieldResolver('Creation', 'oeuvre',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_oeuvre'))
);
}
// ___ _
@@ -398,16 +610,19 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
// | _|| | / -_) _| / -_) / _` |
// |_| |_|_\___|_| |_\___|_\__,_|
protected function addFilefield(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Filefield', 'description',
$builder->callback(function ($parent, $args) {
return $parent['description'];
})
);
$registry->addFieldResolver('Filefield', 'file',
$builder->callback(function ($parent, $args) {
return \Drupal\file\Entity\File::load($parent['target_id']);
})
);
}
// ___ _ _
@@ -417,7 +632,7 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
protected function addFile(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('File', 'url',
$builder->callback(function ($parent, $args) {
return $parent->url();
return $parent->createFileUrl();
})
);