Skip to content

Commit

Permalink
fix(ts-client): no infer runtime unions
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Apr 14, 2024
1 parent 310f10c commit 893ad01
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/generator/__snapshots__/files.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }, [
Expand Down
5 changes: 4 additions & 1 deletion src/generator/code/schemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 6 additions & 0 deletions tests/ts/_/schema/generated/SchemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) }, [
Expand Down

0 comments on commit 893ad01

Please sign in to comment.