Skip to content

Commit

Permalink
GraphQLInterface: add missing template parameters (#3877)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Apr 5, 2023
1 parent ea10c7b commit 35b9d96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/execution/__tests__/abstract-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ describe('Execute: Handles execution of abstract types', () => {
});

it('resolveType can throw', async () => {
const PetType = new GraphQLInterfaceType({
const PetType = new GraphQLInterfaceType<Dog | Cat, Context>({
name: 'Pet',
resolveType(_source, context) {
const error = new Error('We are testing this error');
if (context.async === true) {
if (context.async) {
return Promise.reject(error);
}
throw error;
Expand Down
20 changes: 11 additions & 9 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,34 +1017,36 @@ export interface GraphQLInterfaceTypeExtensions {
* });
* ```
*/
export class GraphQLInterfaceType {
export class GraphQLInterfaceType<TSource = any, TContext = any> {
name: string;
description: Maybe<string>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;
resolveType: Maybe<GraphQLTypeResolver<TSource, TContext>>;
extensions: Readonly<GraphQLInterfaceTypeExtensions>;
astNode: Maybe<InterfaceTypeDefinitionNode>;
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;

private _fields: ThunkObjMap<GraphQLField<any, any>>;
private _fields: ThunkObjMap<GraphQLField<TSource, TContext>>;
private _interfaces: ThunkReadonlyArray<GraphQLInterfaceType>;

constructor(config: Readonly<GraphQLInterfaceTypeConfig<any, any>>) {
constructor(config: Readonly<GraphQLInterfaceTypeConfig<TSource, TContext>>) {
this.name = assertName(config.name);
this.description = config.description;
this.resolveType = config.resolveType;
this.extensions = toObjMap(config.extensions);
this.astNode = config.astNode;
this.extensionASTNodes = config.extensionASTNodes ?? [];

this._fields = defineFieldMap.bind(undefined, config.fields);
// prettier-ignore
// FIXME: blocked by https://github.com/prettier/prettier/issues/14625
this._fields = (defineFieldMap<TSource, TContext>).bind(undefined, config.fields);
this._interfaces = defineInterfaces.bind(undefined, config.interfaces);
}

get [Symbol.toStringTag]() {
return 'GraphQLInterfaceType';
}

getFields(): GraphQLFieldMap<any, any> {
getFields(): GraphQLFieldMap<TSource, TContext> {
if (typeof this._fields === 'function') {
this._fields = this._fields();
}
Expand All @@ -1058,7 +1060,7 @@ export class GraphQLInterfaceType {
return this._interfaces;
}

toConfig(): GraphQLInterfaceTypeNormalizedConfig {
toConfig(): GraphQLInterfaceTypeNormalizedConfig<TSource, TContext> {
return {
name: this.name,
description: this.description,
Expand Down Expand Up @@ -1096,10 +1098,10 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
}

export interface GraphQLInterfaceTypeNormalizedConfig
export interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
extends GraphQLInterfaceTypeConfig<any, any> {
interfaces: ReadonlyArray<GraphQLInterfaceType>;
fields: GraphQLFieldConfigMap<any, any>;
fields: GraphQLFieldConfigMap<TSource, TContext>;
extensions: Readonly<GraphQLInterfaceTypeExtensions>;
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
}
Expand Down

0 comments on commit 35b9d96

Please sign in to comment.