diff --git a/src/Config/Processor/RelayProcessor.php b/src/Config/Processor/RelayProcessor.php index 16e5edd41..2ded244f4 100644 --- a/src/Config/Processor/RelayProcessor.php +++ b/src/Config/Processor/RelayProcessor.php @@ -33,6 +33,9 @@ private static function processRelayConfigs($typeName, $definitionBuilderClass, { foreach ($configs as $name => $config) { if (isset($config['type']) && \is_string($config['type']) && $typeName === $config['type']) { + + $configInherits = isset($config['inherits']) && \is_array($config['inherits']) ? $config['inherits'] : []; + $config = isset($config['config']) && \is_array($config['config']) ? $config['config'] : []; if (empty($config['class_name'])) { @@ -47,6 +50,10 @@ private static function processRelayConfigs($typeName, $definitionBuilderClass, $connectionDefinition = $builder->toMappingDefinition($config); + if (!empty($configInherits)) { + $connectionDefinition[$name]['inherits'] = $configInherits; + } + $configs = \array_replace($configs, $connectionDefinition); } } diff --git a/tests/Functional/App/config/mutation/mapping/Inputs.types.yml b/tests/Functional/App/config/mutation/mapping/Inputs.types.yml index 8a660baa1..ef1d4ffcd 100644 --- a/tests/Functional/App/config/mutation/mapping/Inputs.types.yml +++ b/tests/Functional/App/config/mutation/mapping/Inputs.types.yml @@ -9,6 +9,14 @@ simpleMutationWithThunkFieldsInput: fields: inputData : { type: "Int" } +simpleMutationWithInheritanceInput: + type: relay-mutation-input + inherits: + - simpleMutationWithThunkFieldsInput + config: + fields: + moreData : { type: "Int" } + simplePromiseMutationInput: type: relay-mutation-input config: diff --git a/tests/Functional/App/config/mutation/mapping/Payloads.types.yml b/tests/Functional/App/config/mutation/mapping/Payloads.types.yml index 02b61a1b3..6facebf16 100644 --- a/tests/Functional/App/config/mutation/mapping/Payloads.types.yml +++ b/tests/Functional/App/config/mutation/mapping/Payloads.types.yml @@ -10,6 +10,14 @@ simpleMutationWithThunkFieldsPayload: fields: result: { type: "Int" } +simpleMutationWithInheritancePayload: + type: relay-mutation-payload + inherits: + - simpleMutationWithThunkFieldsPayload + config: + fields: + more: { type: "Int" } + simplePromiseMutationPayload: type: relay-mutation-payload config: diff --git a/tests/Functional/App/config/mutation/mapping/RootMutation.types.yml b/tests/Functional/App/config/mutation/mapping/RootMutation.types.yml index 12cd89778..be62555cc 100644 --- a/tests/Functional/App/config/mutation/mapping/RootMutation.types.yml +++ b/tests/Functional/App/config/mutation/mapping/RootMutation.types.yml @@ -14,6 +14,12 @@ RootMutation: inputType: simpleMutationWithThunkFieldsInput payloadType: simpleMutationWithThunkFieldsPayload mutateAndGetPayload: "@=mutation('simple_mutation_with_thunk_fields', [value])" + simpleMutationWithInheritance: + builder: "Relay::Mutation" + builderConfig: + inputType: simpleMutationWithInheritanceInput + payloadType: simpleMutationWithInheritancePayload + mutateAndGetPayload: {result: 1234, more: 1337} simplePromiseMutation: builder: "Relay::Mutation" builderConfig: diff --git a/tests/Functional/Relay/Mutation/MutationTest.php b/tests/Functional/Relay/Mutation/MutationTest.php index 572a0282b..8c2990e4a 100644 --- a/tests/Functional/Relay/Mutation/MutationTest.php +++ b/tests/Functional/Relay/Mutation/MutationTest.php @@ -77,6 +77,28 @@ public function testSupportsThunksAsInputAndOutputFields() $this->assertGraphQL($query, $expectedData); } + public function testSupportsInheritanceOfInputAndOutputFields() + { + $query = <<<'EOF' +mutation M { + simpleMutationWithInheritance(input: {inputData: 1234, moreData: 1337, clientMutationId: "abc"}) { + result + more + clientMutationId + } +} +EOF; + $expectedData = [ + 'simpleMutationWithInheritance' => [ + 'result' => 1234, + 'more' => 1337, + 'clientMutationId' => 'abc', + ], + ]; + + $this->assertGraphQL($query, $expectedData); + } + public function testSupportsPromiseMutations() { $query = <<<'EOF' @@ -250,6 +272,26 @@ public function testContainsCorrectField() 'kind' => 'OBJECT', ], ], + [ + 'name' => 'simpleMutationWithInheritance', + 'args' => [ + [ + 'name' => 'input', + 'type' => [ + 'name' => null, + 'kind' => 'NON_NULL', + 'ofType' => [ + 'name' => 'simpleMutationWithInheritanceInput', + 'kind' => 'INPUT_OBJECT', + ], + ], + ], + ], + 'type' => [ + 'name' => 'simpleMutationWithInheritancePayload', + 'kind' => 'OBJECT', + ], + ], [ 'name' => 'simplePromiseMutation', 'args' => [