Skip to content

Commit

Permalink
[Bug]: Can't fetch data of editables for documents with inheritance (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>

* Added force parameter when inherited editables are requested

---------

Co-authored-by: mcop1 <[email protected]>
Co-authored-by: robertSt7 <[email protected]>
  • Loading branch information
3 people authored Feb 13, 2023
1 parent 6e53ad0 commit c583e1e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"require": {
"php": "^8.0",
"pimcore/pimcore": "^10.5",
"pimcore/pimcore": "^10.5.16",
"webonyx/graphql-php": "^14.6"
},
"require-dev": {
Expand Down
16 changes: 16 additions & 0 deletions doc/10_GraphQL/04_Query/01_Document_Queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/GraphQL/DocumentResolver/PageSnippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 7 additions & 0 deletions src/GraphQL/DocumentType/PageSnippetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
];

Expand Down

0 comments on commit c583e1e

Please sign in to comment.