Skip to content

Commit f37afb0

Browse files
committed
fix(graphql): wrapped type should always take the query normalization context
1 parent ca6353c commit f37afb0

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

features/graphql/input_output.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Feature: GraphQL DTO input and output
148148
{
149149
"errors": [
150150
{
151-
"message": "Cannot query field \"id\" on type \"createDummyDtoNoOutputPayloadData\".",
151+
"message": "Cannot query field \"id\" on type \"DummyDtoNoOutput\".",
152152
"extensions": {
153153
"category": "graphql"
154154
},

features/graphql/mutation.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Feature: GraphQL mutation support
400400
And the header "Content-Type" should be equal to "application/json"
401401
And the JSON node "data.createFoo.foo.id" should be equal to "/foos/1"
402402
And the JSON node "data.createFoo.foo._id" should be equal to 1
403-
And the JSON node "data.createFoo.foo.__typename" should be equal to "createFooPayloadData"
403+
And the JSON node "data.createFoo.foo.__typename" should be equal to "Foo"
404404
And the JSON node "data.createFoo.foo.name" should be equal to "A new one"
405405
And the JSON node "data.createFoo.foo.bar" should be equal to "new"
406406
And the JSON node "data.createFoo.clientMutationId" should be equal to "myId"

src/GraphQl/Type/TypeBuilder.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,7 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadataCo
115115
'resolveField' => $this->defaultFieldResolver,
116116
'fields' => function () use ($resourceClass, $operation, $operationName, $resourceMetadataCollection, $input, $wrapData, $depth, $ioMetadata) {
117117
if ($wrapData) {
118-
try {
119-
$queryNormalizationContext = $operation instanceof Query ? ($resourceMetadataCollection->getOperation($operationName)->getNormalizationContext() ?? []) : [];
120-
} catch (OperationNotFoundException $e) {
121-
$queryNormalizationContext = [];
122-
}
118+
$queryNormalizationContext = $this->getQueryOperation($resourceMetadataCollection)?->getNormalizationContext() ?? [];
123119

124120
try {
125121
$mutationNormalizationContext = $operation instanceof Mutation || $operation instanceof Subscription ? ($resourceMetadataCollection->getOperation($operationName)->getNormalizationContext() ?? []) : [];
@@ -310,4 +306,18 @@ private function getPageBasedPaginationFields(GraphQLType $resourceType): array
310306
'paginationInfo' => GraphQLType::nonNull($paginationInfoObjectType),
311307
];
312308
}
309+
310+
private function getQueryOperation(ResourceMetadataCollection $resourceMetadataCollection): ?Operation
311+
{
312+
foreach ($resourceMetadataCollection as $resourceMetadata) {
313+
foreach ($resourceMetadata->getGraphQlOperations() as $operation) {
314+
// Filter the custom queries.
315+
if ($operation instanceof Query && !$operation->getResolver()) {
316+
return $operation;
317+
}
318+
}
319+
}
320+
321+
return null;
322+
}
313323
}

0 commit comments

Comments
 (0)