Skip to content

Interfaces stopped working #768

@murtukov

Description

@murtukov

After updating to 14.5.0 I started to see the error:

Runtime Object type "User" is not a possible type for "NodeInterface"

Simplified schema:

final class QueryType extends ObjectType
{
    public function __construct($typeRegistry)
    {
        $config = [
            'name' => 'Query',
            'fields' => fn() => [
                'allObjects' => [
                    'type' => Type::listOf($typeRegistry->get('NodeInterface')),
                    'resolve' => function ($value, $args, $context, $info) {
                        // ...
                    },
                ],
            ],
        ];
        
        parent::__construct($config);
    }
}

final class UserType extends ObjectType
{   
    public function __construct($typeRegistry)
    {
        $config = [
            'name' => 'User',
            'fields' => fn() => [
                'id' => [
                    'type' => Type::nonNull(Type::id()),
                    'resolve' => function ($value, $args, $context, $info) {
                        // ...
                    },
                ],
                'name' => Type::string(),
            ],
            'interfaces' => fn() => [
                $typeRegistry->get('NodeInterface'),
            ],
        ];
        
        parent::__construct($config);
    }
}

final class NodeInterfaceType extends InterfaceType
{
    public function __construct($typeRegistry, $typeResolver)
    {
        $config = [
            'name' => 'NodeInterface',
            'fields' => fn() => [
                'id' => Type::nonNull(Type::id()),
            ],
            'resolveType' => fn($value, $context, $info) => $typeResolver->resolve($value),
        ];
        
        parent::__construct($config);
    }
}

Query:

{
  allObjects {
    id
  }
}

This is a simplified example, but the thing is it was working before I updated from 14.4.0 to 14.5.0. Seems like it doesn't see anymore that the User type implements the NodeInterface interface

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions