Prechádzať zdrojové kódy

getting revisions from graphql #2203

bach 1 rok pred
rodič
commit
26c80c8f27

+ 1 - 0
src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls

@@ -9,6 +9,7 @@ interface NodeInterface {
 
 type Concernement implements NodeInterface {
   id: Int!
+  revision_id: Int!
   path: String!
   uuid: String!
   bundle: String!

+ 4 - 0
src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls

@@ -15,6 +15,10 @@ extend type Query {
   concernement(id: Int!): Concernement
 }
 
+extend type Query {
+  concernementrevisions(id: Int!): [Concernement]
+}
+
 extend type Query {
   allentites: [Entite]
 }

+ 33 - 0
src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php

@@ -154,11 +154,36 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
         ->map('id', $builder->fromArgument('id'))
     );
 
+    $registry->addFieldResolver('Query', 'concernementrevisions',
+      $builder->compose(
+        $builder->produce('entity_load')
+        ->map('type', $builder->fromValue('node'))
+        ->map('id', $builder->fromArgument('id')),
+        $builder->callback(function($parent, $arg){
+          $vids = \Drupal::entityTypeManager()->getStorage('node')->revisionIds($parent);
+          $revisions = [];
+          foreach($vids as $vid){
+            $revisions[] = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid);
+          }
+          return $revisions;
+        })
+      )
+    );
+
     $registry->addFieldResolver('Concernement', 'id',
       $builder->produce('entity_id')
         ->map('entity', $builder->fromParent())
       );
 
+    $registry->addFieldResolver('Concernement', 'revision_id',
+      $builder->compose(
+        $builder->callback(function($parent, $arg){
+          $revid = $parent->getRevisionId();
+          return $revid;
+        })
+      )
+    );
+
     $registry->addFieldResolver('Concernement', 'uuid',
       $builder->produce('entity_uuid')
         ->map('entity', $builder->fromParent())
@@ -269,6 +294,14 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
         ->map('entity', $builder->fromParent())
         ->map('field', $builder->fromValue('field_doleancer'))
     );
+
+    // revisions: [Concernement]
+    $registry->addFieldResolver('Concernement', 'revisions',
+      $builder->produce('entity_reference')
+        ->map('entity', $builder->fromParent())
+        ->map('field', $builder->fromValue('field_doleancer'))
+    );
+  
   }
 
   //   _____       _   _ _    __        ___       _    __             __