This commit is contained in:
Your Name
2021-07-26 19:46:18 +02:00
parent e7a49138bb
commit aae17f10a6
818 changed files with 70695 additions and 16408 deletions
+42 -20
View File
@@ -2,43 +2,65 @@
namespace Nuwave\Lighthouse\Defer;
use Illuminate\Support\ServiceProvider;
use GraphQL\Language\Parser;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Nuwave\Lighthouse\Events\ManipulateAST;
use Nuwave\Lighthouse\Schema\Factories\DirectiveFactory;
use Nuwave\Lighthouse\Events\RegisterDirectiveNamespaces;
use Nuwave\Lighthouse\Events\StartExecution;
use Nuwave\Lighthouse\Schema\AST\ASTHelper;
use Nuwave\Lighthouse\Support\Contracts\CreatesResponse;
class DeferServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @param \Nuwave\Lighthouse\Schema\Factories\DirectiveFactory $directiveFactory
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
* @return void
*/
public function boot(DirectiveFactory $directiveFactory, Dispatcher $dispatcher): void
public function register(): void
{
$directiveFactory->addResolved(
DeferrableDirective::NAME,
DeferrableDirective::class
$this->app->singleton(Defer::class);
$this->app->singleton(CreatesResponse::class, Defer::class);
}
public function boot(Dispatcher $dispatcher): void
{
$dispatcher->listen(
RegisterDirectiveNamespaces::class,
static function (): string {
return __NAMESPACE__;
}
);
$dispatcher->listen(
ManipulateAST::class,
Defer::class.'@handleManipulateAST'
function (ManipulateAST $manipulateAST): void {
$this->handleManipulateAST($manipulateAST);
}
);
$dispatcher->listen(
StartExecution::class,
Defer::class.'@handleStartExecution'
);
}
/**
* Register any application services.
*
* @return void
* Set the tracing directive on all fields of the query to enable tracing them.
*/
public function register(): void
public function handleManipulateAST(ManipulateAST $manipulateAST): void
{
$this->app->singleton(Defer::class);
ASTHelper::attachDirectiveToObjectTypeFields(
$manipulateAST->documentAST,
Parser::constDirective(/** @lang GraphQL */ '@deferrable')
);
$this->app->singleton(CreatesResponse::class, Defer::class);
$manipulateAST->documentAST->setDirectiveDefinition(
Parser::directiveDefinition(/** @lang GraphQL */ '
"""
Use this directive on expensive or slow fields to resolve them asynchronously.
Must not be placed upon:
- Non-Nullable fields
- Mutation root fields
"""
directive @defer(if: Boolean = true) on FIELD
')
);
}
}