From 5322021d28c50a8eb6ec34ebd3cd6387ac42f810 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 8 Apr 2021 19:55:16 +0200 Subject: [PATCH] gql query alltags --- .../graphql/enfr_extension.extension.graphqls | 4 ++++ .../SchemaExtension/EnFrSchemaExtension.php | 16 ++++++++++++++++ 2 files changed, 20 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 9a22f0f..f5f76bc 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 @@ -46,6 +46,10 @@ extend type Query { famille(id: Int!): Taxoterm } +extend type Query { + alltags: [Taxoterm] +} + extend type Query { tag(id: Int!): Taxoterm } 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 5a37bf4..fd53a18 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 @@ -815,6 +815,22 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase { // |_|\__,_\__, | // |___/ protected function addTaxoterm(ResolverRegistryInterface $registry, ResolverBuilder $builder) { + $registry->addFieldResolver('Query', 'alltags', + $builder->compose( + $builder->callback(function($parent, $arg){ + $entity_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); + $query = $entity_storage->getQuery() + ->condition('vid', ['tags', 'tag_prod'], 'IN') + ->accessCheck(TRUE); + $results = $query->execute(); + return $results; + }), + $builder->produce('entity_load_multiple') + ->map('type', $builder->fromValue('taxonomy_term')) + ->map('ids', $builder->fromParent()) + ) + ); + $registry->addFieldResolver('Query', 'tag', $builder->produce('entity_load') ->map('type', $builder->fromValue('taxonomy_term'))