graphql-jit 적용해봤는데… recursive input type 쓰니까 compi...
# 잡담
t
graphql-jit 적용해봤는데… recursive input type 쓰니까 compileQuery 함수에서 무한루프 도네요.. 흑 ㅠ 다들 recursive input type 안쓰시나요??
Copy code
input ArticlesWhereInput {
  _id: String
  user: String
  OR: [ArticlesWhereInput!]
}
성능을 위해서 타입을 하나 더 만들어야될까요 ㅠ
h
헐…
t
결국 스키마를 포기하고… 성능을 택했습니다 ㅋㅋㅋㅋ
엄청 빨라지네요 오오
h
재귀 인풋 타입을 쓰는군요
t
Copy code
input ArticlesWhereInput {
  _id: String
  type: String

  OR: [ArticlesWhereInput!]
}
요런식으로 쓰고있어용 ㅋㅋ
Copy code
{
  articles(where: {
    _id: "...",
    OR: [
      { _id: "..." },
      { type: "business" }
    ]
  }) {
    _id
  }
}
h
될거라고 생각도 못했지만 확실히 jit 돌리기 애매해지긴 하겠군요 ㅋ-ㅋ
역시 필터는 찍어내야 제맛….
t
찍는다는게 무슨뜻인가요?! ㅋㅋㅋ
h
Copy code
type Query {
  articles: [Article!]! @filter(by: ["_id", "type"])
}
Copy code
input ArticleFilterInput {
  ...
  OR: [ArticleFilterInputOrInput!]
}

input ArticleFilterInputOrInput {
  ...
}
이렇게 찍으면 되는거 아닌가용
t
네 ㅋㅋ 그렇게 하면 되죠 ㅋㅋ 근데 제가 스키마는 필드 하나하나 다 Description 달아놔야 직성이 풀리는데…
Description을 두번씩 달아야해서 굉장히 찝찝하네요 ㅋㅋ
설마 저 directive가 Input 타입을 자동으로 만들어주나요?
h
description 도 넣으면 되죠
description argument 를 만들거나
아님 주석을 찾아서 복사하거나
그 맛에 메타프로그래밍 하는 거 아니였습니까 ㅋㅋ
t
ㅋㅋㅋㅋㅋ 이제 저도 custom directive의 세계로 발을 들이게되는건가요
혜성님 따라가기 바쁘네요 ㅠ
h
앗 어렵지 않아요
오히려 좀 원시적으로 하는데
schema.graphql 만들어두고
Copy code
import { makeExecutableSchema } from '@graphql-tools/schema';

import typeDefs from '@devsisters/web-swt-graphql/schema';

const OUTPUT_PATH = resolve(process.cwd(), 'shared/graphql/schema/executable-schema.graphql');

const schema = makeExecutableSchema({
  typeDefs,
  schemaDirectives: {
    constraint: ConstraintDirective,
    formatDate: FormatDateDirective,
    formatDuration: FormatDurationDirective,
    pagination: PaginationDirective,
    // ...
  },
});

writeFileSync(OUTPUT_PATH, printSchema(schema), {
  encoding: 'utf-8',
  flag: 'w',
});
이런 스크립트를 돌려요
스키마가 로컬에 있을 때는 코드젠에 훅걸어서 쓰고