error - GraphQLError: Input Object type CreateEventInput must define one or more fields.

doohyunlm·2024년 2월 4일
2

error

목록 보기
10/10
post-thumbnail
[
  GraphQLError: Input Object type CreateEventInput must define one or more fields.
      at SchemaValidationContext.reportError (/Users/sena/workspace/my-quant-v2-server/node_modules/graphql/type/validate.js:73:7)
      at validateInputFields (/Users/sena/workspace/my-quant-v2-server/node_modules/graphql/type/validate.js:532:13)
      at validateTypes (/Users/sena/workspace/my-quant-v2-server/node_modules/graphql/type/validate.js:260:7)
      at validateSchema (/Users/sena/workspace/my-quant-v2-server/node_modules/graphql/type/validate.js:43:3)
      at graphqlImpl (/Users/sena/workspace/my-quant-v2-server/node_modules/graphql/graphql.js:60:63)
      at /Users/sena/workspace/my-quant-v2-server/node_modules/graphql/graphql.js:23:43
      at new Promise (<anonymous>)
      at graphql (/Users/sena/workspace/my-quant-v2-server/node_modules/graphql/graphql.js:23:10)
      at GraphQLSchemaFactory.create (/Users/sena/workspace/my-quant-v2-server/node_modules/@nestjs/graphql/dist/schema-builder/graphql-schema.factory.js:55:69)
      at GraphQLSchemaBuilder.generateSchema (/Users/sena/workspace/my-quant-v2-server/node_modules/@nestjs/graphql/dist/graphql-schema.builder.js:36:52) {
    path: undefined,
    locations: undefined,
    extensions: [Object: null prototype] {}
  }
]

graphql로 개발을 하다보면 가끔 마주 할 수 있는 error입니다.

graphql에서 dto를 설계하다 보면 pickType이나 OmitType을 많이 사용하게 되는데 상속 받아서 사용할때 따로 어노테이션을 걸어주지 않으면 error를 발생하게 됩니다.

해결방법

@InputType({ isAbstract: true })
@ObjectType()

기존 entity의 상단에 InputType을 추가해주면 정상적으로 동작합니다.

마치며

  • 틀린 점이 있다면 말씀 부탁드립니다.
profile
백엔드 개발자

2개의 댓글

comment-user-thumbnail
2024년 2월 4일

유익하네요!

1개의 답글