From d9b128fabad0411089f882e239349361883cfc85 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 30 Jun 2021 10:27:41 +0200 Subject: [PATCH] gql missing field_creations on textref #1269 --- .vscode/launch.json | 26 +++++++++++++++++ .../graphql/enfr_extension.base.graphqls | 1 + .../graphql/enfr_extension.extension.graphqls | 4 +++ .../SchemaExtension/EnFrSchemaExtension.php | 28 +++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f3e19e2 --- /dev/null +++ b/.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 + } + ] +} \ No newline at end of file diff --git a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls b/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls index 9dcf02f..cb17b5a 100644 --- a/src/web/modules/custom/enfrancais_graphql/graphql/enfr_extension.base.graphqls +++ b/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 { 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 1b35004..937beb5 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 @@ -69,6 +69,10 @@ extend type Query { alltags: [Taxoterm] } +# extend type Query { +# famillytags(famillyid: Int!): [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 4e6da8f..fe2fe4f 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 @@ -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',