1 year ago

#70398

test-img

Tyler Edmonds

Problems implementing Interface in graphql

I am trying to implement an interface in graphql and stuck in a loop.

I am getting the following error

Object type 'FeaturedCourseDto' implements a known interface, but no class could be found for that type name. Please pass a class for type 'FeaturedCourseDto' in the parser's dictionary.

So I add Featured Element Dto to the dictionary, but then get

value already present: class x.x.x.FeaturedCourseDto

My dictionary code below has some commented out fields because I've been flipping around trying all sorts of combinations to no avail...

Any help would be appreciated.

Here is my graphql code

interface Featurable {
    guid: ID
    entityGuid: ID
    friendly: String
    description: String
    institutionName: String
    institutionFriendly: String
    primaryImageUrlBase: String
    primaryImageUrlPath: String
}

type FeaturedElementDto implements Featurable{
    guid: ID
    type: String
    entityGuid: ID
    friendly: String
    description: String
    institutionName: String
    institutionFriendly: String
    primaryImageUrlBase: String
    primaryImageUrlPath: String
    orderNumber: Int
}

type FeaturedCourseDto implements Featurable{
    guid: ID
    type: String
    entityGuid: ID
    friendly: String
    description: String
    institutionName: String
    institutionFriendly: String
    primaryImageUrlBase: String
    primaryImageUrlPath: String
    orderNumber: Int
    author: String
    syllabus: String
    trailer: String
}

type FeaturedListDto {
    guid: ID
    friendly: String
    description: String
    elements: [Featurable]
}

My Java code

@Getter
@Setter
@NoArgsConstructor
public class FeaturedElementDto {
    private UUID guid;
    private String type;
    private UUID entityGuid;
    private String friendly;
    private String description;
    private String institutionName;
    private String institutionFriendly;
    private String primaryImageUrlBase;
    private String primaryImageUrlPath;
    private Integer orderNumber;
}

@Getter
@Setter
@NoArgsConstructor
public class FeaturedCourseDto extends FeaturedElementDto {
    private String author;
    private String syllabus;
    private String trailer;
}

@Bean
    public SchemaParserDictionary schemaParserDictionary() {
        return new SchemaParserDictionary()
//              .add("Featurable", Featurable.class);
                .add("FeaturedElementDto", FeaturedElementDto.class);
//              .add("FeaturedCourseDto", FeaturedCourseDto.class);
    }

java

spring-boot

graphql

graphql-java

0 Answers

Your Answer

Accepted video resources