Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将中间件应用于nuwave/lighthouse版本5中的分组查询或突变_Php_Laravel_Graphql_Laravel Lighthouse - Fatal编程技术网

Php 如何将中间件应用于nuwave/lighthouse版本5中的分组查询或突变

Php 如何将中间件应用于nuwave/lighthouse版本5中的分组查询或突变,php,laravel,graphql,laravel-lighthouse,Php,Laravel,Graphql,Laravel Lighthouse,在灯塔3号和4号之前,我可以这样做 extend type Mutation @group( namespace: "Api\\Jobs\\Resolvers", middleware: ["verified"] ) { createJob( payload: CreateJobInput ): Job @field(resolver: "Api\\Jobs\\Resolvers\\JobResolve

在灯塔3号和4号之前,我可以这样做

extend type Mutation @group(
    namespace: "Api\\Jobs\\Resolvers",
    middleware: ["verified"]
) {
    createJob(
      payload: CreateJobInput
    ): Job @field(resolver: "Api\\Jobs\\Resolvers\\JobResolver@create")

    updateJob(
      payload: UpdateJobInput
    ): Job @field(resolver: "Api\\Jobs\\Resolvers\\JobResolver@update")

    ...
}
但在lighthouse 5中,
@组
@中间件
指令被删除。我试图像这样在
对象上创建自定义指令,但没有成功

namespace App\GraphQL\Directives;

use ...

final class VerifiedDirective extends BaseDirective implements FieldMiddleware, TypeManipulator
{
    public function handleField(FieldValue $fieldValue, Closure $next) 
    {
        // verify
        return $next($fieldValue);
    }

    public static function definition(): string
    {
        return /** @lang GraphQL */ <<<'GRAPHQL'
            directive @verified on OBJECT
        GRAPHQL;
    }

    // I copied from other OBJECT directive
    public function manipulateTypeDefinition(DocumentAST &$documentAST, TypeDefinitionNode &$typeDefinition): void
    {
        ASTHelper::addDirectiveToFields($this->directiveNode, $typeDefinition);
    }
}
但是它说,
没有为“已验证的”
找到指令

lighthouse 5文档说我应该使用
FieldMiddleware
,但我不想将该指令添加到每个字段。有没有什么方法可以将中间件应用于分组的突变和查询


提前谢谢。

您找到了中间产品的解决方案吗?我也在寻找相同的。@SudeepBashista我最终使用与版本4相同的代码创建了一个自定义中间件指令,请拉出它所需的任何依赖项。您可以共享该代码段吗?
extend type Mutation @namespace(field: "Api\\Companies\\Resolvers") @verified {
    ...
}