Skip to content

NestJs: Make sure your class is decorated with an appropriate decorator

I am using graphql-request as a GraphQL client to query a headless CMS to fetch stuff, modify and return to the original request/query. headless cms is hosted separately fyi.

I have the following code :

@Query(returns => BlogPost)
  async test() {
    const endpoint = ''
    const graphQLClient = new GraphQLClient(endpoint, {
      headers: {
        authorization: 'Bearer xxxxxxx',
    const query = gql`
        findContentContent(id: "9f5dde89-7f9b-4b9c-8669-1f0425b2b55d") {
          flatData {

    return await graphQLClient.request(query);

BlogPost is a model having the types :

import { Field, ObjectType } from '@nestjs/graphql';
import { BaseModel } from './base.model';
import FlatDateType from '../resolvers/blogPost/types/flatDatatype.type';

export class BlogPost extends BaseModel {
  @Field({ nullable: true })
  id!: string;

  @Field((type) => FlatDateType)
  flatData: FlatDateType;

and FlatDateType has the following code

export default class FlatDateType {
  body: string;
  slug: string;
  subtitle: string;
  title: string;

it throws the following exception :

Error: Cannot determine a GraphQL output type for the “flatData”. Make sure your class is decorated with an appropriate decorator.

What is missing in here?



How is your graphql server supposed to understand the type of FlatDataType when there’s no information about it being passed to the graphql parser? You need to add the graphql decorators to it as well. @ObjectType(), @Field(), etc.