Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ private function buildResourceOperations(array $metadataCollection, string $reso
}

if ($metadata instanceof GraphQlOperation) {
if (-1 === $index) {
$resources[++$index] = $this->getResourceWithDefaults($resourceClass, $shortName, new ApiResource());
}
[$key, $operation] = $this->getOperationWithDefaults($resources[$index], $metadata);
$graphQlOperations = $resources[$index]->getGraphQlOperations();
$graphQlOperations[$key] = $operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
[$key, $operation] = $this->getOperationWithDefaults($resource, new NotExposed(), true, ['uriTemplate', 'uriVariables']); // @phpstan-ignore-line $resource is defined if count > 0

if (!$this->linkFactory->createLinksFromIdentifiers($operation)) {
$operation = $operation->withUriTemplate(self::$skolemUriTemplate);
$operation = $operation->withUriTemplate(self::$skolemUriTemplate)->withUriVariables([]);
}

$operations->add($key, $operation)->sort(); // @phpstan-ignore-line $operation exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class: AttributeResource::class
types: ['https://schema.org/Book'],
operations: [
'_api_AttributeResource_get_collection' => new GetCollection(controller: 'api_platform.action.placeholder', shortName: 'AttributeResource', class: AttributeResource::class),
'_api_AttributeResource_get' => new NotExposed(uriTemplate: '/.well-known/genid/{id}', controller: 'api_platform.action.not_exposed', shortName: 'AttributeResource', class: AttributeResource::class, output: false, read: false, extraProperties: ['generated_operation' => true], types: ['https://schema.org/Book']),
'_api_AttributeResource_get' => new NotExposed(uriTemplate: '/.well-known/genid/{id}', uriVariables: [], controller: 'api_platform.action.not_exposed', shortName: 'AttributeResource', class: AttributeResource::class, output: false, read: false, extraProperties: ['generated_operation' => true], types: ['https://schema.org/Book']),
],
class: AttributeResource::class
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue3975;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GraphQl\Query;

#[ApiResource(
operations: [],
graphQlOperations: [
new Query(
resolver: ActionSimulationResolver::class,
args: [
'actionId' => ['type' => 'String!'],
'structureEntityIds' => ['type' => '[String!]'],
],
read: false,
name: 'get'
),
]
)]
class ActionSimulation
{
public string $simulation = '0';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue3975;

use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;

class ActionSimulationResolver implements QueryItemResolverInterface
{
public function __invoke(?object $item, array $context): object
{
$simulation = new ActionSimulation();
$simulation->simulation = 'test';

return $simulation;
}
}
4 changes: 4 additions & 0 deletions tests/Fixtures/app/config/config_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ services:
tags:
- name: 'messenger.message_handler'

ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue3975\ActionSimulationResolver:
tags:
- name: 'api_platform.graphql.resolver'

app.graphql.query_resolver.dummy_custom_item:
class: 'ApiPlatform\Tests\Fixtures\TestBundle\GraphQl\Resolver\DummyCustomQueryItemResolver'
tags:
Expand Down
69 changes: 69 additions & 0 deletions tests/Functional/GraphQl/Issue3975Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Functional\GraphQl;

use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue3975\ActionSimulation;
use ApiPlatform\Tests\SetupClassResourcesTrait;

final class Issue3975Test extends ApiTestCase
{
use SetupClassResourcesTrait;

/**
* @return class-string[]
*/
public static function getResources(): array
{
return [ActionSimulation::class];
}

public function testGraphQlOnlyQueryWithProvider(): void
{
$response = self::createClient()->request('POST', '/graphql', ['json' => [
'query' => <<<'GRAPHQL'
{
getActionSimulation(actionId: "abc123", structureEntityIds: ["s1", "s2"]) {
simulation
}
}
GRAPHQL,
]]);

$this->assertResponseIsSuccessful();
$json = $response->toArray(false);
$this->assertArrayNotHasKey('errors', $json, isset($json['errors']) ? json_encode($json['errors']) : '');
$this->assertEquals('test', $json['data']['getActionSimulation']['simulation']);
}

public function testGraphQlOnlyQueryWithId(): void
{
$response = self::createClient()->request('POST', '/graphql', ['json' => [
'query' => <<<'GRAPHQL'
{
getActionSimulation(actionId: "abc123") {
id
simulation
}
}
GRAPHQL,
]]);

$this->assertResponseIsSuccessful();
$json = $response->toArray(false);
$this->assertArrayNotHasKey('errors', $json, isset($json['errors']) ? json_encode($json['errors']) : '');
$this->assertNotNull($json['data']['getActionSimulation']['id']);
$this->assertEquals('test', $json['data']['getActionSimulation']['simulation']);
}
}
Loading