item没有类型注释,并在其自己的初始化程序中直接或间接引用

时间:2018-07-25 02:28:14

标签: typescript graphql

我有一个模型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”,因为它没有类型注释,并且在其自己的初始化程序中直接或间接引用。

1 个答案:

答案 0 :(得分:3)

您只需将LocationType类型指定为GraphQLObjectType

类似这样的东西:

const LocationType: GraphQLObjectType = new GraphQLObjectType({
    name: "LocationType",
    fields: () => ({
        ...
        states: {type: new GraphQLList(LocationType)},
        ...
    }),
});