Browse Source

gql missing field_creations on textref #1269

bach 2 years ago
parent
commit
d9b128faba

+ 26 - 0
.vscode/launch.json

@@ -0,0 +1,26 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Listen for Xdebug",
+            "type": "php",
+            "request": "launch",
+            "serverSourceRoot":"192.168.0.21"
+            "port": 9001,
+            "pathMappings": {
+                "/var/www/html/d8.materio.com/public_html": "${workspaceFolder}"
+            },
+        },
+        {
+            "name": "Launch currently open script",
+            "type": "php",
+            "request": "launch",
+            "program": "${file}",
+            "cwd": "${fileDirname}",
+            "port": 9001
+        }
+    ]
+}

+ 1 - 0
src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls

@@ -53,6 +53,7 @@ type Textref implements NodeInterface & TextInterface & MapItemInterface{
   tags: [Taxoterm]
   degres_detrangement: Int
   notes: [Noteref]
+  field_creations: [Creation]
 }
 
 type Textprod implements NodeInterface & TextInterface & MapItemInterface {

+ 4 - 0
src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.extension.graphqls

@@ -69,6 +69,10 @@ extend type Query {
   alltags: [Taxoterm]
 }
 
+# extend type Query {
+#   famillytags(famillyid: Int!): [Taxoterm]
+# }
+
 extend type Query {
   tag(id: Int!): Taxoterm
 }

+ 28 - 0
src/web/modules/custom/enfrancais_graphql/src/Plugin/GraphQL/SchemaExtension/EnFrSchemaExtension.php

@@ -156,6 +156,7 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
     );
   }
 
+  // MapItems
   protected function addMapItems(ResolverRegistryInterface $registry, ResolverBuilder $builder){
     // Tell GraphQL how to resolve types of a common interface.
     $registry->addTypeResolver('MapItemInterface', function ($value) {
@@ -304,6 +305,13 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
           ->map('field', $builder->fromValue('field_textes_produits'))
       ));
 
+    $registry->addFieldResolver('Textref', 'field_creations',
+      $builder->compose(
+        $builder->produce('entity_reference')
+          ->map('entity', $builder->fromParent())
+          ->map('field', $builder->fromValue('field_creations'))
+      ));
+
     $registry->addFieldResolver('Textref', 'images',
       $builder->produce('entity_reference')
         ->map('entity', $builder->fromParent())
@@ -1035,6 +1043,26 @@ class EnFrSchemaExtension extends SdlSchemaExtensionPluginBase {
        ->map('id', $builder->fromArgument('id'))
      );
 
+    // get all tags for a given familly
+    // $registry->addFieldResolver('Query', 'famillytags',
+    //   $builder->compose(
+    //     $builder->callback(function($parent, $arg){
+    //       $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
+    //       $query = $entity_storage->getQuery()
+    //         ->condition('type', ['texte', 'texte_prod'], 'IN')
+    //         ->condition('field_famille', $arg->famillyid)
+    //         ->accessCheck(TRUE);
+    //       $results = $query->execute();
+    //       return $results;
+    //     }),
+    //     $builder->produce('entity_load_multiple')
+    //     ->map('type', $builder->fromValue('node'))
+    //     ->map('ids', $builder->fromParent())
+    //     //  $builder->produce('entity_load_multiple')
+    //     //  ->map('type', $builder->fromValue('taxonomy_term'))
+    //     //  ->map('ids', $builder->fromParent())
+    //   )
+    // );
 
 
     $registry->addFieldResolver('Taxoterm', 'id',