src/Execution/DataLoader/BatchLoader.php
public static function instance(string $loaderClass, array $pathToField, array $constructorArgs = []): self
    {
        // The path to the field serves as the unique key for the instance
        $instanceName = static::instanceKey($pathToField);

        // If we are resolving a batched query, we need to assign each
        // query a uniquely indexed instance
        /** @var \Nuwave\Lighthouse\Execution\GraphQLRequest $graphQLRequest */
        $graphQLRequest = app(GraphQLRequest::class);
        if ($graphQLRequest->isBatched()) {
            $currentBatchIndex = $graphQLRequest->batchIndex();
            $instanceName = "batch_{$currentBatchIndex}_{$instanceName}";
        }

        // Only register a new instance if it is not already bound
        $instance = app()->bound($instanceName)
            ? app($instanceName)
            : app()->instance(
                $instanceName,
                app()->makeWith($loaderClass, $constructorArgs)
            );

        if (! $instance instanceof self) {
            throw new Exception(
                "The given class '$loaderClass' must resolve to an instance of Nuwave\Lighthouse\Execution\DataLoader\BatchLoader"
            );
        }

        return $instance;
    }
public static function instance(string $loaderClass, array $pathToField, array $constructorArgs = []): self
    {
        // The path to the field serves as the unique key for the instance
        $instanceName = static::instanceKey($pathToField);

        // If we are resolving a batched query, we need to assign each
        // query a uniquely indexed instance
        /** @var \Nuwave\Lighthouse\Execution\GraphQLRequest $graphQLRequest */
        $graphQLRequest = app(GraphQLRequest::class);
        if ($graphQLRequest->isBatched()) {
            $currentBatchIndex = $graphQLRequest->batchIndex();
            $instanceName = "batch_{$currentBatchIndex}_{$instanceName}";
        }

        // Only register a new instance if it is not already bound
        $instance = app()->bound($instanceName)
            ? app($instanceName)
            : app()->instance(
                $instanceName,
                app()->makeWith($loaderClass, $constructorArgs)
            );

        if (! $instance instanceof self) {
            throw new Exception(
                "The given class '$loaderClass' must resolve to an instance of Nuwave\Lighthouse\Execution\DataLoader\BatchLoader"
            );
        }

        return $instance;
    }
public static function instance ( string $ loaderClass , array $ pathToField , array $ constructorArgs = [ ] ) : self { // The path to the field serves as the unique key for the instance $ instanceName = static :: instanceKey ( $ pathToField ) ; // If we are resolving a batched query, we need to assign each // query a uniquely indexed instance /** @var \Nuwave\Lighthouse\Execution\GraphQLRequest $graphQLRequest */ $ graphQLRequest = app ( GraphQLRequest :: class ) ; if ( $ graphQLRequest -> isBatched ( ) ) { $ currentBatchIndex = $ graphQLRequest -> batchIndex ( ) ; $ instanceName = "batch_{$currentBatchIndex}_{$instanceName}" ; } // Only register a new instance if it is not already bound $ instance = app ( ) -> bound ( $ instanceName ) ? app ( $ instanceName ) : app ( ) -> instance ( $ instanceName , app ( ) -> makeWith ( $ loaderClass , $ constructorArgs ) ) ; if ( ! $ instance instanceof self ) { throw new Exception ( "The given class '$loaderClass' must resolve to an instance of Nuwave\Lighthouse\Execution\DataLoader\BatchLoader" ) ; } return $ instance ; }
Return an instance of a BatchLoader for a specific field.

@param  string  $loaderClass  The class name of the concrete BatchLoader to instantiate
@param  mixed[]  $pathToField  Path to the GraphQL field from the root, is used as a key for BatchLoader instances
@param  mixed[]  $constructorArgs  Those arguments are passed to the constructor of the new BatchLoader instance
@return static

@throws \Exception
Return an instance of a BatchLoader for a specific field .