在我的项目中,我有不同的实体,每个实体都有不同的属性,因此我需要一个复杂的实体类型。我已经阅读了有关在GraphQL中创建此类动态模式的接口的信息,并且尝试通过实体中的单个属性对象(而非用于测试的映射)来实现该模式,但是由于出现该模式无效,因此出现了GraphQLError
模式出了什么问题,如何实现动态模式?有更好的解决方案来解决这个问题吗?
schema.graphql
type Query {
entities: [Entity]
}
type Entity {
name: String!,
property: Property
}
type PropertyString implements Property {
value: String
}
type PropertyInt implements Property {
value: Int
}
interface Property {
}
Entity.ts
export class Entity {
private _name: string;
private _property: Property;
...
}
PropertyInt.ts
export class PropertyInt implements Property {
private _value: number;
...
}
PropertyString.ts
export class PropertyString implements Property {
private _value: string;
...
}