Skip to content

Commit dcb38cf

Browse files
committed
fix: bug in TS when query has no variables
1 parent ef3c26e commit dcb38cf

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/internal/graphqlTypegenCore.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export default function graphqlTypegenCore(
7373
if (file.endsWith('.ts')) j = j.withParser('ts')
7474
else if (file.endsWith('.tsx')) j = j.withParser('tsx')
7575

76+
const emptyObjectType = () =>
77+
isTS ? j.tsTypeLiteral([]) : j.objectTypeAnnotation([])
78+
7679
const root = j(code)
7780
const { statement } = j.template
7881

@@ -185,7 +188,7 @@ export default function graphqlTypegenCore(
185188
params.push(
186189
variables
187190
? genericTypeAnnotation(j.identifier(variables.id.name), null)
188-
: j.objectTypeAnnotation([])
191+
: emptyObjectType()
189192
)
190193
return typeParameterInstantiation(params)
191194
}
@@ -219,7 +222,7 @@ export default function graphqlTypegenCore(
219222
genericTypeAnnotation(j.identifier(data.id.name), null),
220223
variables
221224
? genericTypeAnnotation(j.identifier(variables.id.name), null)
222-
: j.objectTypeAnnotation([]),
225+
: emptyObjectType(),
223226
])
224227
)
225228
)
@@ -247,7 +250,7 @@ export default function graphqlTypegenCore(
247250
genericTypeAnnotation(j.identifier(data.id.name), null),
248251
variables
249252
? genericTypeAnnotation(j.identifier(variables.id.name), null)
250-
: j.objectTypeAnnotation([]),
253+
: emptyObjectType(),
251254
])
252255
)
253256
)

0 commit comments

Comments
 (0)