问题描述
我正在使用"nuwave/lighthouse": "^4.14"
,并具有基于the docs of this feature的schema.graphql:
type Query {
# ...
postsWithUnseenComments(orderBy: _ @orderBy(columns: ["id","created_at"],order: ASC),hasComments: _ @whereHasConditions(columns: ["user_id","seen_at"])): [Post!]! @paginate(defaultCount: 20) @cache
}
我得到这个错误:
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)
我已经尝试过here中的PHP artisan package:discover
,但没有帮助。
我从the docs知道应该vendor\nuwave\lighthouse\src\WhereConditions\WhereHasConditionsDirective.PHP
自动加载。
@spawnia,非常感谢您提供的出色库。对于我做错事情的任何提示,我将不胜感激。谢谢。
解决方法
来自https://lighthouse-php.com/4.14/eloquent/complex-where-conditions.html#setup:
这是一项实验性功能,默认情况下不包含在Lighthouse中。
将服务提供商添加到您的config/app.php
'providers' => [
\Nuwave\Lighthouse\WhereConditions\WhereConditionsServiceProvider::class,],
安装依赖项mll-lab/graphql-php-scalars:
composer require mll-lab/graphql-php-scalars