-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathgraphql-transformer.ts
More file actions
398 lines (308 loc) · 14.7 KB
/
graphql-transformer.ts
File metadata and controls
398 lines (308 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
import { beforeAll, describe, expect, test } from 'vitest'
import { get } from '@/tests/helpers/e2etest'
const makeURL = (pathname: string): string => {
const params = new URLSearchParams({ pathname })
return `/api/article/body?${params}`
}
describe('GraphQL transformer', { timeout: 10000 }, () => {
// Cache expensive responses to avoid duplicate requests
const responseCache = new Map<string, Awaited<ReturnType<typeof get>>>()
const getCached = async (url: string) => {
if (!responseCache.has(url)) {
responseCache.set(url, await get(makeURL(url)))
}
return responseCache.get(url)!
}
beforeAll(() => {
if (!process.env.ROOT) {
console.warn(
'WARNING: The GraphQL transformer tests require the ROOT environment variable to be set to the fixture root',
)
}
})
describe('Reference pages', () => {
test('queries page renders with markdown structure', async () => {
const res = await getCached('/en/graphql/reference/queries')
expect(res.statusCode).toBe(200)
expect(res.headers['content-type']).toContain('text/markdown')
// Check for the main heading
expect(res.body).toContain('# Queries')
// Check for intro
expect(res.body).toContain(
'The query type defines GraphQL operations that retrieve data from the server.',
)
// Check for manual content section
expect(res.body).toContain('## About queries')
expect(res.body).toContain('Every GraphQL schema has a root type')
})
test('queries are formatted correctly', async () => {
const res = await getCached('/en/graphql/reference/queries')
expect(res.statusCode).toBe(200)
// Check for query heading
expect(res.body).toContain('## repository')
// Check for query description
expect(res.body).toContain('Lookup a given repository by the owner and repository name.')
// Check for type (without link)
expect(res.body).toContain('**Type:** Repository')
})
test('query arguments are listed in bullet format', async () => {
const res = await getCached('/en/graphql/reference/queries')
expect(res.statusCode).toBe(200)
// Check for arguments section for codeOfConduct query
expect(res.body).toContain('### Arguments for `codeOfConduct`')
// Check for specific arguments in bullet format
expect(res.body).toContain('`key` (String!)')
expect(res.body).toContain("The code of conduct's key.")
})
test('mutations page renders correctly', async () => {
const res = await getCached('/en/graphql/reference/mutations')
expect(res.statusCode).toBe(200)
// Check for mutation heading
expect(res.body).toContain('## createRepository')
// Check for mutation description
expect(res.body).toContain('Create a new repository.')
// Check for input fields in bullet format
expect(res.body).toContain('### Input fields for `createRepository`')
expect(res.body).toContain('`input`')
// Check for return fields in bullet format
expect(res.body).toContain('### Return fields for `createRepository`')
expect(res.body).toContain('`repository`')
expect(res.body).toContain('The new repository.')
})
test('objects page renders with implements and fields', async () => {
const res = await getCached('/en/graphql/reference/objects')
expect(res.statusCode).toBe(200)
// Check for object heading - AddedToMergeQueueEvent has implements
expect(res.body).toContain('## AddedToMergeQueueEvent')
// Check for implements inline
expect(res.body).toContain('**Implements:** Node')
// Check for fields in bullet format
expect(res.body).toContain('### Fields for `AddedToMergeQueueEvent`')
expect(res.body).toContain('`id`')
expect(res.body).toContain('`actor`')
expect(res.body).toContain('`createdAt`')
})
test('objects page shows field arguments as nested bullets', async () => {
const res = await getCached('/en/graphql/reference/objects')
expect(res.statusCode).toBe(200)
// Check for User object with repositories field that has arguments
expect(res.body).toContain('## User')
expect(res.body).toContain('`repositories`')
// Check for nested argument bullets
expect(res.body).toContain('`first`')
expect(res.body).toContain('Returns the first n elements from the list.')
expect(res.body).toContain('`orderBy`')
})
test('objects page collapses boilerplate Connection and Edge types', async () => {
const res = await getCached('/en/graphql/reference/objects')
expect(res.statusCode).toBe(200)
// Check for Connection/Edge summary section
expect(res.body).toContain('## Connection and Edge types')
expect(res.body).toContain('standard pagination fields')
// Boilerplate Connection/Edge types should be in the summary, not as H2 sections
// ActorConnection has only standard fields (edges, nodes, pageInfo, totalCount)
expect(res.body).toContain('`ActorConnection`')
expect(res.body).not.toMatch(/^## ActorConnection$/m)
})
test('interfaces page renders correctly', async () => {
const res = await getCached('/en/graphql/reference/interfaces')
expect(res.statusCode).toBe(200)
// Check for interface heading
expect(res.body).toContain('## Node')
// Check for interface description
expect(res.body).toContain('An object with an ID.')
// Check for fields in bullet format
expect(res.body).toContain('### Fields for `Node`')
expect(res.body).toContain('`id`')
expect(res.body).toContain('ID of the object.')
})
test('enums page renders with values', async () => {
const res = await getCached('/en/graphql/reference/enums')
expect(res.statusCode).toBe(200)
// Check for enum heading
expect(res.body).toContain('## RepositoryVisibility')
// Check for enum description
expect(res.body).toContain("The repository's visibility level.")
// Check for values in bullet format
expect(res.body).toContain('### Values for `RepositoryVisibility`')
expect(res.body).toContain('`PUBLIC`')
expect(res.body).toContain('The repository is visible to everyone.')
expect(res.body).toContain('`PRIVATE`')
expect(res.body).toContain('The repository is visible only to those with explicit access.')
expect(res.body).toContain('`INTERNAL`')
})
test('unions page renders with possible types', async () => {
const res = await getCached('/en/graphql/reference/unions')
expect(res.statusCode).toBe(200)
// Check for union heading
expect(res.body).toContain('## SearchResultItem')
// Check for union description
expect(res.body).toContain('The results of a search.')
// Check for possible types in bullet format (without links)
expect(res.body).toContain('### Possible types for `SearchResultItem`')
expect(res.body).toMatch(/\*\s*Bot/)
expect(res.body).toMatch(/\*\s*PullRequest/)
expect(res.body).toMatch(/\*\s*User/)
})
test('input-objects page renders correctly', async () => {
const res = await getCached('/en/graphql/reference/input-objects')
expect(res.statusCode).toBe(200)
// Check for input object heading
expect(res.body).toContain('## AbortQueuedMigrationsInput')
// Check for input object description
expect(res.body).toContain('Autogenerated input type of CreateRepository.')
// Check for input fields in bullet format
expect(res.body).toContain('### Input fields for `AbortQueuedMigrationsInput`')
expect(res.body).toContain('`ownerId`')
expect(res.body).toContain('The ID of the organization that is running the migrations.')
})
test('scalars page renders correctly', async () => {
const res = await getCached('/en/graphql/reference/scalars')
expect(res.statusCode).toBe(200)
// Check for scalar heading
expect(res.body).toContain('## Boolean')
// Check for scalar description
expect(res.body).toContain('Represents true or false values.')
// Check for other scalars
expect(res.body).toContain('## String')
expect(res.body).toContain('## ID')
expect(res.body).toContain('## Int')
})
test('reference index page renders', async () => {
const res = await getCached('/en/graphql/reference')
expect(res.statusCode).toBe(200)
// Check for main heading
expect(res.body).toContain('# Reference')
// Check for intro with liquid variable rendered
expect(res.body).toMatch(/(GitHub|HubGit) GraphQL API schema/)
})
})
describe('Overview pages', () => {
test('changelog index page renders with latest year changes', async () => {
const res = await getCached('/en/graphql/overview/changelog')
expect(res.statusCode).toBe(200)
// Check for main heading
expect(res.body).toContain('# Changelog')
// Check for intro
expect(res.body).toContain(
'The GraphQL schema changelog is a list of recent and upcoming changes',
)
// Check for manual content
expect(res.body).toContain(
'Breaking changes include changes that will break existing queries',
)
// Index page shows latest year (2026) entries only
expect(res.body).toContain('## Schema changes for 2026-')
// Check for change items
expect(res.body).toContain('### The GraphQL schema includes these changes:')
// Should NOT contain entries from other years
expect(res.body).not.toContain('## Schema changes for 2025-')
// Check for year navigation
expect(res.body).toContain('2026')
expect(res.body).toContain('2025')
})
test('changelog year page renders with that year only', async () => {
const res = await getCached('/en/graphql/overview/changelog/2025')
expect(res.statusCode).toBe(200)
// Check for year-specific heading
expect(res.body).toContain('# GraphQL changelog for 2025')
// Check for date-based changelog sections from 2025
expect(res.body).toContain('## Schema changes for 2025-')
// Should NOT contain entries from other years
expect(res.body).not.toContain('## Schema changes for 2026-')
expect(res.body).not.toContain('## Schema changes for 2024-')
})
test('changelog removes HTML tags from changes', async () => {
// Use a year page that has the specific test data
const res = await getCached('/en/graphql/overview/changelog/2025')
expect(res.statusCode).toBe(200)
// Check that HTML tags are removed
expect(res.body).toContain('Field suggestedReviewerActors was added')
expect(res.body).not.toContain('<code>')
expect(res.body).not.toContain('</code>')
expect(res.body).not.toContain('<p>')
expect(res.body).not.toContain('</p>')
})
test('breaking changes page renders with scheduled changes', async () => {
const res = await getCached('/en/graphql/overview/breaking-changes')
expect(res.statusCode).toBe(200)
// Check for main heading
expect(res.body).toContain('# Breaking changes')
// Check for intro
expect(res.body).toContain('Learn about recent and upcoming breaking changes')
// Check for manual content
expect(res.body).toContain('## About breaking changes')
expect(res.body).toContain('Breaking:** Changes that will break existing queries')
// Check for date-based sections
expect(res.body).toContain('## Changes scheduled for 2025-04-01')
expect(res.body).toContain('## Changes scheduled for 2026-04-01')
})
test('breaking changes shows criticality levels', async () => {
const res = await getCached('/en/graphql/overview/breaking-changes')
expect(res.statusCode).toBe(200)
// Check for breaking criticality
expect(res.body).toMatch(/\*\*Breaking\*\*\s+A change will be made to `\w+\.\w+`\./)
expect(res.body).toMatch(/\*\*Description:\*\*.*will be removed/)
expect(res.body).toMatch(/\*\*Reason:\*\*/)
})
test('breaking changes removes HTML tags', async () => {
const res = await getCached('/en/graphql/overview/breaking-changes')
expect(res.statusCode).toBe(200)
expect(res.body).toContain('scheduled for')
// Check that HTML tags are removed from descriptions
expect(res.body).not.toContain('<p>')
expect(res.body).not.toContain('</p>')
expect(res.body).not.toContain('<code>')
expect(res.body).not.toContain('</code>')
expect(res.body).not.toContain('<p>')
expect(res.body).not.toContain('</p>')
})
})
describe('Liquid tags', () => {
test('AUTOTITLE links are resolved in manual content', async () => {
const res = await getCached('/en/graphql/reference/queries')
expect(res.statusCode).toBe(200)
// Check that AUTOTITLE has been resolved
expect(res.body).toMatch(/(Forming calls with GraphQL|Hello World)/)
// Make sure the raw AUTOTITLE tag is not present
expect(res.body).not.toContain('[AUTOTITLE]')
})
test('Liquid variables are rendered in intro', async () => {
const res = await getCached('/en/graphql/reference')
expect(res.statusCode).toBe(200)
// Liquid variables should be rendered
expect(res.body).toMatch(/(GitHub|HubGit) GraphQL API schema/)
expect(res.body).not.toContain('{% data variables.product.prodname_dotcom %}')
})
test('Liquid variables are rendered in breaking changes', async () => {
const res = await getCached('/en/graphql/overview/breaking-changes')
expect(res.statusCode).toBe(200)
// Check that liquid variables in intro are rendered
expect(res.body).toMatch(/(GitHub|HubGit) GraphQL API/)
expect(res.body).not.toContain('{% data variables.product.prodname_dotcom %}')
})
})
describe('Multiple items', () => {
test('multiple queries are all rendered', async () => {
const res = await getCached('/en/graphql/reference/queries')
expect(res.statusCode).toBe(200)
// Check for multiple query headings
expect(res.body).toContain('## repository')
expect(res.body).toContain('## viewer')
})
test('multiple objects are all rendered', async () => {
const res = await getCached('/en/graphql/reference/objects')
expect(res.statusCode).toBe(200)
// Check for multiple object headings
expect(res.body).toContain('## Repository')
expect(res.body).toContain('## User')
})
test('multiple enums are all rendered', async () => {
const res = await getCached('/en/graphql/reference/enums')
expect(res.statusCode).toBe(200)
// Check for multiple enum headings
expect(res.body).toContain('## RepositoryVisibility')
expect(res.body).toContain('## OrderDirection')
})
})
})