瀏覽代碼

add queries mapitems(ids) & allmapitemsof(familyId)

axolotle 3 年之前
父節點
當前提交
9eb4584930

+ 10 - 1
src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls

@@ -3,12 +3,21 @@
 # }
 
 extend type Query {
-  mapitems: [MapItemInterface]
+  allmapitems: [MapItemInterface]
 }
+
+extend type Query {
+  mapitems(ids: [Int]): [MapItemInterface]
+}
+
 extend type Query {
   mapitem(id: Int!): MapItemInterface
 }
 
+extend type Query {
+  allmapitemsof(familyId: Int!): [MapItemInterface]
+}
+
 extend type Query {
   texts: [TextInterface]
 }

+ 34 - 1
src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php

@@ -168,7 +168,7 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
       throw new Error('Could not resolve content type.');
     });
 
-    $registry->addFieldResolver('Query', 'mapitems',
+    $registry->addFieldResolver('Query', 'allmapitems',
       $builder->compose(
           $builder->callback(function($parent, $arg){
             $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
@@ -184,11 +184,44 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
         )
     );
 
+    $registry->addFieldResolver('Query', 'mapitems',
+      $builder->compose(
+          $builder->callback(function($parent, $arg){
+            $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
+            $query = $entity_storage->getQuery()
+              ->condition('type', ['texte', 'texte_prod', 'creation'], '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', 'mapitem',
       $builder->produce('entity_load')
         ->map('type', $builder->fromValue('node'))
         ->map('id', $builder->fromArgument('id'))
     );
+
+    $registry->addFieldResolver('Query', 'allmapitemsof',
+      $builder->compose(
+          $builder->callback(function($parent, $arg){
+            $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
+            $query = $entity_storage->getQuery()
+              ->condition('type', ['texte', 'texte_prod'], 'IN')
+              ->condition('field_famille', $arg)
+              ->accessCheck(TRUE);
+            $results = $query->execute();
+            return $results;
+          }),
+          $builder->produce('entity_load_multiple')
+          ->map('type', $builder->fromValue('node'))
+          ->map('ids', $builder->fromParent())
+        )
+    );
   }
 
   //  _____        _        ___                     _