N:M 등록 / 조회 API
query{
fetchProduct(productId:"7967c808-532f-48e8-87b7-4f4536ab1903"){
id
name
description
price
isSoldout
productSaleslocation{
id
address
addressDetail
lat
lng
meetingTime
}
productCategory{
id
name
}
productTags{
id
name
}
}
}
{
"errors": [
{
"message": "Cannot return null for non-nullable field Query.fetchProduct.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"fetchProduct"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stacktrace": [
"Error: Cannot return null for non-nullable field Query.fetchProduct.",
" at completeValue (C:\\Users\\enter\\OneDrive\\바탕 화면\\agarang-camp\\19-01-typeorm-crud-many-to-many\\node_modules\\graphql\\execution\\execute.js:594:13)",
" at C:\\Users\\enter\\OneDrive\\바탕 화면\\agarang-camp\\19-01-typeorm-crud-many-to-many\\node_modules\\graphql\\execution\\execute.js:486:9",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async Promise.all (index 0)",
" at execute (C:\\Users\\enter\\OneDrive\\바탕 화면\\agarang-camp\\19-01-typeorm-crud-many-to-many\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:501:14)",
" at processGraphQLRequest (C:\\Users\\enter\\OneDrive\\바탕 화면\\agarang-camp\\19-01-typeorm-crud-many-to-many\\node_modules\\apollo-server-core\\src\\requestPipeline.ts:407:22)",
" at processHTTPRequest (C:\\Users\\enter\\OneDrive\\바탕 화면\\agarang-camp\\19-01-typeorm-crud-many-to-many\\node_modules\\apollo-server-core\\src\\runHttpQuery.ts:436:24)"
]
}
}
}
],
"data": null
}
똑같이 따라헀는데, fetchproduct 부분에서 왜 이런 오류가 발생하는 것일까요?
product.entity.ts 를 아래와 같이 nullable: true로 수정했는데도 플레이 그라운드에서 똑같은 에러가 나옵니다.
========================
import { Field, Int, ObjectType } from '@nestjs/graphql';
/* eslint-disable prettier/prettier */
// product.entity.ts
import { ProductCategory } from 'src/apis/productCategory/entities/productCategory.entity';
import { ProductSaleslocation } from 'src/apis/productsSaleslocation/entities/productSaleslocation.entity';
import { ProductTag } from 'src/apis/productTags/entities/productTag.entity';
import { User } from 'src/apis/users/entities/user.entity';
import {
Column,
DeleteDateColumn,
Entity,
JoinColumn,
JoinTable,
ManyToMany,
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
@Entity()
@ObjectType()
export class Product {
@PrimaryGeneratedColumn('uuid')
@Field(() => String)
id: string;
@Column()
@Field(() => String)
name: string;
@Column()
@Field(() => String)
description: string;
@Column()
@Field(() => Int)
price: number;
@Column({ default: false }) //시작시 디폴트값
@Field(() => Boolean)
isSoldout: boolean;
// soldedAt: Date
// @Column({ default: false }) //시작시 디폴트값
// @Field(() => Boolean)
// isDeleted: boolean;
// @Column({ default: null }) //시작시 디폴트값
// @Field(() => Date)
// DeletedAt: Date;
@DeleteDateColumn()
@Field({ nullable: true })
deletedAt: Date;
@JoinColumn()
@OneToOne(() => ProductSaleslocation)
@Field(() => ProductSaleslocation)
productSaleslocation: ProductSaleslocation;
@ManyToOne(() => ProductCategory)
@Field(() => ProductCategory)
productCategory: ProductCategory;
@ManyToOne(() => User)
@Field(() => User, { nullable: true })
user: User;
@JoinTable()
@ManyToMany(() => ProductTag, (productTags) => productTags.products)
@Field(() => [ProductTag])
productTags: ProductTag[];
}
/*tag가 배열이다
그래프QL에서 배열은 양쪽으로 감싸는 게 배열이다. */
위 product.enttity.ts를 수정한 이유는
DB에 deletedAt 컬럼이 null, userId 컬럼이 null로 되어 있어서 아래와 같이 추가해주었습니다. 그래도 똑같은 에러가 발생하네요.
@Field({ nullable: true })
deletedAt: Date;
@ManyToOne(() => User)
@Field(() => User, { nullable: true })
user: User;
Câu trả lời 1
그래프 ql 문서 사용할때 느낌표 남는거 어떻게 없애나요?
0
80
2
강의 전체 소스 코드를 받고싶습니다.
0
74
2
fontawesome 사용 문의
0
75
2
소스 코드 부탁드립니다~
0
84
2
깃 레포지터리 소스
0
78
2
커리큘럼12.css 정렬 에 나오는 과제 정답알고싶어요
0
71
2
10-01 Entity TypeOrmModule.forRoot 에 entities
0
83
3
강의 버전관련 문의입니다
0
101
2
Ubuntu 설치 관련
0
59
1
schema.gql 질문 드립니다.
0
49
1
서버 재실행시 Many to Many
0
100
3
input 관련 문의
0
89
2
Rest API 보다는 graphql이 주된 내용인데
0
130
2
강의 전체 소스코드 받을수있을까요?
0
153
1
도커볼륨 마운트 관련
0
125
2
findOne 타입스크립트오류
0
107
1
http => htrtps 호출 인증서 신뢰 오류
0
347
1
self-signed certificate in certificate chain 에러 발생
0
408
1
mongoose 설치 오류
0
140
1
특정 API, 특정 IP 허용 (단일경로에 CORS 활성화)
0
279
2
08-06
0
174
3
구조랑 패턴 관련해서 질문
0
121
2
mydocker
0
125
2
coolsms statuscode 2000 인데 전송안돼는 경우 확인.
0
153
1

