我有一个模型Location
,这种关系与自身有关。
class Location extends Model<Location> {
...
@BelongsTo(() => Location, "countryId")
public country?: Location;
@BelongsTo(() => Location, "stateId")
public state?: Location;
@HasMany(() => Location, "countryId")
public states?: Location[];
@HasMany(() => Location, "stateId")
public regions?: Location[];
@HasMany(() => Location, "regionId")
public places?: Location[];
...
}
所以基本上counties
有很多states
有很多regions
等等。我想将其实现为GraphQLType
。< / p>
我尝试过什么:
const LocationType = new GraphQLObjectType({
name: "LocationType",
fields: () => ({
...
states: {type: new GraphQLList(LocationType)},
...
}),
});
我遇到错误
“ LocationType”隐式具有类型“ any”,因为它没有类型注释,并且在其自己的初始化程序中直接或间接引用。
答案 0 :(得分:3)
您只需将LocationType
类型指定为GraphQLObjectType
。
类似这样的东西:
const LocationType: GraphQLObjectType = new GraphQLObjectType({
name: "LocationType",
fields: () => ({
...
states: {type: new GraphQLList(LocationType)},
...
}),
});