From 067e1f666a71e56fe9f23b2342be8f7e89a19b9a Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Thu, 25 Apr 2024 21:01:36 +1000 Subject: [PATCH 1/4] Make RefType optional to avoid TS compiler error with certain config options --- .../visitor-plugin-common/src/base-resolvers-visitor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts b/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts index 2d20fe39a56..5ace0b3de5d 100644 --- a/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts +++ b/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts @@ -1040,7 +1040,7 @@ export class BaseResolversVisitor< // - If there are fields to Omit, keep track of these "type with maybe Omit" to replace in original unionMemberValue const fieldsToOmit = this.getRelevantFieldsToOmit({ schemaType: type, - getTypeToUse: baseType => `RefType['${baseType}']`, + getTypeToUse: baseType => `_RefType['${baseType}']`, }); if (fieldsToOmit.length > 0) { typeValue = this.replaceFieldsInType(typeValue, fieldsToOmit); @@ -1147,7 +1147,7 @@ export class BaseResolversVisitor< return new DeclarationBlock(this._declarationBlockConfig) .export() .asKind(declarationKind) - .withName(this.convertName('ResolversUnionTypes'), `>`) + .withName(this.convertName('ResolversUnionTypes'), `<_RefType extends Record>`) .withComment('Mapping of union types') .withBlock( Object.entries(this._resolversUnionTypes) @@ -1165,7 +1165,7 @@ export class BaseResolversVisitor< return new DeclarationBlock(this._declarationBlockConfig) .export() .asKind(declarationKind) - .withName(this.convertName('ResolversInterfaceTypes'), `>`) + .withName(this.convertName('ResolversInterfaceTypes'), `<_RefType extends Record>`) .withComment('Mapping of interface types') .withBlock( Object.entries(this._resolversInterfaceTypes) From 9396dec58929da8ec169a62cfb53124aff5297f1 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Thu, 25 Apr 2024 21:07:23 +1000 Subject: [PATCH 2/4] Update tests --- .../__snapshots__/ts-resolvers.spec.ts.snap | 36 ++-- .../resolvers/tests/mapping.spec.ts | 178 +++++++++--------- .../resolvers/tests/ts-resolvers.spec.ts | 92 ++++----- 3 files changed, 153 insertions(+), 153 deletions(-) diff --git a/packages/plugins/typescript/resolvers/tests/__snapshots__/ts-resolvers.spec.ts.snap b/packages/plugins/typescript/resolvers/tests/__snapshots__/ts-resolvers.spec.ts.snap index f2ab6d709f2..bb357dc74ef 100644 --- a/packages/plugins/typescript/resolvers/tests/__snapshots__/ts-resolvers.spec.ts.snap +++ b/packages/plugins/typescript/resolvers/tests/__snapshots__/ts-resolvers.spec.ts.snap @@ -167,17 +167,17 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping of union types */ -export type ResolversUnionTypes> = ResolversObject<{ +export type ResolversUnionTypes<_RefType extends Record> = ResolversObject<{ ChildUnion: ( Child ) | ( MyOtherType ); - MyUnion: ( Omit & { unionChild?: Maybe } ) | ( MyOtherType ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( MyOtherType ); }>; /** Mapping of interface types */ -export type ResolversInterfaceTypes> = ResolversObject<{ +export type ResolversInterfaceTypes<_RefType extends Record> = ResolversObject<{ Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }>; /** Mapping between all available schema types and the resolvers types */ @@ -426,17 +426,17 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping of union types */ -export type ResolversUnionTypes> = ResolversObject<{ +export type ResolversUnionTypes<_RefType extends Record> = ResolversObject<{ ChildUnion: ( Types.Child ) | ( Types.MyOtherType ); - MyUnion: ( Omit & { unionChild?: Types.Maybe } ) | ( Types.MyOtherType ); + MyUnion: ( Omit & { unionChild?: Types.Maybe<_RefType['ChildUnion']> } ) | ( Types.MyOtherType ); }>; /** Mapping of interface types */ -export type ResolversInterfaceTypes> = ResolversObject<{ +export type ResolversInterfaceTypes<_RefType extends Record> = ResolversObject<{ Node: ( Types.SomeNode ); - AnotherNode: ( Omit & { unionChild?: Types.Maybe } ) | ( Omit & { unionChild?: Types.Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Types.Maybe } ) | ( Omit & { unionChild?: Types.Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Types.Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Types.Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Types.Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Types.Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Types.Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Types.Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }>; /** Mapping between all available schema types and the resolvers types */ @@ -771,17 +771,17 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping of union types */ -export type ResolversUnionTypes> = ResolversObject<{ +export type ResolversUnionTypes<_RefType extends Record> = ResolversObject<{ ChildUnion: ( Child ) | ( MyOtherType ); - MyUnion: ( Omit & { unionChild?: Maybe } ) | ( MyOtherType ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( MyOtherType ); }>; /** Mapping of interface types */ -export type ResolversInterfaceTypes> = ResolversObject<{ +export type ResolversInterfaceTypes<_RefType extends Record> = ResolversObject<{ Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }>; /** Mapping between all available schema types and the resolvers types */ diff --git a/packages/plugins/typescript/resolvers/tests/mapping.spec.ts b/packages/plugins/typescript/resolvers/tests/mapping.spec.ts index ec9d5ba7bbf..67b46f4717d 100644 --- a/packages/plugins/typescript/resolvers/tests/mapping.spec.ts +++ b/packages/plugins/typescript/resolvers/tests/mapping.spec.ts @@ -8,17 +8,17 @@ describe('ResolversTypes', () => { const result = await plugin(resolversTestingSchema, [], {}, { outputFile: '' }); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Child ) | ( MyOtherType ); - MyUnion: ( Omit & { unionChild?: Maybe } ) | ( MyOtherType ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( MyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -84,17 +84,17 @@ describe('ResolversTypes', () => { )) as Types.ComplexPluginOutput; expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { bar: RefType['String'], parent?: Maybe } ) | ( Omit & { bar: RefType['String'] } ); - MyUnion: ( MyTypeDb ) | ( Omit & { bar: RefType['String'] } ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { bar: _RefType['String'], parent?: Maybe<_RefType['MyType']> } ) | ( Omit & { bar: _RefType['String'] } ); + MyUnion: ( MyTypeDb ) | ( Omit & { bar: _RefType['String'] } ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -178,7 +178,7 @@ describe('ResolversTypes', () => { const content = mergeOutputs([result]); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { MovieLike: ( MovieEntity ) | ( Book ); }; `); @@ -248,7 +248,7 @@ describe('ResolversTypes', () => { const content = mergeOutputs([result]); expect(content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { MovieLike: ( MovieEntity ) | ( Book ); }; `); @@ -391,17 +391,17 @@ describe('ResolversTypes', () => { )) as Types.ComplexPluginOutput; expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Partial ) | ( Partial ); - MyUnion: ( Partial & { unionChild?: Maybe }> ) | ( Partial ); + MyUnion: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Partial ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( Partial ); - AnotherNode: ( Partial & { unionChild?: Maybe }> ) | ( Partial & { unionChild?: Maybe, unionChildren: Array }> ); - WithChild: ( Partial & { unionChild?: Maybe }> ) | ( Partial & { unionChild?: Maybe, unionChildren: Array }> ); - WithChildren: ( Partial & { unionChild?: Maybe, unionChildren: Array }> ); + AnotherNode: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); + WithChild: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); + WithChildren: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -464,17 +464,17 @@ describe('ResolversTypes', () => { expect(result.prepend).toContain(`import { CustomPartial } from './my-wrapper';`); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( CustomPartial ) | ( CustomPartial ); - MyUnion: ( CustomPartial & { unionChild?: Maybe }> ) | ( CustomPartial ); + MyUnion: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( CustomPartial ); } `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( CustomPartial ); - AnotherNode: ( CustomPartial & { unionChild?: Maybe }> ) | ( CustomPartial & { unionChild?: Maybe, unionChildren: Array }> ); - WithChild: ( CustomPartial & { unionChild?: Maybe }> ) | ( CustomPartial & { unionChild?: Maybe, unionChildren: Array }> ); - WithChildren: ( CustomPartial & { unionChild?: Maybe, unionChildren: Array }> ); + AnotherNode: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); + WithChild: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); + WithChildren: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -540,17 +540,17 @@ describe('ResolversTypes', () => { expect(result.prepend).toContain(`import { CustomPartial } from './my-wrapper';`); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( MyOtherType ); - MyUnion: ( CustomPartial & { unionChild?: Maybe }> ) | ( MyOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( MyOtherType ); + MyUnion: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( MyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( CustomPartial & { unionChild?: Maybe }> ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( CustomPartial & { unionChild?: Maybe }> ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( CustomPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -692,17 +692,17 @@ describe('ResolversTypes', () => { `import { AnotherNodeWithChild as AnotherNodeWithChildMapper } from './my-interface';` ); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( MyOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( MyOtherType ); MyUnion: ( DatabaseMyType ) | ( MyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -770,13 +770,13 @@ describe('ResolversTypes', () => { expect(result.prepend).toContain(`import DatabaseMyOtherType, { MyType as DatabaseMyType } from './my-type';`); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( DatabaseMyOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( DatabaseMyOtherType ); MyUnion: ( DatabaseMyType ) | ( DatabaseMyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); AnotherNode: ( AnotherNodeWithChildMapper ) | ( AnotherNodeWithAllMapper ); WithChild: ( AnotherNodeWithChildMapper ) | ( AnotherNodeWithAllMapper ); @@ -854,13 +854,13 @@ describe('ResolversTypes', () => { `import type { default as AnotherNodeWithChildMapper, AnotherNodeWithAll as AnotherNodeWithAllMapper } from './my-interface';` ); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( DatabaseMyOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( DatabaseMyOtherType ); MyUnion: ( DatabaseMyType ) | ( DatabaseMyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); AnotherNode: ( AnotherNodeWithChildMapper ) | ( AnotherNodeWithAllMapper ); WithChild: ( AnotherNodeWithChildMapper ) | ( AnotherNodeWithAllMapper ); @@ -994,13 +994,13 @@ describe('ResolversTypes', () => { )) as Types.ComplexPluginOutput; expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( CustomMyOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( CustomMyOtherType ); MyUnion: ( MyTypeDb ) | ( CustomMyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); AnotherNode: ( AnotherNodeWithChildMapper ) | ( AnotherNodeWithAllMapper ); WithChild: ( AnotherNodeWithChildMapper ) | ( AnotherNodeWithAllMapper ); @@ -1069,17 +1069,17 @@ describe('ResolversTypes', () => { )) as Types.ComplexPluginOutput; expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( MyOtherType ); - MyUnion: ( Partial & { unionChild?: Maybe }> ) | ( MyOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( MyOtherType ); + MyUnion: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( MyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( ExtraPartial & { unionChild?: Maybe }> ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( ExtraPartial & { unionChild?: Maybe }> ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( ExtraPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( ExtraPartial & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -1608,17 +1608,17 @@ describe('ResolversTypes', () => { )) as Types.ComplexPluginOutput; expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( MyOtherTypeCustom ); - MyUnion: ( Omit & { otherType?: Maybe, unionChild?: Maybe } ) | ( MyOtherTypeCustom ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( MyOtherTypeCustom ); + MyUnion: ( Omit & { otherType?: Maybe<_RefType['MyOtherType']>, unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( MyOtherTypeCustom ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -1684,17 +1684,17 @@ describe('ResolversTypes', () => { )) as Types.ComplexPluginOutput; expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( MyOtherTypeCustom ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( MyOtherTypeCustom ); MyUnion: ( MyTypeCustom ) | ( MyOtherTypeCustom ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -1762,17 +1762,17 @@ describe('ResolversTypes', () => { expect(result.prepend).toContain(`import { MyNamespace } from './my-file';`); expect(result.prepend).toContain(`import { InterfaceNamespace } from './my-interface';`); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( Omit & { parent?: Maybe } ) | ( MyNamespace.MyCustomOtherType ); - MyUnion: ( Omit & { otherType?: Maybe, unionChild?: Maybe } ) | ( MyNamespace.MyCustomOtherType ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Omit & { parent?: Maybe<_RefType['MyType']> } ) | ( MyNamespace.MyCustomOtherType ); + MyUnion: ( Omit & { otherType?: Maybe<_RefType['MyOtherType']>, unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( MyNamespace.MyCustomOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( InterfaceNamespace.AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( InterfaceNamespace.AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( InterfaceNamespace.AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( InterfaceNamespace.AnotherNodeWithChildMapper ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -1918,17 +1918,17 @@ describe('ResolversTypes', () => { expect(result.prepend).toContain(`import { MyNamespace } from './my-file';`); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Child ) | ( MyOtherType ); - MyUnion: ( Omit & { unionChild?: Maybe } ) | ( MyOtherType ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( MyOtherType ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); expect(result.content).toBeSimilarStringTo(` @@ -1996,17 +1996,17 @@ describe('ResolversTypes', () => { expect(result.prepend).toContain(`import { MyNamespace } from './my-file';`); expect(result.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { - ChildUnion: ( MyNamespace.MyDefaultMapper & { parent?: Maybe }> ) | ( MyNamespace.MyDefaultMapper ); - MyUnion: ( MyNamespace.MyType & { unionChild?: Maybe }> ) | ( MyNamespace.MyDefaultMapper ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( MyNamespace.MyDefaultMapper & { parent?: Maybe<_RefType['MyType']> }> ) | ( MyNamespace.MyDefaultMapper ); + MyUnion: ( MyNamespace.MyType & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( MyNamespace.MyDefaultMapper ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( MyNamespace.MyDefaultMapper ); - AnotherNode: ( InterfaceNamespace.MyInterface & { unionChild?: Maybe }> ) | ( MyNamespace.MyDefaultMapper & { unionChild?: Maybe, unionChildren: Array }> ); - WithChild: ( InterfaceNamespace.MyInterface & { unionChild?: Maybe }> ) | ( MyNamespace.MyDefaultMapper & { unionChild?: Maybe, unionChildren: Array }> ); - WithChildren: ( MyNamespace.MyDefaultMapper & { unionChild?: Maybe, unionChildren: Array }> ); + AnotherNode: ( InterfaceNamespace.MyInterface & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( MyNamespace.MyDefaultMapper & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); + WithChild: ( InterfaceNamespace.MyInterface & { unionChild?: Maybe<_RefType['ChildUnion']> }> ) | ( MyNamespace.MyDefaultMapper & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); + WithChildren: ( MyNamespace.MyDefaultMapper & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> ); }; `); expect(result.content).toBeSimilarStringTo(` diff --git a/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts b/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts index c557bad7b97..73a1b71ccd8 100644 --- a/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts +++ b/packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts @@ -234,17 +234,17 @@ export type MyTypeResolvers> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Child & { __typename: 'Child' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); - MyUnion: ( Omit & { unionChild?: Maybe } & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode & { __typename: 'SomeNode' } ); - AnotherNode: ( Omit & { unionChild?: Maybe } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChild: ( Omit & { unionChild?: Maybe } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); }; `); }); @@ -258,9 +258,9 @@ export type MyTypeResolvers> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Child & { __typename: 'Child' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); - MyUnion: ( Omit & { unionChild?: Maybe } & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); }; `); }); @@ -277,7 +277,7 @@ export type MyTypeResolvers> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( ChildMapper & { __typename: 'Child' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); MyUnion: ( MyTypeMapper & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); }; @@ -296,9 +296,9 @@ export type MyTypeResolvers> = { - ChildUnion: ( Wrapper & { parent?: Maybe }> & { __typename: 'Child' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); - MyUnion: ( MyWrapper & { unionChild?: Maybe }> & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); + export type ResolversUnionTypes<_RefType extends Record> = { + ChildUnion: ( Wrapper & { parent?: Maybe<_RefType['MyType']> }> & { __typename: 'Child' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); + MyUnion: ( MyWrapper & { unionChild?: Maybe<_RefType['ChildUnion']> }> & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); }; `); }); @@ -315,9 +315,9 @@ export type MyTypeResolvers> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Partial & { __typename: 'Child' } ) | ( Partial & { __typename: 'MyOtherType' } ); - MyUnion: ( Partial & { unionChild?: Maybe }> & { __typename: 'MyType' } ) | ( Partial & { __typename: 'MyOtherType' } ); + MyUnion: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> & { __typename: 'MyType' } ) | ( Partial & { __typename: 'MyOtherType' } ); }; `); }); @@ -346,11 +346,11 @@ export type MyTypeResolvers> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode & { __typename: 'SomeNode' } ); - AnotherNode: ( Omit & { unionChild?: Maybe } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChild: ( Omit & { unionChild?: Maybe } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); }; `); }); @@ -367,11 +367,11 @@ export type MyTypeResolvers> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode & { __typename: 'SomeNode' } ); - AnotherNode: ( AnotherNodeWithChildMapper & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChild: ( AnotherNodeWithChildMapper & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); + AnotherNode: ( AnotherNodeWithChildMapper & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChild: ( AnotherNodeWithChildMapper & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); }; `); }); @@ -388,11 +388,11 @@ export type MyTypeResolvers> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode & { __typename: 'SomeNode' } ); - AnotherNode: ( Wrapper & { unionChild?: Maybe }> & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChild: ( Wrapper & { unionChild?: Maybe }> & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); + AnotherNode: ( Wrapper & { unionChild?: Maybe<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChild: ( Wrapper & { unionChild?: Maybe<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); }; `); }); @@ -409,11 +409,11 @@ export type MyTypeResolvers> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( Partial & { __typename: 'SomeNode' } ); - AnotherNode: ( Partial & { unionChild?: Maybe }> & { __typename: 'AnotherNodeWithChild' } ) | ( Partial & { unionChild?: Maybe, unionChildren: Array }> & { __typename: 'AnotherNodeWithAll' } ); - WithChild: ( Partial & { unionChild?: Maybe }> & { __typename: 'AnotherNodeWithChild' } ) | ( Partial & { unionChild?: Maybe, unionChildren: Array }> & { __typename: 'AnotherNodeWithAll' } ); - WithChildren: ( Partial & { unionChild?: Maybe, unionChildren: Array }> & { __typename: 'AnotherNodeWithAll' } ); + AnotherNode: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithChild' } ) | ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithAll' } ); + WithChild: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithChild' } ) | ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithAll' } ); + WithChildren: ( Partial & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> }> & { __typename: 'AnotherNodeWithAll' } ); }; `); }); @@ -447,18 +447,18 @@ export type MyTypeResolvers> = { + export type ResolversUnionTypes<_RefType extends Record> = { ChildUnion: ( Child ) | ( MyOtherType ); - MyUnion: ( Omit & { unionChild?: Maybe } & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); + MyUnion: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'MyType' } ) | ( MyOtherType & { __typename: 'MyOtherType' } ); }; `); expect(result.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } & { __typename: 'AnotherNodeWithAll' } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithChild' } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } & { __typename: 'AnotherNodeWithAll' } ); }; `); }); @@ -1681,7 +1681,7 @@ export type ResolverFn = ( `); expect(content.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { CCCUnion: ( CccFoo ) | ( CccBar ); }; `); @@ -2032,7 +2032,7 @@ export type ResolverFn = ( const content = await plugin(testSchema, [], {}, { outputFile: 'graphql.ts' }); expect(content.content).toBeSimilarStringTo(` - export type ResolversUnionTypes> = { + export type ResolversUnionTypes<_RefType extends Record> = { UserPayload: ( UserResult ) | ( StandardError ); PostsPayload: ( PostsResult ) | ( StandardError ); }; @@ -2092,11 +2092,11 @@ export type ResolverFn = ( const content = await plugin(resolversTestingSchema, [], {}, { outputFile: 'graphql.ts' }); expect(content.content).toBeSimilarStringTo(` - export type ResolversInterfaceTypes> = { + export type ResolversInterfaceTypes<_RefType extends Record> = { Node: ( SomeNode ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); @@ -2158,11 +2158,11 @@ export type ResolverFn = ( ); expect(content.content).toBeSimilarStringTo(` - export type I_ResolversInterfaceTypes_Types> = { + export type I_ResolversInterfaceTypes_Types<_RefType extends Record> = { Node: ( I_SomeNode_Types ); - AnotherNode: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChild: ( Omit & { unionChild?: Maybe } ) | ( Omit & { unionChild?: Maybe, unionChildren: Array } ); - WithChildren: ( Omit & { unionChild?: Maybe, unionChildren: Array } ); + AnotherNode: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChild: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']> } ) | ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); + WithChildren: ( Omit & { unionChild?: Maybe<_RefType['ChildUnion']>, unionChildren: Array<_RefType['ChildUnion']> } ); }; `); From 7d80ada2b2663ea1301c6752ede2460940367269 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Thu, 25 Apr 2024 21:45:49 +1000 Subject: [PATCH 3/4] Add changeset --- .changeset/gentle-ladybugs-speak.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/gentle-ladybugs-speak.md diff --git a/.changeset/gentle-ladybugs-speak.md b/.changeset/gentle-ladybugs-speak.md new file mode 100644 index 00000000000..26e0501839d --- /dev/null +++ b/.changeset/gentle-ladybugs-speak.md @@ -0,0 +1,6 @@ +--- +'@graphql-codegen/visitor-plugin-common': patch +'@graphql-codegen/typescript-resolvers': patch +--- + +Add \_ prefix to generated `RefType` in `ResolversInterfaceTypes` and `ResolversUnionTypes` as it is sometimes unused From 1ac284ac51b27d312ef3f9922218f228a3b468e3 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Thu, 25 Apr 2024 21:53:18 +1000 Subject: [PATCH 4/4] Update dev-tests --- dev-test/modules/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-test/modules/types.ts b/dev-test/modules/types.ts index 893f0c452f1..af996e8e275 100644 --- a/dev-test/modules/types.ts +++ b/dev-test/modules/types.ts @@ -165,7 +165,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping of union types */ -export type ResolversUnionTypes> = { +export type ResolversUnionTypes<_RefType extends Record> = { PaymentOption: CreditCard | Paypal; };