Skip to content
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

Should MutableObjectTypeAdapter be setting description? #697

Open
joelcollinsdc opened this issue Aug 13, 2024 · 4 comments
Open

Should MutableObjectTypeAdapter be setting description? #697

joelcollinsdc opened this issue Aug 13, 2024 · 4 comments

Comments

@joelcollinsdc
Copy link

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!

@oojacoboo
Copy link
Collaborator

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?

@joelcollinsdc
Copy link
Author

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
Copy link
Author

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

@oojacoboo
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants