Skip to content

Interfaces and unions not allowed as types in a union #456

Open
@rideliner

Description

@rideliner

Description

A union can only contain object types. The class scanner fails to deeply scan a union if it contains another union or interface type.

Expected behavior

A union that contains another union or an interface should be valid.

type Query {
    entity: StarWarsEntity
}

interface Character {
    name: String
}

type Human implements Character {
    name: String
}

type Droid implements Character {
    name: String
}

type Planet {
    location: String
}

union StarWarsEntity = Character | Planet

Actual behavior

The SchemaClassScanner only looks at ObjectTypeDefinitions when a union is scanned. InterfaceTypeDefinitions and UnionTypeDefinitions are ignored.

graphql.kickstart.tools.SchemaClassScannerError: No object type found with name 'Character' for union: UnionTypeDefinition{name='StarWarsEntity'directives=[], memberTypes=[TypeName{name='Character'}, TypeName{name='Planet'}]}

Steps to reproduce the bug

interface StarWarsEntity {}
interface Character extends StarWarsEntity {
    String getName();
}

class Human implements Character {
    @Override
    String getName() {
        return null;
    }
}

class Droid implements Character {
    @Override
    String getName() {
        return null;
    }
}

class Planet implements StarWarsEntity {
    String location;
}
SchemaParser.newParser()
    .schemaString("...")
    .resolvers(new GraphQLQueryResolver() {
        StarWarsEntity getEntity() { return null; }
    })
    .dictionary(Human.class, Droid.class, Planet.class, Character.class)
    .scan();

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