You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
-
462
442
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.
463
443
```php
464
444
namespace App\GraphQL\Queries;
@@ -2696,9 +2676,6 @@ To prevent such scenarios, you can add the `UnusedVariablesMiddleware` to your
2696
2676
-`batching`\
2697
2677
- 'enable'\
2698
2678
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.
2702
2679
-`error_formatter`\
2703
2680
This callable will be passed the Error object for each errors GraphQL catch.
2704
2681
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
2824
2801
2825
2802
## Performance considerations
2826
2803
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
-
2845
2804
### Wrap Types
2846
2805
2847
2806
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:
message:"#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesConfigAliasQuery\\:\\:resolve\\(\\) has parameter \\$args with no type specified\\.$#"
message:"#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesConfigAliasQuery\\:\\:resolve\\(\\) has parameter \\$root with no type specified\\.$#"
message:"#^Method Rebing\\\\GraphQL\\\\Tests\\\\Support\\\\Objects\\\\ExamplesFilteredQuery\\:\\:resolve\\(\\) has parameter \\$args with no type specified\\.$#"
Copy file name to clipboardExpand all lines: src/GraphQL.php
+4-10Lines changed: 4 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -242,11 +242,7 @@ public function getType(string $name, bool $fresh = false): Type
242
242
}
243
243
244
244
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.";
250
246
251
247
thrownewTypeNotFound($error);
252
248
}
@@ -401,11 +397,9 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema
0 commit comments