@@ -53,7 +53,7 @@ exports.createPages = async function ({ actions, graphql }) {
53
53
let labelsMap = new Map ( ) ;
54
54
let nlen = 0 ;
55
55
56
- data . allDiscussionsJson . edges . forEach ( ( { previous, next, node } ) => {
56
+ data ? .allDiscussionsJson ? .edges ? .forEach ( ( { previous, next, node } ) => {
57
57
const curr = node . node ;
58
58
const number = curr . number ;
59
59
@@ -69,18 +69,19 @@ exports.createPages = async function ({ actions, graphql }) {
69
69
} ) ;
70
70
71
71
// category
72
- const category = curr . category ;
73
- if ( ! categoryMap . get ( category . name ) ) {
74
- categoryMap . set ( category . name , category ) ;
72
+ const category = curr ? .category ;
73
+ if ( category && ! categoryMap . get ( category ? .name ) ) {
74
+ categoryMap . set ( category ? .name , category ) ;
75
75
}
76
76
77
77
// labels
78
- const labels = curr . labels . edges ;
79
- labels . forEach ( ( label ) => {
80
- if ( ! labelsMap . get ( label . node . name ) ) {
81
- labelsMap . set ( label . node . name , label . node ) ;
82
- }
83
- } ) ;
78
+ const labels = curr ?. labels ?. edges ;
79
+ labels &&
80
+ labels . forEach ( ( label ) => {
81
+ if ( ! labelsMap . get ( label . node . name ) ) {
82
+ labelsMap . set ( label . node . name , label . node ) ;
83
+ }
84
+ } ) ;
84
85
} ) ;
85
86
86
87
// create category pages
@@ -127,3 +128,69 @@ exports.onCreateWebpackConfig = ({ actions }) => {
127
128
] ,
128
129
} ) ;
129
130
} ;
131
+
132
+ exports . createSchemaCustomization = ( { actions } ) => {
133
+ const { createTypes } = actions ;
134
+ const typeDefs = `
135
+ type DiscussionsJsonNode {
136
+ category: Category
137
+ labels: LabelsConnection
138
+ }
139
+
140
+ type Category {
141
+ name: String!
142
+ emoji: String!
143
+ description: String!
144
+ isAnswerable: Boolean!
145
+ }
146
+
147
+ type LabelsConnection {
148
+ edges: [LabelsEdge]
149
+ }
150
+ type LabelsEdge {
151
+ node: Labels!
152
+ }
153
+ type Labels {
154
+ id: String
155
+ name: String
156
+ color: String
157
+ }
158
+
159
+ type IssuesJson implements Node {
160
+ labels: LabelsConnection
161
+ author: Author!
162
+ comments: CommentsConnection
163
+ }
164
+
165
+ type CommentsConnection {
166
+ edges: [CommentsEdge]
167
+ }
168
+ type CommentsEdge {
169
+ node: IssuesJsonCommentsEdgesNode
170
+ }
171
+
172
+ type IssuesJsonCommentsEdgesNode {
173
+ id: String!
174
+ bodyHTML: String!
175
+ author: Author!
176
+ replies: RepliesConnection
177
+ }
178
+ type RepliesConnection {
179
+ edges: [RepliesEdge]
180
+ }
181
+ type RepliesEdge {
182
+ node: Replies!
183
+ }
184
+ type Replies {
185
+ id: String!
186
+ bodyHTML: String!
187
+ author: Author!
188
+ }
189
+ type Author {
190
+ login: String!
191
+ avatarUrl: String!
192
+ url: String!
193
+ }
194
+ ` ;
195
+ createTypes ( typeDefs ) ;
196
+ } ;
0 commit comments