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

GraphQLInterface: add missing template parameters #3877

Merged
merged 1 commit into from
Apr 5, 2023
Merged
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
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