-
-
Notifications
You must be signed in to change notification settings - Fork 575
Remember initial types instead of lazy-loading #1697
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -99,6 +99,10 @@ | |||||||||||||||||||||||||||||||||||||
| $this->extensionASTNodes = $config->extensionASTNodes; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| $this->config = $config; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| foreach ($this->config->types as $type) { | ||||||||||||||||||||||||||||||||||||||
|
Check failure on line 103 in src/Type/Schema.php
|
||||||||||||||||||||||||||||||||||||||
| $this->resolvedTypes[$type->name()] = $type; | ||||||||||||||||||||||||||||||||||||||
|
Check failure on line 104 in src/Type/Schema.php
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| $this->resolvedTypes[$type->name()] = $type; | |
| $typeName = $type->name(); | |
| if (isset($this->resolvedTypes[$typeName]) && $this->resolvedTypes[$typeName] !== $type) { | |
| throw new InvariantViolation( | |
| 'Schema must contain unique named types but contains multiple types named ' . $typeName | |
| ); | |
| } | |
| $this->resolvedTypes[$typeName] = $type; |
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eagerly resolving all types in the constructor defeats the purpose of lazy loading and can negatively impact performance for large schemas. If the types array contains many types or lazy callables, all of them will be resolved immediately during schema construction, even if they're never used. This is particularly problematic when combined with typeLoader, as it changes the expected behavior where types are only loaded on-demand. Consider documenting this behavior change and its performance implications.
| if (is_callable($types)) { | |
| $types = $types(); | |
| } | |
| foreach ($types as $typeOrLazyType) { | |
| /** @var Type|callable(): Type $typeOrLazyType */ | |
| $type = self::resolveType($typeOrLazyType); | |
| assert($type instanceof NamedType); | |
| $this->resolvedTypes[$type->name()] = $type; | |
| } | |
| // If $types is a callable, defer its execution to preserve lazy loading. | |
| if (! is_callable($types)) { | |
| foreach ($types as $typeOrLazyType) { | |
| /** @var Type|callable(): Type $typeOrLazyType */ | |
| $type = self::resolveType($typeOrLazyType); | |
| assert($type instanceof NamedType); | |
| $this->resolvedTypes[$type->name()] = $type; | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users may specify
typesin a multitude of ways, its type isiterable<Type&NamedType>|(callable(): iterable<Type&NamedType>)|iterable<(callable(): Type&NamedType)>|(callable(): iterable<(callable(): Type&NamedType)>). The code you wrote does not work with some of those options.