Skip to content

How to add entity manager in resolver #997

@ace90

Description

@ace90
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']

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions