Skip to content

Commit 608518d

Browse files
authored
fix(graphql): type builder output (#4791)
* Revert "fix(graphql): output creates its own type in TypeBuilder (#4766)" This reverts commit 1f4085e. * fix: resources order
1 parent 4c16efe commit 608518d

File tree

13 files changed

+20
-224
lines changed

13 files changed

+20
-224
lines changed

features/graphql/mutation.feature

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -819,26 +819,6 @@ Feature: GraphQL mutation support
819819
And the JSON node "data.testCustomArgumentsDummyCustomMutation.dummyCustomMutation.result" should be equal to "18"
820820
And the JSON node "data.testCustomArgumentsDummyCustomMutation.clientMutationId" should be equal to "myId"
821821

822-
Scenario: Execute a custom mutation with output
823-
When I send the following GraphQL request:
824-
"""
825-
mutation {
826-
testOutputDummyCustomMutation(input: {id: "/dummy_custom_mutations/1", operandA: 9, clientMutationId: "myId"}) {
827-
dummyCustomMutation {
828-
baz
829-
bat
830-
}
831-
clientMutationId
832-
}
833-
}
834-
"""
835-
Then the response status code should be 200
836-
And the response should be in JSON
837-
And the header "Content-Type" should be equal to "application/json"
838-
And the JSON node "data.testOutputDummyCustomMutation.dummyCustomMutation.baz" should be equal to "98"
839-
And the JSON node "data.testOutputDummyCustomMutation.dummyCustomMutation.bat" should be equal to "9"
840-
And the JSON node "data.testOutputDummyCustomMutation.clientMutationId" should be equal to "myId"
841-
842822
Scenario: Uploading a file with a custom mutation
843823
Given I have the following file for a GraphQL request:
844824
| name | file |

features/graphql/query.feature

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -432,32 +432,6 @@ Feature: GraphQL query support
432432
}
433433
"""
434434

435-
Scenario: Custom item query with output
436-
Given there are 2 dummyCustomQuery objects
437-
When I send the following GraphQL request:
438-
"""
439-
{
440-
testItemOutputDummyCustomQuery(id: "/dummy_custom_queries/1",) {
441-
baz
442-
bat
443-
}
444-
}
445-
"""
446-
Then the response status code should be 200
447-
And the response should be in JSON
448-
And the header "Content-Type" should be equal to "application/json"
449-
And the JSON should be equal to:
450-
"""
451-
{
452-
"data": {
453-
"testItemOutputDummyCustomQuery": {
454-
"baz": 46,
455-
"bat": "Success!"
456-
}
457-
}
458-
}
459-
"""
460-
461435
@createSchema
462436
Scenario: Retrieve an item with different serialization groups for item_query and collection_query
463437
Given there are 1 dummy with different GraphQL serialization groups objects

src/Core/GraphQl/Type/TypeBuilder.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadata $
5454
{
5555
$shortName = $resourceMetadata->getShortName();
5656

57-
$ioMetadata = $resourceMetadata->getGraphqlAttribute($subscriptionName ?? $mutationName ?? $queryName, $input ? 'input' : 'output', null, true);
58-
if (null !== $ioMetadata && \array_key_exists('class', $ioMetadata) && null !== $ioMetadata['class']) {
59-
$resourceClass = $ioMetadata['class'];
60-
$shortName = $ioMetadata['name'];
61-
}
62-
6357
if (null !== $mutationName) {
6458
$shortName = $mutationName.ucfirst($shortName);
6559
}
@@ -99,6 +93,11 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadata $
9993
return $resourceObjectType;
10094
}
10195

96+
$ioMetadata = $resourceMetadata->getGraphqlAttribute($subscriptionName ?? $mutationName ?? $queryName, $input ? 'input' : 'output', null, true);
97+
if (null !== $ioMetadata && \array_key_exists('class', $ioMetadata) && null !== $ioMetadata['class']) {
98+
$resourceClass = $ioMetadata['class'];
99+
}
100+
102101
$wrapData = !$wrapped && (null !== $mutationName || null !== $subscriptionName) && !$input && $depth < 1;
103102

104103
$configuration = [

src/GraphQl/Type/TypeBuilder.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadataCo
5959
$shortName = $operation->getShortName();
6060
$operationName = $operation->getName();
6161

62-
$ioMetadata = $input ? $operation->getInput() : $operation->getOutput();
63-
if (null !== $ioMetadata && \array_key_exists('class', $ioMetadata) && null !== $ioMetadata['class']) {
64-
$resourceClass = $ioMetadata['class'];
65-
$shortName = $ioMetadata['name'] ?? $shortName;
66-
}
67-
6862
if ($operation instanceof Mutation) {
6963
$shortName = $operationName.ucfirst($shortName);
7064
}
@@ -108,6 +102,11 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadataCo
108102
return $resourceObjectType;
109103
}
110104

105+
$ioMetadata = $input ? $operation->getInput() : $operation->getOutput();
106+
if (null !== $ioMetadata && \array_key_exists('class', $ioMetadata) && null !== $ioMetadata['class']) {
107+
$resourceClass = $ioMetadata['class'];
108+
}
109+
111110
$wrapData = !$wrapped && ($operation instanceof Mutation || $operation instanceof Subscription) && !$input && $depth < 1;
112111

113112
$configuration = [

src/Util/ReflectionClassRecursiveIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public static function getReflectionClassesFromDirectories(array $directories):
5656
}
5757
}
5858

59-
$declared = array_merge(get_declared_classes(), get_declared_interfaces());
59+
$sortedClasses = get_declared_classes();
60+
sort($sortedClasses);
61+
$sortedInterfaces = get_declared_interfaces();
62+
sort($sortedInterfaces);
63+
$declared = array_merge($sortedClasses, $sortedInterfaces);
6064
foreach ($declared as $className) {
6165
$reflectionClass = new \ReflectionClass($className);
6266
$sourceFile = $reflectionClass->getFileName();

tests/Fixtures/TestBundle/DataTransformer/DummyCustomMutationDtoDataTransformer.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/Fixtures/TestBundle/DataTransformer/DummyCustomQueryDtoDataTransformer.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/Fixtures/TestBundle/Document/DummyCustomMutation.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document;
1515

1616
use ApiPlatform\Core\Annotation\ApiResource;
17-
use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto;
1817
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1918
use Symfony\Component\Serializer\Annotation\Groups;
2019

@@ -51,10 +50,6 @@
5150
* "testCustomArguments"={
5251
* "mutation"="app.graphql.mutation_resolver.dummy_custom",
5352
* "args"={"operandC"={"type"="Int!"}}
54-
* },
55-
* "testOutput"={
56-
* "mutation"="app.graphql.mutation_resolver.dummy_custom",
57-
* "output"=OutputDto::class
5853
* }
5954
* })
6055
*

tests/Fixtures/TestBundle/Document/DummyCustomQuery.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document;
1515

1616
use ApiPlatform\Core\Annotation\ApiResource;
17-
use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto;
1817
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1918

2019
/**
@@ -48,10 +47,6 @@
4847
* "customArgumentCustomType"={"type"="DateTime!"}
4948
* }
5049
* },
51-
* "testItemOutput"={
52-
* "item_query"="app.graphql.query_resolver.dummy_custom_item",
53-
* "output"=OutputDto::class
54-
* },
5550
* "testCollection"={
5651
* "collection_query"="app.graphql.query_resolver.dummy_custom_collection"
5752
* },

tests/Fixtures/TestBundle/Entity/DummyCustomMutation.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
1515

1616
use ApiPlatform\Core\Annotation\ApiResource;
17-
use ApiPlatform\Tests\Fixtures\TestBundle\Dto\OutputDto;
1817
use Doctrine\ORM\Mapping as ORM;
1918
use Symfony\Component\Serializer\Annotation\Groups;
2019

@@ -51,10 +50,6 @@
5150
* "testCustomArguments"={
5251
* "mutation"="app.graphql.mutation_resolver.dummy_custom",
5352
* "args"={"operandC"={"type"="Int!"}}
54-
* },
55-
* "testOutput"={
56-
* "mutation"="app.graphql.mutation_resolver.dummy_custom",
57-
* "output"=OutputDto::class
5853
* }
5954
* })
6055
*

0 commit comments

Comments
 (0)