From 893ad01ea3e84344054f73e24f36c61403585f09 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Sun, 14 Apr 2024 17:59:19 -0400 Subject: [PATCH] fix(ts-client): no infer runtime unions --- src/generator/__snapshots__/files.test.ts.snap | 6 ++++++ src/generator/code/schemaRuntime.ts | 5 ++++- tests/ts/_/schema/generated/SchemaRuntime.ts | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/generator/__snapshots__/files.test.ts.snap b/src/generator/__snapshots__/files.test.ts.snap index 90d64808c..a99b69969 100644 --- a/src/generator/__snapshots__/files.test.ts.snap +++ b/src/generator/__snapshots__/files.test.ts.snap @@ -392,10 +392,16 @@ export const Object2ImplementingInterface = $.Object$(\`Object2ImplementingInter boolean: $.field($.Output.Nullable($Scalar.Boolean)), }) +// eslint-disable-next-line +// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. export const DateUnion = $.Union(\`DateUnion\`, [DateObject1, DateObject2]) +// eslint-disable-next-line +// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. export const FooBarUnion = $.Union(\`FooBarUnion\`, [Foo, Bar]) +// eslint-disable-next-line +// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. export const lowerCaseUnion = $.Union(\`lowerCaseUnion\`, [lowerCaseObject, lowerCaseObject2]) export const DateInterface1 = $.Interface(\`DateInterface1\`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [ diff --git a/src/generator/code/schemaRuntime.ts b/src/generator/code/schemaRuntime.ts index 71fd9258b..ee4f25523 100644 --- a/src/generator/code/schemaRuntime.ts +++ b/src/generator/code/schemaRuntime.ts @@ -72,7 +72,10 @@ const index = (config: Config) => { const union = (config: Config, type: GraphQLUnionType) => { // todo probably need thunks here const members = type.getTypes().map(t => t.name).join(`, `) - return `export const ${type.name} = $.Union(\`${type.name}\`, [${members}])\n` + return ` + // eslint-disable-next-line + // @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. + export const ${type.name} = $.Union(\`${type.name}\`, [${members}])\n` } const interface$ = (config: Config, type: GraphQLInterfaceType) => { diff --git a/tests/ts/_/schema/generated/SchemaRuntime.ts b/tests/ts/_/schema/generated/SchemaRuntime.ts index 882d58410..a2300614e 100644 --- a/tests/ts/_/schema/generated/SchemaRuntime.ts +++ b/tests/ts/_/schema/generated/SchemaRuntime.ts @@ -91,10 +91,16 @@ export const Object2ImplementingInterface = $.Object$(`Object2ImplementingInterf boolean: $.field($.Output.Nullable($Scalar.Boolean)), }) +// eslint-disable-next-line +// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. export const DateUnion = $.Union(`DateUnion`, [DateObject1, DateObject2]) +// eslint-disable-next-line +// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. export const FooBarUnion = $.Union(`FooBarUnion`, [Foo, Bar]) +// eslint-disable-next-line +// @ts-ignore - circular types cannot infer. Ignore in case there are any. This comment is always added, it does not indicate if this particular type could infer or not. export const lowerCaseUnion = $.Union(`lowerCaseUnion`, [lowerCaseObject, lowerCaseObject2]) export const DateInterface1 = $.Interface(`DateInterface1`, { date1: $.field($.Output.Nullable($Scalar.Date)) }, [