GraphQLBundle
GraphQLBundle copied to clipboard
Can't set a scalar parameter with GraphQL services
Q | A |
---|---|
Bug report? | yes |
Version | 0.11.9 |
Symfony version | 4.1 |
Hi and thanks for your work !
I think I have encountered a bug in the compiler pass of the bundle. I can't manage to use named parameter with autowiring for my GraphQL services, they are reset somehow.
Reproduction
in services.yaml
App\GraphQL\Mutation\UploadMutation:
arguments:
$cardUploadDir: '%card_upload_dir%'
in App\GraphQL\Mutation\UploadMutation
class UploadMutation implements MutationInterface, AliasedInterface
{
private $cardUploadDir;
public function __construct(string $cardUploadDir)
I always end up with the exception
Cannot autowire service "App\GraphQL\Mutation\UploadMutation": argument "$cardUploadDir" of method "__construct()" is type-hinted "string", you should configure its value explicitly.
Temporary fix for me
Quick and dirty fix for me was to override the process function in my kernel.
public function process(ContainerBuilder $container)
{
$container->getDefinition('App\GraphQL\Mutation\UploadMutation')->setArgument('$cardUploadDir', '%card_upload_dir%');
}
Hi! thanks for reporting this issue and the reproduction. We'll try to give this a fix quickly.
Ok I get it, your service is missing the mutation tag
App\GraphQL\Mutation\UploadMutation:
arguments:
$cardUploadDir: '%card_upload_dir%'
tags: ['overblog_graphql.mutation']
I'm having the same issue with the tag sadly.
Can you try to remove MutationInterface
I'm having a weird exception now with
class UploadMutation implements AliasedInterface
{
App\GraphQL\Mutation\UploadMutation:
tags: ['overblog_graphql.mutation']
arguments:
$cardUploadDir: '%card_upload_dir%'
Hi, what's the status on this bug? I'm using your package and I need to pass entity manager with alternative connection. I'm doing this from services.yaml
AppBundle\GraphQL\Mutation\UserMutation:
tags: ['@overblog_graphql.mutation']
arguments:
$em: '@doctrine.orm.user_entity_manager'
And when I autowire argument in class __constuct, I get default entity manager.
This bug was not fixed since this could introduce BC, this come from AliasedInterface usage, removed it and defined your aliases using tags.
Thanx for quick answer, but it did not help:( I'll post my whole code, please look at it, maybe I've made a mistake somewhere.
mutation class:
Class UserMutation implements MutationInterface
{
/**
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
\Doctrine\Common\Util\Debug::dump($em->getConnection());die; // here I get default connection
$this->em = $em;
}
public function createUser(array $args): User
{...}
}
services.yaml
AppBundle\GraphQL\Mutation\UserMutation:
arguments:
$em: '@doctrine.orm.user_entity_manager'
tags:
- { name: overblog_graphql.mutation, method: createUser, alias: createUser }
Mutation.yaml
Mutation:
type: object
config:
fields:
createUser:
type: User!
resolve: '@=mutation("AppBundle\\GraphQL\\Mutation\\UserMutation::createUser", [args["input"]])'
args:
input:
type: UserInput!
if you want to use fqcn you must remove alias:
AppBundle\GraphQL\Mutation\UserMutation:
arguments:
$em: '@doctrine.orm.user_entity_manager'
tags:
- { name: overblog_graphql.mutation, method: createUser }
Did not helped, still default connection:( Any thoughts?
Do you have some wildcard rules in your dependency injection configuration?
I get a quick look at project and not found any wildcards
Can you name your service
app.user_mutation:
class: AppBundle\GraphQL\Mutation\UserMutation:
arguments:
$em: '@doctrine.orm.user_entity_manager'
tags:
- { name: overblog_graphql.mutation, method: createUser }
what is the output of this CLI?
bin/console graphql:debug --category=mutation
solution id:
AppBundle\GraphQL\Mutation\UserMutation::createUser
app.user_mutation::createUser
aliases :
It's shown in table, but I don't know how to visualise table, sorry:)