java-graphql-无法将类型定义与Java类型匹配

时间:2018-08-03 19:55:54

标签: spring graphql graphql-java

我正在使用graphql-spring-boot从我的spring-boot项目中提供graphql查询。现在,我正在努力使graphql方案类型定义与我的spring entite匹配。无论出于何种原因,我都会遇到以下错误:

Caused by: com.coxautodev.graphql.tools.SchemaClassScannerError: Unable to match type definition (ListType{type=TypeName{name='HomestayInfo'}}) with java type (class ninja.familyhomestay.domain.HomestayInfo): Java class is not a List or generic type information was lost: class ninja.familyhomestay.domain.HomestayInfo
    at com.coxautodev.graphql.tools.TypeClassMatcher.error(TypeClassMatcher.kt:19)
    at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:79)
    at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:25)

这是我对HomestayInfo的graphql模式定义:

type HomestayInfo{
    homestayName: String
    homestayShortDescription: String
    homestayDescription: String
    address: Address
    rooms: [Room]
    houseImages: [HouseImage]
    pets: [Pet]
}

和相应的kotlin实体:

@Entity
@Table(name = "homestay_info")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "homestay_info")
data class HomestayInfo(
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    var id: Long? = null,

    @Column(name = "homestay_name")
    var homestayName: String? = null,

    @Column(name = "homestay_short_description")
    var homestayShortDescription: String? = null,

    @Column(name = "homestay_description")
    var homestayDescription: String? = null,

    @OneToOne
    @JoinColumn(name = "address_id")
    var address:Address?=null,

    @OneToMany(mappedBy = "homestayInfo", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
    var rooms: MutableSet<Room> = HashSet(),

    @OneToMany(mappedBy = "homestayInfo", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
    var houseImages: MutableSet<HouseImage> = HashSet(),

    @OneToMany(mappedBy = "homestayInfo", cascade = [CascadeType.ALL], fetch = FetchType.LAZY)
    var pets: MutableSet<Pet> = HashSet()
) : Serializable

我认为映射没有任何问题。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在您的schema.graphqls文件顶部添加标量日期应该可以解决问题!因此您的文件如下所示:

scalar Date

schema {           // not sure if your file has this, but mine does

   query: Query

}

type HomestayInfo{
...