From 2fb90cb0cbfa3ece5fe7c58a5dbfec9048920456 Mon Sep 17 00:00:00 2001 From: bach Date: Fri, 12 Feb 2021 14:27:21 +0100 Subject: [PATCH] created textsdepart graphql query --- .../graphql/enfr_extension.extension.graphqls | 4 +++ .../SchemaExtension/EnFrSchemaExtension.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls b/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls index ff10960..019e039 100644 --- a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls +++ b/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 } diff --git a/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php b/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php index a8998b4..55addb5 100644 --- a/src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php +++ b/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()) + ) + ); + + } + // _____ _ __ // |_ _|____ _| |_ _ _ ___ / _| // | |/ -_) \ / _| '_/ -_) _|