Skip to content

Commit

Permalink
fix(blog.entity): the field "body" is not recognized by GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrdsilva committed May 26, 2024
1 parent d47e45a commit 8f77d8e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
37 changes: 35 additions & 2 deletions src/entities/blog.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
import { Field, ID, Int, ObjectType } from '@nestjs/graphql';
import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';

@ObjectType()
class Body {
@Field(() => String)
time: String;

@Field(() => [Block])
blocks: Block[];

@Field(() => String)
version: string;
}

@ObjectType()
class Data {
@Field(() => String)
text: string;

@Field(() => Int, { nullable: true })
level: number;
}

@ObjectType()
class Block {
@Field(() => String)
id: string;

@Field(() => String)
type: string;

@Field(() => Data)
data: Data;
}

@Entity()
@ObjectType()
export class Blog {
Expand All @@ -21,8 +54,8 @@ export class Blog {
filename: string;

@Column({ type: 'json', nullable: false })
@Field(() => String)
body: string;
@Field(() => Body)
body: Body;

@Column({ default: 0 })
@Field(() => Int)
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/blog.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { File } from '../entities/file.entity';
export class BlogResolver {
constructor(private readonly blogService: BlogService) {}

// @UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard)
@Query(() => [Blog])
findBlogPosts() {
return this.blogService.find();
}

// @UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard)
@Query(() => Blog)
findBlogPost(@Args('id') id: string) {
return this.blogService.findById(id);
Expand Down

0 comments on commit 8f77d8e

Please sign in to comment.