From c583e1edd8ce45e12ba516d85630c74442d08cdb Mon Sep 17 00:00:00 2001 From: mcop1 <89011527+mcop1@users.noreply.github.com> Date: Mon, 13 Feb 2023 18:05:47 +0100 Subject: [PATCH] [Bug]: Can't fetch data of editables for documents with inheritance (#694) * [Bug]: Can't fetch data of editables for documents with inheritance * Sample query * Added check for method getGetInheritedValues * Apply php-cs-fixer changes * Added comment for method exists calls * Added check for method getGetInheritedValues * Changed required pimcore version * Update src/GraphQL/DocumentType/PageSnippetType.php Co-authored-by: robertSt7 <104770750+robertSt7@users.noreply.github.com> * Added force parameter when inherited editables are requested --------- Co-authored-by: mcop1 Co-authored-by: robertSt7 <104770750+robertSt7@users.noreply.github.com> --- composer.json | 2 +- doc/10_GraphQL/04_Query/01_Document_Queries.md | 16 ++++++++++++++++ src/GraphQL/DocumentResolver/PageSnippet.php | 9 ++++++++- src/GraphQL/DocumentType/PageSnippetType.php | 7 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0e1dbb83..dbe0195b 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "require": { "php": "^8.0", - "pimcore/pimcore": "^10.5", + "pimcore/pimcore": "^10.5.16", "webonyx/graphql-php": "^14.6" }, "require-dev": { diff --git a/doc/10_GraphQL/04_Query/01_Document_Queries.md b/doc/10_GraphQL/04_Query/01_Document_Queries.md index b18c6b30..812571ce 100644 --- a/doc/10_GraphQL/04_Query/01_Document_Queries.md +++ b/doc/10_GraphQL/04_Query/01_Document_Queries.md @@ -53,6 +53,22 @@ } ``` + +### Fetch Document Page and get all editables, including the inherited editables + +```graphql +{ + getDocument(id: 207) { + ... on document_page { + id, + editables(getInheritedValues: true ){ + __typename + } + } + } +} +``` + ## Fetch Document Page via data object relation and get more editable data * get data object ID 61 diff --git a/src/GraphQL/DocumentResolver/PageSnippet.php b/src/GraphQL/DocumentResolver/PageSnippet.php index 01863132..76903800 100644 --- a/src/GraphQL/DocumentResolver/PageSnippet.php +++ b/src/GraphQL/DocumentResolver/PageSnippet.php @@ -39,13 +39,20 @@ class PageSnippet public function resolveElements($value = null, $args = [], $context = [], ResolveInfo $resolveInfo = null) { $documentId = $value['id']; - $document = Document::getById($documentId); + $getInheritedValuesInput = $args['getInheritedValues'] ?? false; + $document = Document::getById($documentId, ['force' => $getInheritedValuesInput]); if ($document instanceof Document\PageSnippet) { $result = []; $sortBy = []; + + $getInheritedValues = Document\PageSnippet::getGetInheritedValues(); + Document\PageSnippet::setGetInheritedValues($getInheritedValuesInput); + $elements = $document->getEditables(); + Document\PageSnippet::setGetInheritedValues($getInheritedValues); + $service = $this->getGraphQlService(); $supportedTypeNames = $service->getSupportedDocumentElementQueryDataTypes(); diff --git a/src/GraphQL/DocumentType/PageSnippetType.php b/src/GraphQL/DocumentType/PageSnippetType.php index 2d10181e..403f3996 100644 --- a/src/GraphQL/DocumentType/PageSnippetType.php +++ b/src/GraphQL/DocumentType/PageSnippetType.php @@ -53,6 +53,13 @@ public function build(&$config) $config['fields']['editables'] = [ 'type' => Type::listOf($this->documentElementType), + 'args' => [ + 'getInheritedValues' => [ + 'type' => Type::boolean(), + 'description' => 'Whether inherited editables should be fetched or not.', + 'defaultValue' => false + ], + ], 'resolve' => [$resolver, 'resolveElements'] ];