Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autowire in Symfony in prefetchMethod is failing #231

Closed
moufmouf opened this issue Jan 29, 2020 · 1 comment · Fixed by thecodingmachine/graphqlite-bundle#52
Closed

Comments

@moufmouf
Copy link
Member

I'm trying to autowire a service in a prefetchMethod in Symfony.

    /**
     * @Field(prefetchMethod="prefetchProducts")
     * @return Product[]
     */
    public function getProducts($sortedProducts)
    {
        return $sortedProducts[$this->getId()];
    }

    /**
     * @param Company[] $companies
     * @Autowire(for="$productRepository")
     * @return array<int, array<Product>>
     */
    public function prefetchProducts(iterable $companies, ProductRepository $productRepository)
    {
        $products = $productRepository->findByCompanies($companies);

        $sortedProducts = [];
        foreach ($products as $product) {
            $sortedProducts[$product->getId()][] = $product;
        }

        return $sortedProducts;
    }

I get this:

{
  "type": "https://tools.ietf.org/html/rfc2616#section-10",
  "title": "An error occurred",
  "status": 500,
  "detail": "The \"App\\Repository\\ProductRepository\" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.",
  "class": "Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException",
@darkiron
Copy link

darkiron commented Jun 4, 2021

I have same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants