Jelajahi Sumber

gql query alltags

bach 3 tahun lalu
induk
melakukan
5322021d28

+ 4 - 0
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
 }

+ 16 - 0
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'))