Skip to content

Commit 38ee06d

Browse files
committed
Remove optional support for non-lazy loading of types
Lazy loading has been introduced in 2.0.0 (2019-08) and has been enabled by default in 8.0.0 (2021-11). From now on the type loader is always used when resolving types and the impact mostly means that you can't have types registered using an alias different from their name. As can be seen by th commit, this reduces complexity and maintenance overhead of the library.
1 parent 59251b2 commit 38ee06d

File tree

13 files changed

+15
-196
lines changed

13 files changed

+15
-196
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
matrix:
3636
php: ${{ fromJson(needs.supported-versions-matrix.outputs.version) }}
3737
laravel: [^6.0, ^8.0, ^9.0]
38-
lazy_types: ['false', 'true']
3938
exclude:
4039
- php: 7.4
4140
laravel: ^9.0
@@ -45,7 +44,7 @@ jobs:
4544
laravel: ^6.0
4645
- php: 8.2
4746
laravel: ^6.0
48-
name: P=${{ matrix.php }} L=${{ matrix.laravel }} Lazy types=${{ matrix.lazy_types }}
47+
name: P=${{ matrix.php }} L=${{ matrix.laravel }}
4948
runs-on: ubuntu-latest
5049
env:
5150
COMPOSER_NO_INTERACTION: 1
@@ -79,9 +78,5 @@ jobs:
7978

8079
- run: composer update --prefer-dist --no-progress
8180

82-
- name: Enable lazy types conditionally
83-
run: echo "TESTS_ENABLE_LAZYLOAD_TYPES=1" >> $GITHUB_ENV
84-
if: matrix.lazy_types == 'true'
85-
8681
- name: Run tests
8782
run: composer tests

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ CHANGELOG
44
[Next release](https://github.com/rebing/graphql-laravel/compare/8.4.0...master)
55
--------------
66

7+
## Breaking changes
8+
### Removed
9+
- Remove support for eager loading (=non-lazy loading) of types\
10+
Lazy loading has been introduced in 2.0.0 (2019-08) and has been made the
11+
default since 8.0.0 (2021-11).\
12+
The practical impact is that types are always going to be resolved using a
13+
type loader and therefore cannot use aliases anymore. Types and their type
14+
name have to match.
15+
716
2023-01-06, 8.4.0
817
-----------------
918
### Added

README.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ The default GraphiQL view makes use of the global `csrf_token()` helper function
126126
- [Upgrading from v1 to v2](#upgrading-from-v1-to-v2)
127127
- [Migrating from Folklore](#migrating-from-folklore)
128128
- [Performance considerations](#performance-considerations)
129-
- [Lazy loading of types](#lazy-loading-of-types)
130-
- [Example of aliasing **not** supported by lazy loading](#example-of-aliasing-not-supported-by-lazy-loading)
131129
- [Wrap Types](#wrap-types)
132130
- [GraphQL testing clients](#graphql-testing-clients)
133131

@@ -278,12 +276,6 @@ them, in addition to the global middleware. For example:
278276
'default' => [
279277
'query' => [
280278
ExampleQuery::class,
281-
// It's possible to specify a name/alias with the key
282-
// but this is discouraged as it prevents things
283-
// like improving performance with e.g. `lazyload_types=true`
284-
// It's recommended to specify just the class here and
285-
// rely on the `'name'` attribute in the query / type.
286-
'someQuery' => AnotherExampleQuery::class,
287279
],
288280
'mutation' => [
289281
ExampleMutation::class,
@@ -447,18 +439,6 @@ Alternatively you can:
447439
GraphQL::addType(\App\GraphQL\Types\UserType::class);
448440
```
449441

450-
As with queries/mutations, you can use an alias name (though again this prevents
451-
it from taking advantage of lazy type loading):
452-
```php
453-
'schemas' => [
454-
'default' => [
455-
// ...
456-
457-
'types' => [
458-
'Useralias' => App\GraphQL\Types\UserType::class,
459-
],
460-
```
461-
462442
Then you need to define a query that returns this type (or a list). You can also specify arguments that you can use in the resolve method.
463443
```php
464444
namespace App\GraphQL\Queries;
@@ -2696,9 +2676,6 @@ To prevent such scenarios, you can add the `UnusedVariablesMiddleware` to your
26962676
- `batching`\
26972677
- 'enable'\
26982678
Whether to support GraphQL batching or not
2699-
- `lazyload_types`\
2700-
The types will be loaded on demand. Enabled by default as it improves
2701-
performance. Cannot be used with type aliasing.
27022679
- `error_formatter`\
27032680
This callable will be passed the Error object for each errors GraphQL catch.
27042681
The method should return an array representing the error.
@@ -2824,24 +2801,6 @@ The following is not a bullet-proof list but should serve as a guide. It's not a
28242801

28252802
## Performance considerations
28262803

2827-
### Lazy loading of types
2828-
2829-
Lazy loading of types is a way of improving the start up performance.
2830-
2831-
If you are declaring types using aliases, this is not supported and you need to
2832-
set `lazyload_types` set to `false`.
2833-
2834-
#### Example of aliasing **not** supported by lazy loading
2835-
2836-
I.e. you cannot have a query class `ExampleQuery` with the `$name` property
2837-
`example` but register it with a different one; this will **not** work:
2838-
2839-
```php
2840-
'query' => [
2841-
'aliasedExample' => ExampleQuery::class,
2842-
],
2843-
```
2844-
28452804
### Wrap Types
28462805

28472806
You can wrap types to add more information to the queries and mutations. Similar as the pagination is working you can do the same with your extra data that you want to inject ([see test examples](https://github.com/rebing/graphql-laravel/tree/master/tests/Unit/WithTypeTests)). For instance, in your query:

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@
6969
"phpstan-baseline": "phpstan analyse --memory-limit=512M --generate-baseline",
7070
"lint": "php-cs-fixer fix --diff --dry-run",
7171
"fix-style": "php-cs-fixer fix",
72-
"tests": "phpunit --colors=always --verbose",
73-
"tests-all": [
74-
"TESTS_ENABLE_LAZYLOAD_TYPES=0 phpunit --colors=always --verbose",
75-
"TESTS_ENABLE_LAZYLOAD_TYPES=1 phpunit --colors=always --verbose"
76-
]
72+
"tests": "phpunit --colors=always --verbose"
7773
},
7874
"extra": {
7975
"branch-alias": {

config/config.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@
111111
// \Rebing\GraphQL\Support\UploadType::class,
112112
],
113113

114-
// The types will be loaded on demand. Default is to load all types on each request
115-
// Can increase performance on schemes with many types
116-
// Presupposes the config type key to match the type class name property
117-
'lazyload_types' => true,
118-
119114
// This callable will be passed the Error object for each errors GraphQL catch.
120115
// The method should return an array representing the error.
121116
// Typically:

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -865,21 +865,6 @@ parameters:
865865
count: 1
866866
path: tests/Support/Objects/ExamplesAuthorizeQuery.php
867867

868-
-
869-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesConfigAliasQuery\\:\\:resolve\\(\\) has no return type specified\\.$#"
870-
count: 1
871-
path: tests/Support/Objects/ExamplesConfigAliasQuery.php
872-
873-
-
874-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesConfigAliasQuery\\:\\:resolve\\(\\) has parameter \\$args with no type specified\\.$#"
875-
count: 1
876-
path: tests/Support/Objects/ExamplesConfigAliasQuery.php
877-
878-
-
879-
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesConfigAliasQuery\\:\\:resolve\\(\\) has parameter \\$root with no type specified\\.$#"
880-
count: 1
881-
path: tests/Support/Objects/ExamplesConfigAliasQuery.php
882-
883868
-
884869
message: "#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesFilteredQuery\\:\\:resolve\\(\\) has parameter \\$args with no type specified\\.$#"
885870
count: 1

src/GraphQL.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,7 @@ public function getType(string $name, bool $fresh = false): Type
242242
}
243243

244244
if (!isset($this->types[$name])) {
245-
$error = "Type $name not found.";
246-
247-
if ($this->config->get('graphql.lazyload_types', true)) {
248-
$error .= "\nCheck that the config array key for the type matches the name attribute in the type's class.\nIt is required when 'lazyload_types' is enabled";
249-
}
245+
$error = "Type $name not found. Check that the config array key for the type matches the name attribute in the type's class.";
250246

251247
throw new TypeNotFound($error);
252248
}
@@ -401,11 +397,9 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema
401397

402398
return $types;
403399
},
404-
'typeLoader' => $this->config->get('graphql.lazyload_types', true)
405-
? function ($name) {
406-
return $this->type($name);
407-
}
408-
: null,
400+
'typeLoader' => function ($name) {
401+
return $this->type($name);
402+
},
409403
]);
410404
}
411405

tests/Support/Objects/ExampleType2.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/Support/Objects/ExamplesConfigAliasQuery.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/TestCase.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818
use Rebing\GraphQL\Tests\Support\Objects\ExamplesAuthorizeMessageQuery;
1919
use Rebing\GraphQL\Tests\Support\Objects\ExamplesAuthorizeQuery;
2020
use Rebing\GraphQL\Tests\Support\Objects\ExampleSchema;
21-
use Rebing\GraphQL\Tests\Support\Objects\ExamplesConfigAliasQuery;
2221
use Rebing\GraphQL\Tests\Support\Objects\ExamplesFilteredQuery;
2322
use Rebing\GraphQL\Tests\Support\Objects\ExamplesMiddlewareQuery;
2423
use Rebing\GraphQL\Tests\Support\Objects\ExamplesPaginationQuery;
2524
use Rebing\GraphQL\Tests\Support\Objects\ExamplesQuery;
2625
use Rebing\GraphQL\Tests\Support\Objects\ExampleType;
27-
use Rebing\GraphQL\Tests\Support\Objects\ExampleType2;
2826
use Rebing\GraphQL\Tests\Support\Objects\UpdateExampleMutation;
2927
use Symfony\Component\Console\Tester\CommandTester;
3028

@@ -43,10 +41,6 @@ protected function setUp(): void
4341

4442
protected function getEnvironmentSetUp($app): void
4543
{
46-
if ('0' === env('TESTS_ENABLE_LAZYLOAD_TYPES')) {
47-
$app['config']->set('graphql.lazyload_types', false);
48-
}
49-
5044
$app['config']->set('graphql.schemas.default', [
5145
'query' => [
5246
'examples' => ExamplesQuery::class,
@@ -55,7 +49,6 @@ protected function getEnvironmentSetUp($app): void
5549
'examplesMiddleware' => ExamplesMiddlewareQuery::class,
5650
'examplesPagination' => ExamplesPaginationQuery::class,
5751
'examplesFiltered' => ExamplesFilteredQuery::class,
58-
'examplesConfigAlias' => ExamplesConfigAliasQuery::class,
5952
],
6053
'mutation' => [
6154
'updateExample' => UpdateExampleMutation::class,
@@ -75,7 +68,6 @@ protected function getEnvironmentSetUp($app): void
7568

7669
$app['config']->set('graphql.types', [
7770
'Example' => ExampleType::class,
78-
'ExampleConfigAlias' => ExampleType2::class,
7971
'ExampleFilterInput' => ExampleFilterInputType::class,
8072
]);
8173

0 commit comments

Comments
 (0)