Skip to content

[Bug]: mutation must have unique named fields from objectbrick #894

Open

Description

@LeonNoBears

Expected behavior

Mutation is possible by calling the fields by either only their code e.g. foo or with the objec obrick as a prefix e.g. ObjectBrickFoo.foo

Actual behavior

gives an error because the label is picked and set in the scema.

Steps to reproduce

  1. Create a Class (MyClass)
  2. Create a object brick (ObjectBrickFoo), with a datatype table (code: foo, label: table)
  3. Create another object brick (ObjectBrickBar), with a datatype table (code: bar, label: table)
  4. link both the object bricks to the class.
  5. open mutation schema and setup the fields of the class (ObjectBrickFoo.foo and ObjectBrickBar.bar)
  6. fire a mutation and recieve error:
{
  "errors": [
    {
      "message": "Schema must contain unique named types but contains multiple types named \"TableInput\" (see [Introduction - graphql-php](https://webonyx.github.io/graphql-php/type-definitions/#type-registry).) "
    }
  ]
}

Activity

  1. br33f commented on Oct 24, 2024

    @br33f

    Does anyone have a workaround for this one?

  2. br33f commented on Oct 25, 2024

    @br33f

    @LeonNoBears
    Here is how I fixed this problem (at least temporarly):

    In file \Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectMutationFieldConfigGenerator\Table::getGraphQlMutationFieldConfig

    public function getGraphQlMutationFieldConfig($nodeDef, $class, $container = null, $params = [])
        {
            $fieldName = $nodeDef['attributes']['attribute'];
            $tableDef = $this->getGraphQlService()->getObjectFieldHelper()->getFieldDefinitionFromKey($class, $fieldName);
            $inputItems = [];
            $numCols = 0;
    
            if ($tableDef instanceof Data\Table) {
                $numCols = (int) $tableDef->getCols();
            }
    
            $this->getProcessors($processors, $tableDef);
    
            $processor = new \Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectInputProcessor\Table($nodeDef, $processors);
            $processor->setGraphQLService($this->getGraphQlService());
    
            foreach (range(0, $numCols - 1) as $i) {
                $inputItems['col' . $i] = Type::string();
            }
           // Here the changes start
    
            $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,
                'processor' => [$processor, 'process'],
            ];
        }
    

    This problem is also present in "Image Gallery" and can be fixed analogically.

    Basically, if you reuse the same "name" you should make sure to also use the exact same instance. Originally for each new field of type "Table" or "Image gallery" new instance of InputObjectType was created. And if different instances share the same "name", then: \GraphQL\Utils\TypeInfo::extractTypes throws an exception.

  3. github-actions commented on Nov 15, 2024

    @github-actions
    Contributor

    Thanks a lot for reporting the issue. We did not consider the issue as "Pimcore:Priority", "Pimcore:ToDo" or "Pimcore:Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Affected capability

    None yet

    Platform Version

    None yet

    Galaxy

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions