![](/img/trans.png)
[英]Babel - decorator of decorated class properties is called before instantiating class
[英]NestJs: Make sure your class is decorated with an appropriate decorator
我正在使用graphql-request
作為 GraphQL 客戶端來查詢無頭 CMS 以獲取內容、修改並返回到原始請求/查詢。 無頭 cms 單獨托管僅供參考。
我有以下代碼:
@Query(returns => BlogPost)
async test() {
const endpoint = 'https://contentxx.com/api/content/project-dev/graphql'
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: 'Bearer xxxxxxx',
},
})
const query = gql`
{
findContentContent(id: "9f5dde89-7f9b-4b9c-8669-1f0425b2b55d") {
id
flatData {
body
slug
subtitle
title
}
}
}`
return await graphQLClient.request(query);
}
BlogPost
是一個 model 具有以下類型:
import { Field, ObjectType } from '@nestjs/graphql';
import { BaseModel } from './base.model';
import FlatDateType from '../resolvers/blogPost/types/flatDatatype.type';
@ObjectType()
export class BlogPost extends BaseModel {
@Field({ nullable: true })
id!: string;
@Field((type) => FlatDateType)
flatData: FlatDateType;
}
和FlatDateType
有以下代碼
export default class FlatDateType {
body: string;
slug: string;
subtitle: string;
title: string;
}
它拋出以下異常:
錯誤:無法確定“flatData”的 GraphQL output 類型。 確保您的 class 使用合適的裝飾器進行裝飾。
這里缺少什么?
當沒有有關將其傳遞給 graphql 解析器的信息時,您的 graphql 服務器應該如何理解FlatDataType
的類型? 您還需要向其中添加 graphql 裝飾器。 @ObjectType()
、 @Field()
等。
FlatDataType
未定義為@ObjectType()
,因此 type-graphql(或 @nestjs/graphql)不能將其視為 GraphQL 中的 output。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.