graphqlite icon indicating copy to clipboard operation
graphqlite copied to clipboard

Should MutableObjectTypeAdapter be setting description?

Open joelcollinsdc opened this issue 1 year ago • 4 comments

I'm just trying to get my head around this library works, I tried adding a static type defition mapping like so:

$myStaticTypeMapper = new StaticTypeMapper();
$myStaticTypeMapper->setTypes([
	Example::class => new ExampleOutputType(),
]);
$schemaFactory->addTypeMapper($myStaticTypeMapper);

When I run SchemaPrinter::doPrint($schema);

And I get an error that there is no description set on the MutableObjectTypeAdapter that is wrapping ExampleOutputType. It appears the printer calls $def->description even though the mutable object type adapter never sets a description.

Guessing i'm trying to use the static type mapper incorrectly, but figured i'd ask, thanks!

joelcollinsdc avatar Aug 13 '24 22:08 joelcollinsdc

I don't see StaticTypeMapper::setTypes. It's passed through the constructor it seems. I'm guessing you just wrote pseudo code here. I haven't used the StaticTypeMapper in an implementation, personally. I don't think many people are using it - opting instead for actual objects and standard mapping. That said, I would expect a description to default to null. Do you have a stacktrace?

oojacoboo avatar Aug 14 '24 03:08 oojacoboo

Thanks for the response, I see setTypes is only a 6.2 branch concept. I had initial trouble working off of 7.0 so we downgraded. Maybe I should have gone back to 7.0/main branch.

joelcollinsdc avatar Aug 14 '24 15:08 joelcollinsdc

Checked on master, and i got the same error (using the constructor). Again i'm more just trying to learn how custom type mappers work at this point rather than this being an actual issue. This can be closed if thats best, thanks.

<b>Fatal error</b>: Uncaught Error: Typed property GraphQL\Type\Definition\ObjectType::$description must not be accessed
before initialization in
/vendor/webonyx/graphql-php/src/Utils/SchemaPrinter.php:246
Stack trace:
#0
/vendor/webonyx/graphql-php/src/Utils/SchemaPrinter.php(382):
GraphQL\Utils\SchemaPrinter::printDescription(Array,
Object(TheCodingMachine\GraphQLite\Mappers\Proxys\MutableObjectTypeAdapter))
#1
/vendor/webonyx/graphql-php/src/Utils/SchemaPrinter.php(106):
GraphQL\Utils\SchemaPrinter::printObject(Object(TheCodingMachine\GraphQLite\Mappers\Proxys\MutableObjectTypeAdapter),
Array)
#2

joelcollinsdc avatar Aug 14 '24 20:08 joelcollinsdc

So, that ObjectType::$description is required according to webonyx, the underlying GraphQL lib used by GraphQLite. It seems we need to at least set this as null, either implicitly or explicitly.

oojacoboo avatar Aug 15 '24 02:08 oojacoboo