Description
Ran into what looks like a regression somewhere between 8.1.2 and 8.3.0.
Short version: declare a GraphQL interface the documented way (#[Type] on a PHP interface), have something return that interface as an output type, and building the schema blows up on 8.3.0. The exact same code builds fine on 8.1.2.
Error:
Expected GraphQL type "Foo" to be an MutableObjectType. Got a TheCodingMachine\GraphQLite\Types\TypeAnnotatedInterfaceType thrown from TypeRegistry::getMutableObjectType().
Repro is basically the interfaces doc example:
#[Type(name: 'Foo')]
interface FooInterface { #[Field] public function getId(): ID; }
#[Type]
class Bar implements FooInterface {
public function __construct(private Thing $thing) {}
public function getId(): ID { return new ID((string) $this->thing->id); }
}
Then have any field return Foo (the interface) as its output type and build/validate the schema.
What's going on, from a backtrace:
Schema->assertValid()
-> RecursiveTypeMapper::getOutputTypes() (RecursiveTypeMapper.php:447)
-> mapClassToType(FooInterface::class) // object-only
-> TypeRegistry::getMutableObjectType('Foo') (TypeRegistry.php:80)
-> it's an interface -> throws
getOutputTypes()loops over every supported class and calls mapClassToType() on it, interfaces included. In 8.3.0 mapClassToType() is typed : MutableObjectType, so the second it hits the interface class it throws. On 8.1.2 that method could return an interface, so it was fine.
Description
Ran into what looks like a regression somewhere between 8.1.2 and 8.3.0.
Short version: declare a GraphQL interface the documented way (#[Type] on a PHP interface), have something return that interface as an output type, and building the schema blows up on 8.3.0. The exact same code builds fine on 8.1.2.
Error:
Expected GraphQL type "Foo" to be an MutableObjectType. Got a TheCodingMachine\GraphQLite\Types\TypeAnnotatedInterfaceType thrown from TypeRegistry::getMutableObjectType().
Repro is basically the interfaces doc example:
Then have any field return Foo (the interface) as its output type and build/validate the schema.
What's going on, from a backtrace:
getOutputTypes()loops over every supported class and calls mapClassToType() on it, interfaces included. In 8.3.0 mapClassToType() is typed: MutableObjectType, so the second it hits the interface class it throws. On 8.1.2 that method could return an interface, so it was fine.