Skip to content

Commit

Permalink
Mutation unique named fields (TableInput, RowInput, GalleryImageInput…
Browse files Browse the repository at this point in the history
…, ImageGalleryInput) bug fix
  • Loading branch information
dzamojski-epoint committed Oct 24, 2024
1 parent d21e3f3 commit 3acaa66
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 33 deletions.
50 changes: 33 additions & 17 deletions src/GraphQL/DataObjectMutationFieldConfigGenerator/ImageGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,41 @@ public function getGraphQlMutationFieldConfig($nodeDef, $class, $container = nul
$processor = new \Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectInputProcessor\ImageGallery($nodeDef);
$processor->setGraphQLService($this->getGraphQlService());

$imageInput = new InputObjectType([
'name' => 'GalleryImageInput',
'fields' => [
'id' => Type::int(),
],
]);

$inputType = new InputObjectType([
'name' => 'ImageGalleryInput',
'fields' => [
'replace' => [
'type' => Type::boolean(),
'description' => 'if true then the entire gallery list will be overwritten',
$dataTypes = $this->getGraphQlService()->getDataObjectDataTypes();

$imageInput = array_key_exists('gallery_image_input', $dataTypes)
? $dataTypes['gallery_image_input']
: new InputObjectType([
'name' => 'GalleryImageInput',
'fields' => [
'id' => Type::int(),
],
'images' => [
'type' => Type::listOf($imageInput),
]);

$inputType = array_key_exists('image_gallery_input', $dataTypes)
? $dataTypes['image_gallery_input']
: new InputObjectType([
'name' => 'ImageGalleryInput',
'fields' => [
'replace' => [
'type' => Type::boolean(),
'description' => 'if true then the entire gallery list will be overwritten',
],
'images' => [
'type' => Type::listOf($imageInput),
],
],
],
]);
]);


if (!array_key_exists('gallery_image_input', $dataTypes) && !array_key_exists('image_gallery_input', $params) ) {
$newDataTypes = [
'gallery_image_input' => $imageInput,
'image_gallery_input' => $inputType
];

$this->getGraphQlService()->registerDataObjectDataTypes($dataTypes + $newDataTypes);
}

return [
'arg' => $inputType,
Expand Down
47 changes: 31 additions & 16 deletions src/GraphQL/DataObjectMutationFieldConfigGenerator/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,38 @@ public function getGraphQlMutationFieldConfig($nodeDef, $class, $container = nul
$inputItems['col' . $i] = Type::string();
}

$rowInput = new InputObjectType([
'name' => 'RowInput',
'fields' => $inputItems,
]);

$inputType = new InputObjectType([
'name' => 'TableInput',
'fields' => [
'replace' => [
'type' => Type::boolean(),
'description' => 'if true then the entire table will be overwritten',
],
'rows' => [
'type' => Type::listOf($rowInput),
$dataTypes = $this->getGraphQlService()->getDataObjectDataTypes();

$rowInput = array_key_exists('row_input', $dataTypes)
? $dataTypes['row_input']
: new InputObjectType([
'name' => 'RowInput',
'fields' => $inputItems,
]);

$inputType = array_key_exists('table_input', $dataTypes)
? $dataTypes['table_input']
: new InputObjectType([
'name' => 'TableInput',
'fields' => [
'replace' => [
'type' => Type::boolean(),
'description' => 'if true then the entire table will be overwritten',
],
'rows' => [
'type' => Type::listOf($rowInput),
],
],
],
]);
]);

if (!array_key_exists('row_input', $dataTypes) && !array_key_exists('table_input', $params) ) {
$newDataTypes = [
'row_input' => $rowInput,
'table_input' => $inputType
];

$this->getGraphQlService()->registerDataObjectDataTypes($dataTypes + $newDataTypes);
}

return [
'arg' => $inputType,
Expand Down

0 comments on commit 3acaa66

Please sign in to comment.