Skip to content
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
5 changes: 3 additions & 2 deletions src/FieldsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,11 @@ private function resolvePhpType(string $phpTypeStr, ReflectionClass $refClass, R
{
$typeResolver = new \phpDocumentor\Reflection\TypeResolver();

$phpdocType = $typeResolver->resolve($phpTypeStr);
$context = $this->cachedDocBlockFactory->getContextFromClass($refClass);
$phpdocType = $typeResolver->resolve($phpTypeStr, $context);
Assert::notNull($phpdocType);

$fakeDocBlock = new DocBlock('', null, [new DocBlock\Tags\Return_($phpdocType)], $this->cachedDocBlockFactory->getContextFromClass($refClass));
$fakeDocBlock = new DocBlock('', null, [new DocBlock\Tags\Return_($phpdocType)], $context);
return $this->typeMapper->mapReturnType($refMethod, $fakeDocBlock);

// TODO: add a catch to CannotMapTypeExceptionInterface and a "addMagicFieldInfo" method to know where the issues are coming from.
Expand Down
9 changes: 3 additions & 6 deletions tests/Fixtures/Integration/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
use TheCodingMachine\GraphQLite\Annotations\Parameter;
use TheCodingMachine\GraphQLite\Annotations\Right;
use TheCodingMachine\GraphQLite\Annotations\Type;
use TheCodingMachine\GraphQLite\Mappers\CompositeTypeMapper;
use TheCodingMachine\GraphQLite\Mappers\Parameters\ParameterHandlerInterface;
use TheCodingMachine\GraphQLite\TypeRegistry;
use TheCodingMachine\GraphQLite\Annotations\Autowire;

/**
* @Type()
* @MagicField(name="magicNumber", phpType="int")
* @MagicField(name="magicContact", phpType="Contact")
*/
class Contact
{
Expand Down Expand Up @@ -54,7 +51,7 @@ public function __construct(string $name)
{
$this->name = $name;
}

public function getName()
{
return $this->name;
Expand Down Expand Up @@ -210,6 +207,6 @@ public function injectServiceFromExternal(string $testService, string $testSkip

public function __get(string $property)
{
return 42;
return new Contact('foo');
}
}
12 changes: 9 additions & 3 deletions tests/Integration/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,9 @@ public function testEndToEndMagicFieldWithPhpType(): void
$queryString = '
query {
contacts {
magicNumber
magicContact {
name
}
}
}
';
Expand All @@ -1310,10 +1312,14 @@ public function testEndToEndMagicFieldWithPhpType(): void
$this->assertSame([
'contacts' => [
[
'magicNumber' => 42,
'magicContact' => [
'name' => 'foo'
]
],
[
'magicNumber' => 42,
'magicContact' => [
'name' => 'foo'
]
],
]
], $result->toArray(Debug::RETHROW_INTERNAL_EXCEPTIONS)['data']);
Expand Down