diff --git a/features/graphql/input_output.feature b/features/graphql/input_output.feature index 08bbb4c167..1a5bcb166b 100644 --- a/features/graphql/input_output.feature +++ b/features/graphql/input_output.feature @@ -148,7 +148,7 @@ Feature: GraphQL DTO input and output { "errors": [ { - "message": "Cannot query field \"id\" on type \"createDummyDtoNoOutputPayloadData\".", + "message": "Cannot query field \"id\" on type \"DummyDtoNoOutput\".", "extensions": { "category": "graphql" }, diff --git a/features/graphql/mutation.feature b/features/graphql/mutation.feature index 48c6a7781f..01b38f97e1 100644 --- a/features/graphql/mutation.feature +++ b/features/graphql/mutation.feature @@ -400,7 +400,7 @@ Feature: GraphQL mutation support And the header "Content-Type" should be equal to "application/json" And the JSON node "data.createFoo.foo.id" should be equal to "/foos/1" And the JSON node "data.createFoo.foo._id" should be equal to 1 - And the JSON node "data.createFoo.foo.__typename" should be equal to "createFooPayloadData" + And the JSON node "data.createFoo.foo.__typename" should be equal to "Foo" And the JSON node "data.createFoo.foo.name" should be equal to "A new one" And the JSON node "data.createFoo.foo.bar" should be equal to "new" And the JSON node "data.createFoo.clientMutationId" should be equal to "myId" diff --git a/src/GraphQl/Type/TypeBuilder.php b/src/GraphQl/Type/TypeBuilder.php index af6774f7b5..9378b922c8 100644 --- a/src/GraphQl/Type/TypeBuilder.php +++ b/src/GraphQl/Type/TypeBuilder.php @@ -115,11 +115,7 @@ public function getResourceObjectType(?string $resourceClass, ResourceMetadataCo 'resolveField' => $this->defaultFieldResolver, 'fields' => function () use ($resourceClass, $operation, $operationName, $resourceMetadataCollection, $input, $wrapData, $depth, $ioMetadata) { if ($wrapData) { - try { - $queryNormalizationContext = $operation instanceof Query ? ($resourceMetadataCollection->getOperation($operationName)->getNormalizationContext() ?? []) : []; - } catch (OperationNotFoundException $e) { - $queryNormalizationContext = []; - } + $queryNormalizationContext = $this->getQueryOperation($resourceMetadataCollection)?->getNormalizationContext() ?? []; try { $mutationNormalizationContext = $operation instanceof Mutation || $operation instanceof Subscription ? ($resourceMetadataCollection->getOperation($operationName)->getNormalizationContext() ?? []) : []; @@ -310,4 +306,18 @@ private function getPageBasedPaginationFields(GraphQLType $resourceType): array 'paginationInfo' => GraphQLType::nonNull($paginationInfoObjectType), ]; } + + private function getQueryOperation(ResourceMetadataCollection $resourceMetadataCollection): ?Operation + { + foreach ($resourceMetadataCollection as $resourceMetadata) { + foreach ($resourceMetadata->getGraphQlOperations() as $operation) { + // Filter the custom queries. + if ($operation instanceof Query && !$operation->getResolver()) { + return $operation; + } + } + } + + return null; + } }