Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Config/Processor/RelayProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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);
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Functional/App/config/mutation/mapping/Inputs.types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions tests/Functional/Relay/Mutation/MutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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' => [
Expand Down