MCPcopy Create free account
hub / github.com/47ng/nuqs / fetchDiscussionNodes

Function fetchDiscussionNodes

packages/scripts/lib/commit-graph.ts:424–477  ·  view source on GitHub ↗
(
  numbers: number[],
  githubToken: string
)

Source from the content-addressed store, hash-verified

422// token/scope failure that nulls *every* alias, not a per-candidate skip — and
423// silently returning `[]` would drop the whole feature on a green run.
424export async function fetchDiscussionNodes(
425 numbers: number[],
426 githubToken: string
427): Promise<Discussion[]> {
428 if (numbers.length === 0) return []
429 const aliases = numbers
430 .map(number => `d${number}: discussion(number: ${number}) { number id }`)
431 .join('\n')
432 const query = `query { repository(owner: "47ng", name: "nuqs") { ${aliases} } }`
433 const response = await fetch(
434 'https://api.github.com/graphql?fn=fetchDiscussions',
435 {
436 method: 'POST',
437 headers: {
438 Authorization: `Bearer ${githubToken}`,
439 'Content-Type': 'application/json'
440 },
441 body: JSON.stringify({ query })
442 }
443 )
444 if (!response.ok) {
445 throw new Error(
446 `fetchDiscussions: GitHub API error ${response.status} ${response.statusText} for [${numbers.join(', ')}]`
447 )
448 }
449 const envelopeSchema = z.object({
450 data: z
451 .object({
452 repository: z.record(z.string(), discussionSchema.nullable()).nullable()
453 })
454 .nullable(),
455 errors: z
456 .array(z.object({ type: z.string().optional(), message: z.string() }))
457 .optional()
458 })
459 const envelope = envelopeSchema.safeParse(await response.json())
460 if (!envelope.success) {
461 throw new Error(
462 `fetchDiscussions: unexpected GraphQL response shape for [${numbers.join(', ')}]: ${envelope.error.message}`
463 )
464 }
465 const { data, errors } = envelope.data
466 const fatal = (errors ?? []).filter(({ type }) => type !== 'NOT_FOUND')
467 if (fatal.length > 0) {
468 throw new Error(
469 `fetchDiscussions: GraphQL errors for [${numbers.join(', ')}]: ${fatal
470 .map(error => error.message)
471 .join('; ')}`
472 )
473 }
474 return Object.values(data?.repository ?? {}).filter(
475 (node): node is Discussion => node !== null
476 )
477}
478
479// The closing-issues facet shared by `PR` and `PRClosingIssues`, so
480// `collectIssues` serves both discovery paths from the same field.

Callers 2

makeGitHubGraphReaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected