인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

윰이님의 프로필 이미지

작성한 질문수

[코드캠프] 부트캠프에서 만든 '완벽한' 프론트엔드 코스

10-1 API 타입 codegen 에러

해결된 질문

작성

·

48

0

yarn codegen을 입력하면 이런 에러가 뜹니다 Not all operations have an unique name: fetchBoard:

success Saved 1 new dependency.

info Direct dependencies

└─ @graphql-codegen/cli@5.0.4

info All dependencies

└─ @graphql-codegen/cli@5.0.4

코드젠은 이렇게 잘 설치가 되었고

package.json 에도 이렇게 추가해 놓았습니다

"codegen": "graphql-codegen --config codegen.ts" 

 

PS C:\Users\young\Desktop\frontend\class-example\my-app> yarn codegen

yarn run v1.22.22

warning ..\..\..\..\package.json: No license field

$ graphql-codegen --config codegen.ts

Parse Configuration

❯ Generate outputs

❯ Generate to ./src/commons/graphql/

Load GraphQL schemas

Load GraphQL documents

⠏ Generate

[client-preset] the following anonymous operation is skipped:

mutation {

createBoard(writer: "윰", title: "작성중", contents: "내용작성중") {

_id

number

message

}

}

[client-preset] the following anonymous operation is skipped:

query {

fetchBoard(number: 1) {

number

writer

title

contents

}

}

[client-preset] the following anonymous operation is skipped:

query {

fetchBoard(number: 2) {

number

writer

title

contents

}

}

[client-preset] the following anonymous operation is skipped:

query {

fetchBoards {

number

writer

title

contents

}

}

[client-preset] the following anonymous operation is skipped:

query {

fetchBoards {

number

Parse Configuration

Generate outputs

❯ Generate to ./src/commons/graphql/

Load GraphQL schemas

Load GraphQL documents

Not all operations have an unique name: fetchBoard:

* fetchBoard found in:

- C:/Users/young/Desktop/frontend/class-examp…

error Command failed with exit code 1.

info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

답변 1

0

인프런 AI 인턴님의 프로필 이미지

안녕하세요, 인프런 AI 인턴입니다.

윰이님께서 겪고 계신 문제는 GraphQL 코드 제너레이터를 사용하는 과정에서 발생한 오류입니다. 이 오류 메시지는 모든 GraphQL operation에 고유한 이름이 필요하다는 것을 나타냅니다. GraphQL에서 operation 이름은 고유해야 하며, 이름이 없는 (익명) 또는 중복된 이름이 있는 operation은 문제가 됩니다.

다음과 같은 해결 방법을 고려해 볼 수 있습니다:

  1. GraphQL 쿼리 또는 변형에 이름 추가:
    만약 익명으로 작성된 GraphQL 작업이 있다면, 각 작업에 명시적으로 이름을 부여해야 합니다. 예를 들어:
    ”`graphql
    mutation CreateBoard {
    createBoard(writer: “윰”, title: “작성중”, contents: “내용작성중”) {
    _id
    number
    message
    }
    }

query FetchBoard1 {
fetchBoard(number: 1) {
number
writer
title
contents
}
}
“`

  1. 코드 중복 확인:
    코드 내에서 동일한 이름을 가진 여러 operation이 있을 수 있습니다. 이러한 경우, 적절하게 이름을 변경하여 각각의 operation을 고유하게 만들어야 합니다.

이러한 조치를 취하면 코드젠 에러를 해결하는 데 도움이 될 것입니다. 더 자세한 내용을 알고 싶다면 GraphQL Code Generator 공식 문서를 참고하시길 바랍니다.

질문이 더 있다면 언제든지 문의해 주세요!

윰이님의 프로필 이미지

작성한 질문수

질문하기