-
-
Notifications
You must be signed in to change notification settings - Fork 934
Closed
Labels
Description
API Platform version: 3,3
My resource description looks like so:
#[ApiResource(
security: "is_granted('ROLE_USER')",
order: ['id' => 'DESC'],
normalizationContext: ['groups' => ["batch:query"]],
denormalizationContext: ['groups' => ["batch:mutation"]],
operations: [
new Get(),
new GetCollection(),
new Post(
name: 'create',
controller: CreateBatchController::class,
),
new Post(
name: 'start',
controller: BatchTransitionStartController::class,
uriTemplate: '/batches/{id}/start',
denormalizationContext: ['groups' => ["batch:transition"]]
),
new Post(
name: 'finish',
controller: BatchTransitionFinishController::class,
uriTemplate: '/batches/{id}/finish',
denormalizationContext: ['groups' => ["batch:transition"]]
),
new Post(
name: 'pause',
controller: BatchTransitionPauseController::class,
uriTemplate: '/batches/{id}/pause',
denormalizationContext: ['groups' => ["batch:transition"]]
)
],
graphQlOperations: [
new Query(),
new QueryCollection(),
new Mutation(
name: 'create',
resolver: CreateBatchMutationResolver::class
),
new Mutation(
name: 'start',
resolver: BatchTransitionMutationResolver::class,
denormalizationContext: ['groups' => ["batch:transition"]]
),
new Mutation(
name: 'finish',
resolver: BatchTransitionMutationResolver::class,
denormalizationContext: ['groups' => ["batch:transition"]]
),
new Mutation(
name: 'pause',
resolver: BatchTransitionMutationResolver::class,
denormalizationContext: ['groups' => ["batch:transition"]]
),
]
)]
My goal is to reproduce the same API for REST and GraphQL endpoints. Having this getting strange server error in
vendor\/api-platform\/core\/src\/GraphQl\/Type\/TypeConverter.php","line":185
after some digging I see exception firing:
if (!$operation instanceof Operation) {
throw new OperationNotFoundException();
}
following
$operation = $resourceMetadataCollection->getOperation($operationName);
``
FIX. In my case, for example:
new Post(
name: 'start',
controller: BatchTransitionStartController::class,
uriTemplate: '/batches/{id}/start',
),
and
new Mutation(
name: 'start',
resolver: BatchTransitionMutationResolver::class
),
both have "start" as a name, while I can't change the name for Mutation since it will be reflected in autogenerated GraphQL operation naming thus breaking API for existing users, It's safe to name the Post to let's say "start_rest" providing uriTemplate and error is gone. It's either a bug or documentation issue leading to cryptic error messages.