GraphQL Enum Type
特定の値のみを持つ型
code: enum example
enum PullRequestState {
OPEN
CLOSED
MERGED
}
注意
異なる構造を持つリソースをまとめるための「種類」を enum で定義するのはアンチパターン
code: bad example
enum DocumentType {
ENTRY
COMMENT
}
type Document {
documentType: DocumentType!
# COMMENT の場合は title がないので nullable
title: String
# ENTRY も COMMENT も content は必ず存在するので non-nullable
content: String!
}
そうではなく、次の例のようにそれぞれに応じた type, union を定義するほうが、複数の type のインターフェースも無理に一致させる必要がなく適切に type を定義できる
code: good example
type Entry {
...
title: String!
content: String!
...
}
type Comment {
...
content: String!
...
}
union Document = Entry | Comment