Explorar o código

created textsdepart graphql query

bach %!s(int64=3) %!d(string=hai) anos
pai
achega
2fb90cb0cb

+ 4 - 0
src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls

@@ -2,6 +2,10 @@
 #   route(path: String!): NodeInterface
 # }
 
+extend type Query {
+  textsdepart: [Textref]
+}
+
 extend type Query {
   textref(id: Int!): Textref
 }

+ 28 - 0
src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php

@@ -29,6 +29,8 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
 
     $this->addRouteResolver($registry, $builder);
 
+    $this->addTextsdepart($registry, $builder);
+
     $this->addTextref($registry, $builder);
 
     $this->addTextprod($registry, $builder);
@@ -104,6 +106,32 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
   }
 
 
+  //  _____        _        ___                     _
+  // |_   _|____ _| |_ ___ |   \ ___ _ __  __ _ _ _| |_
+  //   | |/ -_) \ /  _(_-< | |) / -_) '_ \/ _` | '_|  _|
+  //   |_|\___/_\_\\__/__/ |___/\___| .__/\__,_|_|  \__|
+  //                                |_|
+  protected function addTextsdepart(ResolverRegistryInterface $registry, ResolverBuilder $builder) {
+
+    $registry->addFieldResolver('Query', 'textsdepart',
+      $builder->compose(
+          $builder->callback(function($parent, $arg){
+            $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
+            $query = $entity_storage->getQuery()
+              ->condition('type', 'texte')
+              ->condition('field_famille', 9)
+              ->accessCheck(TRUE);
+            $results = $query->execute();
+            return $results;
+          }),
+          $builder->produce('entity_load_multiple')
+          ->map('type', $builder->fromValue('node'))
+          ->map('ids', $builder->fromParent())
+        )
+    );
+
+  }
+
   //  _____        _            __
   // |_   _|____ _| |_ _ _ ___ / _|
   //   | |/ -_) \ /  _| '_/ -_)  _|