From ab16a9f516359083826481b706239f6c8d44cebe Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 29 May 2024 17:55:23 +0200 Subject: [PATCH] gql userentites query --- .../graphql/ouatt_extension.extension.graphqls | 4 ++++ .../SchemaExtension/OuattSchemaExtension.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls index b7a2569..5d7f9e1 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls +++ b/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 } diff --git a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php index 2137567..aa6fe56 100644 --- a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php +++ b/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'))