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
i have created the following sample code to prove that the lazy loading feature does not work as desired.
If I query the field Test2, the class TestInvokable is created despite lazy loading. This has the consequence that a lot of dependencies have to be resolved, which are not necessary for the query. In this example this is illustrated by a sleep of 3 seconds.
I have also created an alternative TestCase in which it works. When I set up the Schema as in the linked page: https://webonyx.github.io/graphql-php/schema-definition-language/, the TestInvokable class is not created. Since there are two ways to use the GraphQL, I would like to have this feature also for the scenario described below.
// QueryType.php
class QueryType extends ObjectType
{
private const TEST1_FIELD = 'Test1';
private const TEST2_FIELD = 'Test2';
private ContainerInterface $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct($this->getConfig());
}
public function getConfig(): array
{
return [
'fields' => [
self::TEST1_FIELD => fn() => [
'description' => 'My Test Field 1',
'type' => self::string(),
'resolve' => $this->container->get(TestInvokable::class),
],
self::TEST2_FIELD => fn() => [
'description' => 'My Test Field 2',
'type' => self::string(),
'resolve' => fn() => 'Hello World',
]
],
];
}
}
// Test Invokable
class TestInvokable
{
public function __construct()
{
// Heavy dependencies
sleep(3);
}
public function __invoke($source, array $args): string
{
return 'FooBar';
}
}
Linked issue is a feature request to create a DI container known to GraphQL to use invokable classes for resolution. #1088
The text was updated successfully, but these errors were encountered:
Got it, I can reproduce the issue in a test case. The problem is that the schema is always loader eagerly when no type loader is present. I am trying to fix this in #1104
spawnia
changed the title
Lazy Field Definition does not always work
Lazy Field Definitions are eager loaded when schema has no type loader
Apr 14, 2022
spawnia
changed the title
Lazy Field Definitions are eager loaded when schema has no type loader
Lazy field definitions are eager loaded when schema has no type loader
Apr 14, 2022
Hey,
i have created the following sample code to prove that the lazy loading feature does not work as desired.
If I query the field
Test2
, the classTestInvokable
is created despite lazy loading. This has the consequence that a lot of dependencies have to be resolved, which are not necessary for the query. In this example this is illustrated by a sleep of 3 seconds.I have also created an alternative TestCase in which it works. When I set up the
Schema
as in the linked page: https://webonyx.github.io/graphql-php/schema-definition-language/, theTestInvokable
class is not created. Since there are two ways to use the GraphQL, I would like to have this feature also for the scenario described below.Linked issue is a feature request to create a DI container known to GraphQL to use invokable classes for resolution. #1088
The text was updated successfully, but these errors were encountered: