directiveArgValue('model'); if (is_string($modelArg)) { return function (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($modelArg) { $builder = $this->namespaceModelClass($modelArg)::query(); $this->makeBuilderDecorator($root, $args, $context, $resolveInfo)($builder); return $builder->{$this->function()}($this->column()); }; } $relation = $this->directiveArgValue('relation'); if (is_string($relation)) { return function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Deferred { $relationBatchLoader = BatchLoaderRegistry::instance( [...$this->qualifyPath($args, $resolveInfo), $this->function(), $this->column()], fn (): RelationBatchLoader => new RelationBatchLoader( new AggregateModelsLoader( $this->relation(), $this->column(), $this->function(), $this->makeBuilderDecorator($parent, $args, $context, $resolveInfo), ), ), ); $deferred = $relationBatchLoader->load($parent); return new Deferred(function () use ($deferred) { $result = $deferred->result; return $result ?? 0; }); }; } $modelArg = $this->directiveArgValue('model'); if (is_string($modelArg)) { return function (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($modelArg) { $query = $this->namespaceModelClass($modelArg)::query(); $this->makeBuilderDecorator($root, $args, $context, $resolveInfo)($query); return $query->{$this->function()}($this->column()); }; } if ($this->directiveHasArgument('builder')) { $builderResolver = $this->getResolverFromArgument('builder'); return function (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($builderResolver) { $builder = $builderResolver($root, $args, $context, $resolveInfo); assert( $builder instanceof QueryBuilder || $builder instanceof EloquentBuilder, "The method referenced by the builder argument of the @{$this->name()} directive on {$this->nodeName()} must return a Builder.", ); $this->makeBuilderDecorator($root, $args, $context, $resolveInfo)($builder); return $builder->{$this->function()}($this->column()); }; } throw new DefinitionException("One of the arguments `model`, `relation` or `builder` must be assigned to the '{$this->name()}' directive on '{$this->nodeName()}'."); } }