Skip to content

#[Type] interface used as an output type breaks schema build on 8.3.0 (worked on 8.1.2) #816

Description

@michael-georgiadis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions