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") {
id
flatData {
body
slug
subtitle
title
}
}
}`
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';
@ObjectType()
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?
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 = 'https://contentxx./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
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';
@ObjectType()
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?
Share Improve this question asked Feb 16, 2021 at 13:29 GammerGammer 5,62820 gold badges82 silver badges132 bronze badges2 Answers
Reset to default 8How 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.
FlatDataType
is not defined as @ObjectType()
, therefore type-graphql (or @nestjs/graphql) can't take it as an output in GraphQL.