Browse Source

gql userentites query

bach 6 months ago
parent
commit
ab16a9f516

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

@@ -27,6 +27,10 @@ extend type Query {
   entites(ids: [Int]): [Entite]
 }
 
+extend type Query {
+  userentites(uid: Int!, time:String): [Entite]
+}
+
 extend type Query {
   entite(id: Int!): Entite
 }

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

@@ -421,6 +421,23 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase {
         )
     );
 
+    $registry->addFieldResolver('Query', 'userentites',
+      $builder->compose(
+          $builder->callback(function($parent, $arg){
+            $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
+            $query = $entity_storage->getQuery()
+              ->condition('type', ['entite'], 'IN')
+              ->condition('uid', $arg['uid'])
+              ->accessCheck(TRUE);
+            $results = $query->execute();
+            return $results;
+          }),
+          $builder->produce('entity_load_multiple')
+          ->map('type', $builder->fromValue('node'))
+          ->map('ids', $builder->fromParent())
+        )
+    );
+
     $registry->addFieldResolver('Query', 'entite',
       $builder->produce('entity_load')
         ->map('type', $builder->fromValue('node'))