Skip to content

Commit 827f3d5

Browse files
author
Token Goat Test
committed
fix: TYPE_KINDS omitted graphql_extend, so every extend type/interface/... was invisible to token-goat types
1 parent 66d8442 commit 827f3d5

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/graph_commands.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,16 @@ const TYPE_KINDS: ReadonlyArray<string> = [
701701
// mixin/extension, proto message/enum/service, Apex class/interface/enum, GraphQL
702702
// type/interface/input/enum/union, and Kotlin/Scala object.
703703
'sfc_script_class',
704+
// languages/graphql_idx.ts's TYPE_RE handler maps EVERY `extend type|interface|input|enum|
705+
// union|scalar Foo { ... }` declaration to this one shared kind regardless of which keyword
706+
// follows `extend` -- GraphQL's mechanism for adding fields to a type from another file/module,
707+
// ubiquitous in federation and schema-stitching -- but unlike the six non-extend KIND_MAP
708+
// entries already listed above, this kind was never added here, so every `extend` declaration
709+
// was indexed but silently excluded from `token-goat types` in its entirety, the same class of
710+
// gap already fixed for the other six GraphQL kinds, Rust union, Swift protocol/actor, Zig
711+
// opaque, Dart mixin/extension, proto message/enum/service, Apex class/interface/enum, and
712+
// Kotlin/Scala object.
713+
'graphql_extend',
704714
]
705715

706716
export interface TypesOptions {

tests/graph_commands.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,45 @@ describe('runTypes integration', () => {
955955
}
956956
})
957957

958+
// Regression: TYPE_KINDS never included 'graphql_extend'. languages/graphql_idx.ts's TYPE_RE
959+
// handler maps EVERY `extend type|interface|input|enum|union|scalar Foo { ... }` declaration
960+
// (GraphQL's mechanism for adding fields to a type from another file/module, ubiquitous in
961+
// federation and schema-stitching) to this one shared kind regardless of which keyword follows
962+
// `extend` -- but unlike the six non-extend KIND_MAP entries above (all already fixed), this
963+
// kind was never added to TYPE_KINDS, so every `extend` declaration was indexed but silently
964+
// excluded from `token-goat types` in its entirety -- the same class of gap already fixed for
965+
// the other six GraphQL kinds, Rust union, Swift protocol/actor, Zig opaque, Dart mixin/
966+
// extension, proto message/enum/service, Apex class/interface/enum, and Kotlin/Scala 'object'.
967+
it("surfaces GraphQL 'extend' declarations via TYPE_KINDS, matching the other GraphQL kinds", () => {
968+
const dir = mkdtempSync(join(process.cwd(), 'tg-types-graphql-extend-'))
969+
try {
970+
const file = join(dir, 'fixture.graphql')
971+
writeFileSync(
972+
file,
973+
['extend type TypesGraphqlExtendFixture {', ' extraField: String', '}', ''].join('\n'),
974+
)
975+
indexFileSync(normalizePath(file))
976+
977+
let captured = ''
978+
const origWrite = process.stdout.write.bind(process.stdout)
979+
process.stdout.write = (chunk: string | Uint8Array, ...rest: unknown[]): boolean => {
980+
if (typeof chunk === 'string') captured += chunk
981+
return origWrite(chunk, ...(rest as Parameters<typeof origWrite>))
982+
}
983+
try {
984+
const code = runTypes({ file: normalizePath(file), json: true })
985+
expect(code).toBe(0)
986+
} finally {
987+
process.stdout.write = origWrite
988+
}
989+
const parsed = JSON.parse(captured) as Array<{ name: string; kind: string }>
990+
expect(parsed.map((r) => r.name)).toContain('TypesGraphqlExtendFixture')
991+
expect(parsed.find((r) => r.name === 'TypesGraphqlExtendFixture')?.kind).toBe('graphql_extend')
992+
} finally {
993+
rmSync(dir, { recursive: true, force: true })
994+
}
995+
})
996+
958997
// Regression: TYPE_KINDS never included 'sfc_script_class'. languages/sfc_idx.ts (Vue/Svelte/
959998
// Astro single-file components) emits this distinct kind for a top-level `class Foo { ... }`
960999
// declaration in a component's script block rather than the generic 'class', so unlike a plain

0 commit comments

Comments
 (0)