From 59ac63f160f65a8402b53b12c54dbd8ac9cf9e92 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 19 May 2021 14:51:23 +0200 Subject: [PATCH] CT static gql ok --- .../graphql/enfr_extension.base.graphqls | 13 +++ .../graphql/enfr_extension.extension.graphqls | 12 ++ .../SchemaExtension/EnFrSchemaExtension.php | 106 ++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls b/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls index d25f648..868de9e 100644 --- a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls +++ b/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls @@ -80,6 +80,19 @@ type Creation implements NodeInterface { texte_de_depart: [Textref] # field_texte_de_depart } +type Static implements NodeInterface { + id: Int! + uuid: String! + bundle: String! + title: String! + path: String! + author: String + texte: String + notes: [Noteprod] + fichiers: [File] + poid: Int +} + interface NoteInterface { note: String numero: Int diff --git a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls b/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls index f5f76bc..b922c9f 100644 --- a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls +++ b/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls @@ -42,6 +42,18 @@ extend type Query { creation(id: Int!): Creation } +extend type Query { + allstatics: [Static] +} + +extend type Query { + statics(ids: [Int]): [Static] +} + +extend type Query { + static(id: Int!): Static +} + extend type Query { famille(id: Int!): Taxoterm } diff --git a/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php b/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php index 21bd637..5c959fa 100644 --- a/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php +++ b/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php @@ -42,6 +42,8 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase { $this->addNoteProd($registry, $builder); $this->addCreation($registry, $builder); + + $this->addStatic($registry, $builder); // $this->addFilefield($registry, $builder); // @@ -632,6 +634,110 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase { ); } + + // ___ _ _ _ + // / __| |_ __ _| |_(_)__ ___ + // \__ \ _/ _` | _| / _(_-< + // |___/\__\__,_|\__|_\__/__/ + protected function addStatic(ResolverRegistryInterface $registry, ResolverBuilder $builder) { + + $registry->addFieldResolver('Query', 'allstatics', + $builder->compose( + $builder->callback(function($parent, $arg){ + $entity_storage = \Drupal::entityTypeManager()->getStorage('node'); + $query = $entity_storage->getQuery() + ->condition('type', ['static'], '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', 'statics', + $builder->produce('entity_load_multiple') + ->map('type', $builder->fromValue('node')) + ->map('ids', $builder->fromArgument('ids')) + ); + + $registry->addFieldResolver('Query', 'static', + $builder->produce('entity_load') + ->map('type', $builder->fromValue('node')) + ->map('bundles', $builder->fromValue(['static'])) + ->map('id', $builder->fromArgument('id')) + ); + + + + $registry->addFieldResolver('Static', 'id', + $builder->produce('entity_id') + ->map('entity', $builder->fromParent()) + ); + + $registry->addFieldResolver('Static', 'uuid', + $builder->produce('entity_uuid') + ->map('entity', $builder->fromParent()) + ); + + $registry->addFieldResolver('Static', 'path', + $builder->compose( + $builder->produce('entity_url') + ->map('entity', $builder->fromParent()), + $builder->produce('url_path') + ->map('url', $builder->fromParent()) + ) + ); + + $registry->addFieldResolver('Static', 'title', + $builder->compose( + $builder->produce('entity_label') + ->map('entity', $builder->fromParent()) + )); + + $registry->addFieldResolver('Static', 'bundle', + $builder->compose( + $builder->produce('entity_bundle') + ->map('entity', $builder->fromParent()) + )); + + $registry->addFieldResolver('Static', 'texte', + $builder->produce('property_path') + ->map('type', $builder->fromValue('entity:node')) + ->map('value', $builder->fromParent()) + ->map('path', $builder->fromValue('body.value')) + ); + + $registry->addFieldResolver('Static', 'author', + $builder->compose( + $builder->produce('entity_owner') + ->map('entity', $builder->fromParent()), + $builder->produce('entity_label') + ->map('entity', $builder->fromParent()) + )); + + $registry->addFieldResolver('Static', 'fichiers', + $builder->produce('entity_reference') + ->map('entity', $builder->fromParent()) + ->map('field', $builder->fromValue('field_fichier')) + ); + + $registry->addFieldResolver('Static', 'notes', + $builder->produce('entity_reference_revisions') + ->map('entity', $builder->fromParent()) + ->map('field', $builder->fromValue('field_notes')) + ); + + $registry->addFieldResolver('Static', 'poid', + $builder->produce('property_path') + ->map('type', $builder->fromValue('entity:node')) + ->map('value', $builder->fromParent()) + ->map('path', $builder->fromValue('field_poid.value')) + ); + } + // ___ _ // | \ __ _| |_ ___ // | |) / _` | _/ -_)