how to map java class having parent class as field with graphql

Viewed 408

I have Java class modeled like:

public class Tree {
    private Integer countLeave;
    private String type;
}
    
public class BananaTree extends Tree {
    private Integer countBanana;
}
    
public class MangoTree extends Tree {
    private Integer countMango;
}
    
public class Forest {
    private List<Tree> trees;
}

I want to map above model in GraphQL schema. And have query getForest where it will load all type of tree and return to caller.

type Query {
    getForest:Forest
}

interface Tree {
    countLeave:Integer
    type:String
}
    
type BananaTree implements Tree {
    countBanana:Integer
}
    
type MangoTree implements Tree {
    countMango:Integer
}

But on doing so getting: There is no type resolver defined for interface / union 'Tree' type

0 Answers
Related