From 26c80c8f27298d2403720c9c2cace8192808dba7 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 13 Jul 2023 12:40:00 +0200 Subject: [PATCH] getting revisions from graphql #2203 --- .../graphql/ouatt_extension.base.graphqls | 1 + .../ouatt_extension.extension.graphqls | 4 +++ .../SchemaExtension/OuattSchemaExtension.php | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls index 43276df..1d2723a 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls +++ b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.base.graphqls @@ -9,6 +9,7 @@ interface NodeInterface { type Concernement implements NodeInterface { id: Int! + revision_id: Int! path: String! uuid: String! bundle: String! diff --git a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls index 4c3855b..b7a2569 100644 --- a/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls +++ b/src/web/modules/custom/ouatt_graphql/graphql/ouatt_extension.extension.graphqls @@ -15,6 +15,10 @@ extend type Query { concernement(id: Int!): Concernement } +extend type Query { + concernementrevisions(id: Int!): [Concernement] +} + extend type Query { allentites: [Entite] } diff --git a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php index 5ae6e07..a2f51a3 100644 --- a/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php +++ b/src/web/modules/custom/ouatt_graphql/src/Plugin/GraphQL/SchemaExtension/OuattSchemaExtension.php @@ -154,11 +154,36 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase { ->map('id', $builder->fromArgument('id')) ); + $registry->addFieldResolver('Query', 'concernementrevisions', + $builder->compose( + $builder->produce('entity_load') + ->map('type', $builder->fromValue('node')) + ->map('id', $builder->fromArgument('id')), + $builder->callback(function($parent, $arg){ + $vids = \Drupal::entityTypeManager()->getStorage('node')->revisionIds($parent); + $revisions = []; + foreach($vids as $vid){ + $revisions[] = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($vid); + } + return $revisions; + }) + ) + ); + $registry->addFieldResolver('Concernement', 'id', $builder->produce('entity_id') ->map('entity', $builder->fromParent()) ); + $registry->addFieldResolver('Concernement', 'revision_id', + $builder->compose( + $builder->callback(function($parent, $arg){ + $revid = $parent->getRevisionId(); + return $revid; + }) + ) + ); + $registry->addFieldResolver('Concernement', 'uuid', $builder->produce('entity_uuid') ->map('entity', $builder->fromParent()) @@ -269,6 +294,14 @@ class OuattSchemaExtension extends SdlSchemaExtensionPluginBase { ->map('entity', $builder->fromParent()) ->map('field', $builder->fromValue('field_doleancer')) ); + + // revisions: [Concernement] + $registry->addFieldResolver('Concernement', 'revisions', + $builder->produce('entity_reference') + ->map('entity', $builder->fromParent()) + ->map('field', $builder->fromValue('field_doleancer')) + ); + } // _____ _ _ _ __ ___ _ __ __