Skip to content

Navigation Menu

Sign in
Sign up

How to add entity manager in resolver #1003

ace90 started this conversation in General
Discussion options

Q A
Bug report? yes/no
Feature request? yes/no
BC Break report? yes/no
RFC? yes/no
Version/Branch x.y.z

I'm new in graphql. I try to add entity manger in my resolver using injecting service in constructor

class Characters
{
	public $em;
	public function __construct(EntityManagerInterface $em)
	{
		$this->em = $em;
	}
 public function getHumans()
 {
 dd($this);
 $humans = self::findByType(self::TYPE_HUMAN);
 
 return $humans;
 }
}

but when i query this. I always get this error Using $this when not in object context. May i know how can I fix this issue?

Screenshot 2022年03月22日 at 3 11 09 PM

in my service.yml. I try this one too

App\Resolver\Characters:
 arguments: ['@doctrine.orm.entity_manager']
You must be logged in to vote

Replies: 1 comment

Comment options

You should declare your service as a resolver. You can see how this can be done here.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #997 on April 26, 2022 15:10.

AltStyle によって変換されたページ (->オリジナル) /