diff --git a/src/plugins/github/githubPlugin.js b/src/plugins/github/githubPlugin.js index 174ba82..442996e 100644 --- a/src/plugins/github/githubPlugin.js +++ b/src/plugins/github/githubPlugin.js @@ -109,6 +109,61 @@ export type NodeID = | AuthorNodeID; export type NodeType = $ElementType; +// A map from NodeType string to the corresponding ID and payload types. +// Primarily useful for adding static assertions with $ObjMap, but also +// useful at the value layer as $ElementType, for +// instance. +export type NodeTypes = {| + ISSUE: { + id: IssueNodeID, + payload: IssueNodePayload, + }, + PULL_REQUEST: { + id: PullRequestNodeID, + payload: PullRequestNodePayload, + }, + COMMENT: { + id: CommentNodeID, + payload: CommentNodePayload, + }, + PULL_REQUEST_REVIEW_COMMENT: { + id: PullRequestReviewCommentNodeID, + payload: PullRequestReviewCommentNodePayload, + }, + PULL_REQUEST_REVIEW: { + id: PullRequestReviewNodeID, + payload: PullRequestReviewNodePayload, + }, + USER: { + id: UserNodeID, + payload: UserNodePayload, + }, + ORGANIZATION: { + id: OrganizationNodeID, + payload: OrganizationNodePayload, + }, + BOT: { + id: BotNodeID, + payload: BotNodePayload, + }, +|}; +(function staticAssertions() { + // Check that node payload types are exhaustive. + (x: NodeType): $Keys => x; + + // Check that each type is associated with the correct ID type. + // Doesn't work because of a Flow bug; should work if that bug is + // fixed: https://github.com/facebook/flow/issues/4211 + // (Summary of bug: $ElementType does not preserve unions.) + // + // >( + // x: T + // ): $ElementType< + // $ElementType<$ElementType, "id">, + // "type" + // > => x; +}); + export type AuthorshipEdgePayload = {}; export type AuthorshipEdgeID = { +type: "AUTHORSHIP",