From cd91067f162daa881782df8197d084e82c4860e7 Mon Sep 17 00:00:00 2001 From: bach Date: Tue, 16 May 2023 14:52:04 +0200 Subject: [PATCH] graphql for besoin & reponses --- src/config/sync/devel.settings.yml | 4 +- .../field.field.node.reponse.field_avec.yml | 5 + .../field.field.node.reponse.field_ou.yml | 5 + .../field.field.node.reponse.field_qui.yml | 5 + .../field.field.node.reponse.field_quoi.yml | 5 + .../graphql/ouatt_extension.base.graphqls | 24 +- .../ouatt_extension.extension.graphqls | 24 ++ .../SchemaExtension/OuattSchemaExtension.php | 217 +++++++++++++++++- 8 files changed, 284 insertions(+), 5 deletions(-) diff --git a/src/config/sync/devel.settings.yml b/src/config/sync/devel.settings.yml index 1b3fe95..233ef8f 100644 --- a/src/config/sync/devel.settings.yml +++ b/src/config/sync/devel.settings.yml @@ -8,4 +8,6 @@ error_handlers: rebuild_theme: false debug_mail_file_format: '%to-%subject-%datetime.mail.txt' debug_mail_directory: 'temporary://devel-mails' -devel_dumper: default +devel_dumper: kint +debug_logfile: 'temporary://drupal_debug.txt' +debug_pre: false diff --git a/src/config/sync/field.field.node.reponse.field_avec.yml b/src/config/sync/field.field.node.reponse.field_avec.yml index 754c0a9..9207f87 100644 --- a/src/config/sync/field.field.node.reponse.field_avec.yml +++ b/src/config/sync/field.field.node.reponse.field_avec.yml @@ -6,7 +6,12 @@ dependencies: - field.storage.node.field_avec - node.type.reponse module: + - allowed_formats - text +third_party_settings: + allowed_formats: + allowed_formats: + - linkonly id: node.reponse.field_avec field_name: field_avec entity_type: node diff --git a/src/config/sync/field.field.node.reponse.field_ou.yml b/src/config/sync/field.field.node.reponse.field_ou.yml index c50a5b2..3518c8e 100644 --- a/src/config/sync/field.field.node.reponse.field_ou.yml +++ b/src/config/sync/field.field.node.reponse.field_ou.yml @@ -6,7 +6,12 @@ dependencies: - field.storage.node.field_ou - node.type.reponse module: + - allowed_formats - text +third_party_settings: + allowed_formats: + allowed_formats: + - linkonly id: node.reponse.field_ou field_name: field_ou entity_type: node diff --git a/src/config/sync/field.field.node.reponse.field_qui.yml b/src/config/sync/field.field.node.reponse.field_qui.yml index 9d35aa0..16816a2 100644 --- a/src/config/sync/field.field.node.reponse.field_qui.yml +++ b/src/config/sync/field.field.node.reponse.field_qui.yml @@ -6,7 +6,12 @@ dependencies: - field.storage.node.field_qui - node.type.reponse module: + - allowed_formats - text +third_party_settings: + allowed_formats: + allowed_formats: + - linkonly id: node.reponse.field_qui field_name: field_qui entity_type: node diff --git a/src/config/sync/field.field.node.reponse.field_quoi.yml b/src/config/sync/field.field.node.reponse.field_quoi.yml index 4da3c98..4df3ec4 100644 --- a/src/config/sync/field.field.node.reponse.field_quoi.yml +++ b/src/config/sync/field.field.node.reponse.field_quoi.yml @@ -6,7 +6,12 @@ dependencies: - field.storage.node.field_quoi - node.type.reponse module: + - allowed_formats - text +third_party_settings: + allowed_formats: + allowed_formats: + - linkonly id: node.reponse.field_quoi field_name: field_quoi entity_type: node diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls index c20fd03..18ce4fd 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls +++ b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls @@ -7,16 +7,17 @@ interface NodeInterface { type Concernement implements NodeInterface { id: Int! + path: String! uuid: String! bundle: String! title: String! - path: String! author: String description: String caillou: String recit: Filefield entites: [Entiteintegre] doleances: [Doleance] + besoins: [Besoin] } type Entiteintegre { @@ -28,10 +29,10 @@ type Entiteintegre { type Entite implements NodeInterface { id: Int! + path: String! uuid: String! bundle: String! title: String! - path: String! author: String action: String menacemaintien: String @@ -63,6 +64,25 @@ type Etape { 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 { id: Int! uuid: String! diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls index e70aa1f..2d6ae99 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls +++ b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls @@ -39,6 +39,30 @@ extend type Query { 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 { user(id: Int!): User } diff --git a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php index 1c6741a..8a80537 100644 --- a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php +++ b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php @@ -42,6 +42,10 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase { // $this->addEtape($registry, $builder); // + $this->addBesoin($registry, $builder); + // + $this->addReponse($registry, $builder); + // $this->addStatic($registry, $builder); // $this->addGroup($registry, $builder); @@ -82,6 +86,9 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase { switch ($value->bundle()) { case 'concernement': return 'Concernement'; case 'entite': return 'Entite'; + case 'besoin': return 'Besoin'; + case 'reponse': return 'Reponse'; + case 'static': return 'Static'; } } throw new Error('Could not resolve content type.'); @@ -222,6 +229,13 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase { ->map('entity', $builder->fromParent()) ->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('path', $builder->fromValue('field_entite_agissante.value')) ); - - + $registry->addFieldResolver('Entite', 'action', $builder->produce('property_path') ->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')) + ); + + } + // ___ _ _ _ // / __| |_ __ _| |_(_)__ ___ // \__ \ _/ _` | _| / _(_-<