bach 3 лет назад
Родитель
Сommit
59ac63f160

+ 13 - 0
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

+ 12 - 0
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
 }

+ 106 - 0
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'))
+    );
+  }
+
   //  ___       _
   // |   \ __ _| |_ ___
   // | |) / _` |  _/ -_)