我尝试将UnionType与Graphql集成,但是不幸的是没有成功。
我收到错误消息:
Either the SearchResult type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."
我已经尝试使用解析器内部名为resolveType
的ResolveProperty解决该问题。但是该功能未执行。
当我命名函数__resolveType
时,我收到错误消息Name "__resolveType" must not begin with "__", which is reserved by GraphQL introspection.
createUnionType函数:
export const SearchResultUnion = createUnionType({
name: "SearchResult", // the name of the GraphQL union
types: [CPublicStore,CArticle, CService], // array of object types classes
});
我的Search-ObjectType:
@ObjectType()
export class CSearch implements ISearch {
@Field(type => [SearchResultUnion]) source: (CArticle | CService | CPublicStore)[]
...
}
和应该解析源属性的解析器:
@Resolver(of => CSearch)
export class SearchTransform implements ResolverInterface<CSearch>{
...
@ResolveProperty("__resolveType",()=>String)
__resolveType(obj) {
....
}
}