src/Schema/Directives/WithDirective.php
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $resolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver): Deferred {
                    $loader = BatchLoader::instance(
                        RelationBatchLoader::class,
                        $resolveInfo->path,
                        [
                            'relationName' => $this->directiveArgValue('relation', $this->definitionNode->name->value),
                            'args' => $args,
                            'scopes' => $this->directiveArgValue('scopes', []),
                            'resolveInfo' => $resolveInfo,
                        ]
                    );

                    return new Deferred(function () use ($loader, $resolver, $parent, $args, $context, $resolveInfo) {
                        return $loader
                            ->load(
                                $parent->getKey(),
                                ['parent' => $parent]
                            )->then(
                                function () use ($resolver, $parent, $args, $context, $resolveInfo) {
                                    return $resolver($parent, $args, $context, $resolveInfo);
                                }
                            );
                    });
                }
            )
        );
    }
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $resolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver): Deferred {
                    $loader = BatchLoader::instance(
                        RelationBatchLoader::class,
                        $resolveInfo->path,
                        [
                            'relationName' => $this->directiveArgValue('relation', $this->definitionNode->name->value),
                            'args' => $args,
                            'scopes' => $this->directiveArgValue('scopes', []),
                            'resolveInfo' => $resolveInfo,
                        ]
                    );

                    return new Deferred(function () use ($loader, $resolver, $parent, $args, $context, $resolveInfo) {
                        return $loader
                            ->load(
                                $parent->getKey(),
                                ['parent' => $parent]
                            )->then(
                                function () use ($resolver, $parent, $args, $context, $resolveInfo) {
                                    return $resolver($parent, $args, $context, $resolveInfo);
                                }
                            );
                    });
                }
            )
        );
    }
public function handleField ( FieldValue $ value , Closure $ next ) : FieldValue { $ resolver = $ value -> getResolver ( ) ; return $ next ( $ value -> setResolver ( function ( Model $ parent , array $ args , GraphQLContext $ context , ResolveInfo $ resolveInfo ) use ( $ resolver ) : Deferred { $ loader = BatchLoader :: instance ( RelationBatchLoader :: class , $ resolveInfo -> path , [ 'relationName' => $ this -> directiveArgValue ( 'relation' , $ this -> definitionNode -> name -> value ) , 'args' => $ args , 'scopes' => $ this -> directiveArgValue ( 'scopes' , [ ] ) , 'resolveInfo' => $ resolveInfo , ] ) ; return new Deferred ( function ( ) use ( $ loader , $ resolver , $ parent , $ args , $ context , $ resolveInfo ) { return $ loader -> load ( $ parent -> getKey ( ) , [ 'parent' => $ parent ] ) -> then ( function ( ) use ( $ resolver , $ parent , $ args , $ context , $ resolveInfo ) { return $ resolver ( $ parent , $ args , $ context , $ resolveInfo ) ; } ) ; } ) ; } ) ) ; }
Eager load a relation on the parent instance.

@param  \Nuwave\Lighthouse\Schema\Values\FieldValue  $value
@param  \Closure  $next
@return \Nuwave\Lighthouse\Schema\Values\FieldValue
Eager load a relation on the parent instance .