graphql for besoin & reponses

This commit is contained in:
Bachir Soussi Chiadmi 2023-05-16 14:52:04 +02:00
parent 45e31ee3a9
commit cd91067f16
8 changed files with 284 additions and 5 deletions

View File

@ -8,4 +8,6 @@ error_handlers:
rebuild_theme: false rebuild_theme: false
debug_mail_file_format: '%to-%subject-%datetime.mail.txt' debug_mail_file_format: '%to-%subject-%datetime.mail.txt'
debug_mail_directory: 'temporary://devel-mails' debug_mail_directory: 'temporary://devel-mails'
devel_dumper: default devel_dumper: kint
debug_logfile: 'temporary://drupal_debug.txt'
debug_pre: false

View File

@ -6,7 +6,12 @@ dependencies:
- field.storage.node.field_avec - field.storage.node.field_avec
- node.type.reponse - node.type.reponse
module: module:
- allowed_formats
- text - text
third_party_settings:
allowed_formats:
allowed_formats:
- linkonly
id: node.reponse.field_avec id: node.reponse.field_avec
field_name: field_avec field_name: field_avec
entity_type: node entity_type: node

View File

@ -6,7 +6,12 @@ dependencies:
- field.storage.node.field_ou - field.storage.node.field_ou
- node.type.reponse - node.type.reponse
module: module:
- allowed_formats
- text - text
third_party_settings:
allowed_formats:
allowed_formats:
- linkonly
id: node.reponse.field_ou id: node.reponse.field_ou
field_name: field_ou field_name: field_ou
entity_type: node entity_type: node

View File

@ -6,7 +6,12 @@ dependencies:
- field.storage.node.field_qui - field.storage.node.field_qui
- node.type.reponse - node.type.reponse
module: module:
- allowed_formats
- text - text
third_party_settings:
allowed_formats:
allowed_formats:
- linkonly
id: node.reponse.field_qui id: node.reponse.field_qui
field_name: field_qui field_name: field_qui
entity_type: node entity_type: node

View File

@ -6,7 +6,12 @@ dependencies:
- field.storage.node.field_quoi - field.storage.node.field_quoi
- node.type.reponse - node.type.reponse
module: module:
- allowed_formats
- text - text
third_party_settings:
allowed_formats:
allowed_formats:
- linkonly
id: node.reponse.field_quoi id: node.reponse.field_quoi
field_name: field_quoi field_name: field_quoi
entity_type: node entity_type: node

View File

@ -7,16 +7,17 @@ interface NodeInterface {
type Concernement implements NodeInterface { type Concernement implements NodeInterface {
id: Int! id: Int!
path: String!
uuid: String! uuid: String!
bundle: String! bundle: String!
title: String! title: String!
path: String!
author: String author: String
description: String description: String
caillou: String caillou: String
recit: Filefield recit: Filefield
entites: [Entiteintegre] entites: [Entiteintegre]
doleances: [Doleance] doleances: [Doleance]
besoins: [Besoin]
} }
type Entiteintegre { type Entiteintegre {
@ -28,10 +29,10 @@ type Entiteintegre {
type Entite implements NodeInterface { type Entite implements NodeInterface {
id: Int! id: Int!
path: String!
uuid: String! uuid: String!
bundle: String! bundle: String!
title: String! title: String!
path: String!
author: String author: String
action: String action: String
menacemaintien: String menacemaintien: String
@ -63,6 +64,25 @@ type Etape {
type: Int type: Int
} }
type Besoin implements NodeInterface {
id: Int!
path: String!
description: String!
index: Int
concernement: Concernement
reponses: [Reponse]
}
type Reponse implements NodeInterface {
id: Int!
path: String!
besoin: Besoin
qui: String
quoi: String
ou: String
avec: String
}
type Static implements NodeInterface { type Static implements NodeInterface {
id: Int! id: Int!
uuid: String! uuid: String!

View File

@ -39,6 +39,30 @@ extend type Query {
static(id: Int!): Static static(id: Int!): Static
} }
extend type Query {
allbesoins: [Besoin]
}
extend type Query {
besoins(ids: [Int]): [Besoin]
}
extend type Query {
besoin(id: Int!): Besoin
}
extend type Query {
allreponses: [Reponse]
}
extend type Query {
reponses(ids: [Int]): [Reponse]
}
extend type Query {
reponse(id: Int!): Reponse
}
extend type Query { extend type Query {
user(id: Int!): User user(id: Int!): User
} }

View File

@ -42,6 +42,10 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
// //
$this->addEtape($registry, $builder); $this->addEtape($registry, $builder);
// //
$this->addBesoin($registry, $builder);
//
$this->addReponse($registry, $builder);
//
$this->addStatic($registry, $builder); $this->addStatic($registry, $builder);
// //
$this->addGroup($registry, $builder); $this->addGroup($registry, $builder);
@ -82,6 +86,9 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
switch ($value->bundle()) { switch ($value->bundle()) {
case 'concernement': return 'Concernement'; case 'concernement': return 'Concernement';
case 'entite': return 'Entite'; case 'entite': return 'Entite';
case 'besoin': return 'Besoin';
case 'reponse': return 'Reponse';
case 'static': return 'Static';
} }
} }
throw new Error('Could not resolve content type.'); throw new Error('Could not resolve content type.');
@ -222,6 +229,13 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('entity', $builder->fromParent()) ->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_doleancer')) ->map('field', $builder->fromValue('field_doleancer'))
); );
// besoins: [Besoin]
$registry->addFieldResolver('Concernement', 'besoins',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_besoin'))
);
} }
// _____ _ _ _ __ ___ _ __ __ // _____ _ _ _ __ ___ _ __ __
@ -362,8 +376,7 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
->map('value', $builder->fromParent()) ->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_entite_agissante.value')) ->map('path', $builder->fromValue('field_entite_agissante.value'))
); );
$registry->addFieldResolver('Entite', 'action', $registry->addFieldResolver('Entite', 'action',
$builder->produce('property_path') $builder->produce('property_path')
->map('type', $builder->fromValue('entity:node')) ->map('type', $builder->fromValue('entity:node'))
@ -512,6 +525,206 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
); );
} }
// ____ _
// | __ ) ___ ___ ___ (_)_ __
// | _ \ / _ \/ __|/ _ \| | '_ \
// | |_) | __/\__ \ (_) | | | | |
// |____/ \___||___/\___/|_|_| |_|
protected function addBesoin(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'allbesoins',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['besoin'], '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', 'besoins',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['besoin'], 'IN')
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromArgument('ids'))
)
);
$registry->addFieldResolver('Query', 'besoin',
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('id', $builder->fromArgument('id'))
);
// id: Int!
$registry->addFieldResolver('Besoin', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
// path: String!
$registry->addFieldResolver('Besoin', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
// description: String!
$registry->addFieldResolver('Besoin', 'description',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('body.value'))
);
// index: Int
$registry->addFieldResolver('Besoin', 'index',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_index.value'))
);
// concernement: Concernement
$registry->addFieldResolver('Besoin', 'concernement',
$builder->compose(
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_concernement')),
$builder->callback(function($parent, $arg){
return $parent[0];
})
));
// reponses: [Reponse]
$registry->addFieldResolver('Besoin', 'reponses',
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_reponse'))
);
}
// ____
// | _ \ ___ _ __ ___ _ __ ___ ___
// | |_) / _ \ '_ \ / _ \| '_ \/ __|/ _ \
// | _ < __/ |_) | (_) | | | \__ \ __/
// |_| \_\___| .__/ \___/|_| |_|___/\___|
// |_|
protected function addReponse(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
$registry->addFieldResolver('Query', 'allreponses',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['reponse'], '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', 'reponses',
$builder->compose(
$builder->callback(function($parent, $arg){
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $entity_storage->getQuery()
->condition('type', ['reponse'], 'IN')
->accessCheck(TRUE);
$results = $query->execute();
return $results;
}),
$builder->produce('entity_load_multiple')
->map('type', $builder->fromValue('node'))
->map('ids', $builder->fromArgument('ids'))
)
);
$registry->addFieldResolver('Query', 'reponse',
$builder->produce('entity_load')
->map('type', $builder->fromValue('node'))
->map('id', $builder->fromArgument('id'))
);
// id: Int!
$registry->addFieldResolver('Reponse', 'id',
$builder->produce('entity_id')
->map('entity', $builder->fromParent())
);
// path: String!
$registry->addFieldResolver('Reponse', 'path',
$builder->compose(
$builder->produce('entity_url')
->map('entity', $builder->fromParent()),
$builder->produce('url_path')
->map('url', $builder->fromParent())
)
);
// besoin: Besoin
$registry->addFieldResolver('Reponse', 'besoin',
$builder->compose(
$builder->produce('entity_reference')
->map('entity', $builder->fromParent())
->map('field', $builder->fromValue('field_besoin_on_reponses')),
$builder->callback(function($parent, $arg){
return $parent[0];
})
));
// qui: String
$registry->addFieldResolver('Reponse', 'qui',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_qui.value'))
);
// quoi: String
$registry->addFieldResolver('Reponse', 'quoi',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_quoi.value'))
);
// ou: String
$registry->addFieldResolver('Reponse', 'ou',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_ou.value'))
);
// avec: String
$registry->addFieldResolver('Reponse', 'avec',
$builder->produce('property_path')
->map('type', $builder->fromValue('entity:node'))
->map('value', $builder->fromParent())
->map('path', $builder->fromValue('field_avec.value'))
);
}
// ___ _ _ _ // ___ _ _ _
// / __| |_ __ _| |_(_)__ ___ // / __| |_ __ _| |_(_)__ ___
// \__ \ _/ _` | _| / _(_-< // \__ \ _/ _` | _| / _(_-<