Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use globalThis with Record #9462

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slow-penguins-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-resolvers': patch
---

Use `globalThis` for `Record` in case of conflict
2 changes: 1 addition & 1 deletion dev-test/modules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
) => TResult | Promise<TResult>;

/** Mapping of union types */
export type ResolversUnionTypes<RefType extends Record<string, unknown>> = {
export type ResolversUnionTypes<RefType extends globalThis.Record<string, unknown>> = {
PaymentOption: CreditCard | Paypal;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/other/visitor-plugin-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
The generated types will look like this:

```ts
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = {
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = {
CharacterNode: Fighter | Wizard;
};

Expand Down Expand Up @@ -318,7 +318,7 @@
Then, the generated type looks like this:

```ts
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = {
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = {
CharacterNode: (Fighter & { __typename: 'Fighter' }) | (Wizard & { __typename: 'Wizard' });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ export class BaseResolversVisitor<
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind(declarationKind)
.withName(this.convertName('ResolversUnionTypes'), `<RefType extends Record<string, unknown>>`)
.withName(this.convertName('ResolversUnionTypes'), `<RefType extends globalThis.Record<string, unknown>>`)
.withComment('Mapping of union types')
.withBlock(
Object.entries(this._resolversUnionTypes)
Expand All @@ -1155,7 +1155,7 @@ export class BaseResolversVisitor<
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind(declarationKind)
.withName(this.convertName('ResolversInterfaceTypes'), `<RefType extends Record<string, unknown>>`)
.withName(this.convertName('ResolversInterfaceTypes'), `<RefType extends globalThis.Record<string, unknown>>`)
.withComment('Mapping of interface types')
.withBlock(
Object.entries(this._resolversInterfaceTypes)
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/typescript/resolvers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
The generated types will look like this:

```ts
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = {
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = {
CharacterNode: Fighter | Wizard;
};

Expand Down Expand Up @@ -322,7 +322,7 @@
Then, the generated type looks like this:

```ts
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = {
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = {
CharacterNode: (Fighter & { __typename: 'Fighter' }) | (Wizard & { __typename: 'Wizard' });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type AnotherNodeWithAll = AnotherNode & WithChild & WithChildren & {
};

export type MyUnion = MyType | MyOtherType;
export type WithIndex<TObject> = TObject & Record<string, any>;
export type WithIndex<TObject> = TObject & globalThis.Record<string, any>;
export type ResolversObject<TObject> = WithIndex<TObject>;

export type ResolverTypeWrapper<T> = Promise<T> | T;
Expand Down Expand Up @@ -167,13 +167,13 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
) => TResult | Promise<TResult>;

/** Mapping of union types */
export type ResolversUnionTypes<RefType extends Record<string, unknown>> = ResolversObject<{
export type ResolversUnionTypes<RefType extends globalThis.Record<string, unknown>> = ResolversObject<{
ChildUnion: ( Child ) | ( MyOtherType );
MyUnion: ( Omit<MyType, 'unionChild'> & { unionChild?: Maybe<RefType['ChildUnion']> } ) | ( MyOtherType );
}>;

/** Mapping of interface types */
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = ResolversObject<{
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = ResolversObject<{
Node: ( SomeNode );
AnotherNode: ( Omit<AnotherNodeWithChild, 'unionChild'> & { unionChild?: Maybe<RefType['ChildUnion']> } ) | ( Omit<AnotherNodeWithAll, 'unionChild' | 'unionChildren'> & { unionChild?: Maybe<RefType['ChildUnion']>, unionChildren: Array<RefType['ChildUnion']> } );
WithChild: ( Omit<AnotherNodeWithChild, 'unionChild'> & { unionChild?: Maybe<RefType['ChildUnion']> } ) | ( Omit<AnotherNodeWithAll, 'unionChild' | 'unionChildren'> & { unionChild?: Maybe<RefType['ChildUnion']>, unionChildren: Array<RefType['ChildUnion']> } );
Expand Down Expand Up @@ -357,7 +357,7 @@ exports[`TypeScript Resolvers Plugin Config namespacedImportName - should work c
"import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql';
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };
export type WithIndex<TObject> = TObject & Record<string, any>;
export type WithIndex<TObject> = TObject & globalThis.Record<string, any>;
export type ResolversObject<TObject> = WithIndex<TObject>;

export type ResolverTypeWrapper<T> = Promise<T> | T;
Expand Down Expand Up @@ -426,13 +426,13 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
) => TResult | Promise<TResult>;

/** Mapping of union types */
export type ResolversUnionTypes<RefType extends Record<string, unknown>> = ResolversObject<{
export type ResolversUnionTypes<RefType extends globalThis.Record<string, unknown>> = ResolversObject<{
ChildUnion: ( Types.Child ) | ( Types.MyOtherType );
MyUnion: ( Omit<Types.MyType, 'unionChild'> & { unionChild?: Types.Maybe<RefType['ChildUnion']> } ) | ( Types.MyOtherType );
}>;

/** Mapping of interface types */
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = ResolversObject<{
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = ResolversObject<{
Node: ( Types.SomeNode );
AnotherNode: ( Omit<Types.AnotherNodeWithChild, 'unionChild'> & { unionChild?: Types.Maybe<RefType['ChildUnion']> } ) | ( Omit<Types.AnotherNodeWithAll, 'unionChild' | 'unionChildren'> & { unionChild?: Types.Maybe<RefType['ChildUnion']>, unionChildren: Array<RefType['ChildUnion']> } );
WithChild: ( Omit<Types.AnotherNodeWithChild, 'unionChild'> & { unionChild?: Types.Maybe<RefType['ChildUnion']> } ) | ( Omit<Types.AnotherNodeWithAll, 'unionChild' | 'unionChildren'> & { unionChild?: Types.Maybe<RefType['ChildUnion']>, unionChildren: Array<RefType['ChildUnion']> } );
Expand Down Expand Up @@ -702,7 +702,7 @@ export type AnotherNodeWithAll = AnotherNode & WithChild & WithChildren & {
};

export type MyUnion = MyType | MyOtherType;
export type WithIndex<TObject> = TObject & Record<string, any>;
export type WithIndex<TObject> = TObject & globalThis.Record<string, any>;
export type ResolversObject<TObject> = WithIndex<TObject>;

export type ResolverTypeWrapper<T> = Promise<T> | T;
Expand Down Expand Up @@ -771,13 +771,13 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
) => TResult | Promise<TResult>;

/** Mapping of union types */
export type ResolversUnionTypes<RefType extends Record<string, unknown>> = ResolversObject<{
export type ResolversUnionTypes<RefType extends globalThis.Record<string, unknown>> = ResolversObject<{
ChildUnion: ( Child ) | ( MyOtherType );
MyUnion: ( Omit<MyType, 'unionChild'> & { unionChild?: Maybe<RefType['ChildUnion']> } ) | ( MyOtherType );
}>;

/** Mapping of interface types */
export type ResolversInterfaceTypes<RefType extends Record<string, unknown>> = ResolversObject<{
export type ResolversInterfaceTypes<RefType extends globalThis.Record<string, unknown>> = ResolversObject<{
Node: ( SomeNode );
AnotherNode: ( Omit<AnotherNodeWithChild, 'unionChild'> & { unionChild?: Maybe<RefType['ChildUnion']> } ) | ( Omit<AnotherNodeWithAll, 'unionChild' | 'unionChildren'> & { unionChild?: Maybe<RefType['ChildUnion']>, unionChildren: Array<RefType['ChildUnion']> } );
WithChild: ( Omit<AnotherNodeWithChild, 'unionChild'> & { unionChild?: Maybe<RefType['ChildUnion']> } ) | ( Omit<AnotherNodeWithAll, 'unionChild' | 'unionChildren'> & { unionChild?: Maybe<RefType['ChildUnion']>, unionChildren: Array<RefType['ChildUnion']> } );
Expand Down
Loading
Loading