Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer booting of schema and types #427

Merged
merged 3 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CHANGELOG
- Test suite has been refactored and now features Database (SQLite) tests too

### Changed
- Types and Schemas are now only booted when the `graphql` service is requested, improving performance when having this library installed but not using it in certain workloads (pure artisan commands, non-GraphQL web requests, etc.) [\#427](https://github.com/rebing/graphql-laravel/pull/427)
- Follow Laravel convention and use plural for namspaces (e.g. new queries are placed in `App\GraphQL\Queries`, not `App\GraphQL\Query` anymore); make commands have been adjusted
- Made the following classes _abstract_: `Support\Field`, `Support\InterfaceType`, `Support\Mutation`, `Support\Query`, `Support\Type`, `Support\UnionType` [\#357](https://github.com/rebing/graphql-laravel/pull/357)
- Updated GraphiQL to 0.13.0 [\#335](https://github.com/rebing/graphql-laravel/pull/335)
Expand Down
22 changes: 13 additions & 9 deletions src/GraphQLServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public function boot(): void
{
$this->bootPublishes();

$this->bootTypes();

$this->bootSchemas();

$this->bootRouter();
}

Expand Down Expand Up @@ -70,26 +66,28 @@ protected function bootPublishes(): void
}

/**
* Bootstrap publishes.
* Add types from config.
*
* @param GraphQL $graphQL
* @return void
*/
protected function bootTypes(): void
protected function bootTypes(GraphQL $graphQL): void
{
$configTypes = config('graphql.types');
$this->app->make('graphql')->addTypes($configTypes);
$graphQL->addTypes($configTypes);
}

/**
* Add schemas from config.
*
* @param GraphQL $graphQL
* @return void
*/
protected function bootSchemas(): void
protected function bootSchemas(GraphQL $graphQL): void
{
$configSchemas = config('graphql.schemas');
foreach ($configSchemas as $name => $schema) {
$this->app->make('graphql')->addSchema($name, $schema);
$graphQL->addSchema($name, $schema);
}
}

Expand Down Expand Up @@ -143,8 +141,14 @@ public function registerGraphQL(): void

$this->applySecurityRules();

$this->bootSchemas($graphql);

return $graphql;
});

$this->app->afterResolving('graphql', function (GraphQL $graphQL) {
$this->bootTypes($graphQL);
});
}

/**
Expand Down