Skip to content

Commit 8889115

Browse files
committed
GraphQLInterface: add missing template parameters
Context: GraphQLInterfaceTypeConfig has template parameters but they are not infered by GraphQLInterfaceType. I noticed it while trying to type resolvers, please see changes in `abstract-test.ts`
1 parent ea10c7b commit 8889115

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/execution/__tests__/abstract-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ describe('Execute: Handles execution of abstract types', () => {
357357
});
358358

359359
it('resolveType can throw', async () => {
360-
const PetType = new GraphQLInterfaceType({
360+
const PetType = new GraphQLInterfaceType<Dog | Cat, Context>({
361361
name: 'Pet',
362362
resolveType(_source, context) {
363363
const error = new Error('We are testing this error');
364-
if (context.async === true) {
364+
if (context.async) {
365365
return Promise.reject(error);
366366
}
367367
throw error;

src/type/definition.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,34 +1017,36 @@ export interface GraphQLInterfaceTypeExtensions {
10171017
* });
10181018
* ```
10191019
*/
1020-
export class GraphQLInterfaceType {
1020+
export class GraphQLInterfaceType<TSource = any, TContext = any> {
10211021
name: string;
10221022
description: Maybe<string>;
1023-
resolveType: Maybe<GraphQLTypeResolver<any, any>>;
1023+
resolveType: Maybe<GraphQLTypeResolver<TSource, TContext>>;
10241024
extensions: Readonly<GraphQLInterfaceTypeExtensions>;
10251025
astNode: Maybe<InterfaceTypeDefinitionNode>;
10261026
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
10271027

1028-
private _fields: ThunkObjMap<GraphQLField<any, any>>;
1028+
private _fields: ThunkObjMap<GraphQLField<TSource, TContext>>;
10291029
private _interfaces: ThunkReadonlyArray<GraphQLInterfaceType>;
10301030

1031-
constructor(config: Readonly<GraphQLInterfaceTypeConfig<any, any>>) {
1031+
constructor(config: Readonly<GraphQLInterfaceTypeConfig<TSource, TContext>>) {
10321032
this.name = assertName(config.name);
10331033
this.description = config.description;
10341034
this.resolveType = config.resolveType;
10351035
this.extensions = toObjMap(config.extensions);
10361036
this.astNode = config.astNode;
10371037
this.extensionASTNodes = config.extensionASTNodes ?? [];
10381038

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

10431045
get [Symbol.toStringTag]() {
10441046
return 'GraphQLInterfaceType';
10451047
}
10461048

1047-
getFields(): GraphQLFieldMap<any, any> {
1049+
getFields(): GraphQLFieldMap<TSource, TContext> {
10481050
if (typeof this._fields === 'function') {
10491051
this._fields = this._fields();
10501052
}
@@ -1058,7 +1060,7 @@ export class GraphQLInterfaceType {
10581060
return this._interfaces;
10591061
}
10601062

1061-
toConfig(): GraphQLInterfaceTypeNormalizedConfig {
1063+
toConfig(): GraphQLInterfaceTypeNormalizedConfig<TSource, TContext> {
10621064
return {
10631065
name: this.name,
10641066
description: this.description,
@@ -1096,10 +1098,10 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
10961098
extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
10971099
}
10981100

1099-
export interface GraphQLInterfaceTypeNormalizedConfig
1101+
export interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
11001102
extends GraphQLInterfaceTypeConfig<any, any> {
11011103
interfaces: ReadonlyArray<GraphQLInterfaceType>;
1102-
fields: GraphQLFieldConfigMap<any, any>;
1104+
fields: GraphQLFieldConfigMap<TSource, TContext>;
11031105
extensions: Readonly<GraphQLInterfaceTypeExtensions>;
11041106
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
11051107
}

0 commit comments

Comments
 (0)