Nestjs GraphQL联合类型

时间:2019-04-02 11:03:04

标签: graphql nestjs

我尝试将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) {
       ....
    }
}

0 个答案:

没有答案