Search code examples
laravellaravel-lighthouse

How can I fix "No directive found for `whereHasConditions`" in Laravel Lighthouse?


I'm using "nuwave/lighthouse": "^4.14" and have this schema.graphql based on the docs of this feature:

type Query {
    # ...
    postsWithUnseenComments(orderBy: _ @orderBy(columns: ["id", "created_at"], order: ASC), hasComments: _ @whereHasConditions(columns: ["user_id", "seen_at"])): [Post!]! @paginate(defaultCount: 20) @cache
}

and I get this error:

No directive found for `whereHasConditions` {"exception":"[object] (Nuwave\\Lighthouse\\Exceptions\\DirectiveException(code: 0): No directive found for `whereHasConditions` at C:\\code\\myproject\\vendor\
uwave\\lighthouse\\src\\Schema\\Factories\\DirectiveFactory.php:91)

I have already tried php artisan package:discover from here, but it didn't help.

I know from the docs that vendor\nuwave\lighthouse\src\WhereConditions\WhereHasConditionsDirective.php should automatically be loaded.

@spawnia, thank you so much for your amazing library. I'd appreciate any hints about what I'm doing wrong. Thanks.


Solution

  • From https://lighthouse-php.com/4.14/eloquent/complex-where-conditions.html#setup:

    This is an experimental feature and not included in Lighthouse by default.

    Add the service provider to your config/app.php

    'providers' => [
        \Nuwave\Lighthouse\WhereConditions\WhereConditionsServiceProvider::class,
    ],
    

    Install the dependency mll-lab/graphql-php-scalars:

    composer require mll-lab/graphql-php-scalars