Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NestJs:确保您的类被适当的装饰器装饰_Javascript_Node.js_Typescript_Graphql_Nestjs - Fatal编程技术网

Javascript NestJs:确保您的类被适当的装饰器装饰

Javascript NestJs:确保您的类被适当的装饰器装饰,javascript,node.js,typescript,graphql,nestjs,Javascript,Node.js,Typescript,Graphql,Nestjs,我使用graphql request作为graphql客户端来查询无头CMS,以获取内容、修改并返回原始请求/查询。无头cms单独托管供参考 我有以下代码: @Query(returns => BlogPost) async test() { const endpoint = 'https://contentxx.com/api/content/project-dev/graphql' const graphQLClient = new GraphQLClient(en

我使用
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
是一种具有以下类型的模型:

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输出类型。制作 确保你的班级有合适的装饰师


这里缺少什么?

当没有关于它被传递到graphql解析器的信息时,graphql服务器应该如何理解
FlatDataType
的类型?您还需要向其中添加graphql装饰器
@ObjectType()
@Field()
等。

FlatDataType
未定义为
@ObjectType()
,因此类型graphql(或@nestjs/graphql)不能将其作为graphql中的输出