Skip to content

Commit

Permalink
Better impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jun 19, 2024
1 parent 2442705 commit cd1ab96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/executor/src/execution/__tests__/abstract-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
GraphQLString,
GraphQLUnionType,
parse,
versionInfo,
} from 'graphql';
import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { execute, executeSync } from '../execute.js';
Expand Down Expand Up @@ -621,5 +622,14 @@ describe('Execute: Handles execution of abstract types', () => {
expectError({ forTypeName: undefined }).toEqual(
'Abstract type "Pet" must resolve to an Object type at runtime for field "Query.pet" with value { __typename: undefined }, received "[]".',
);

if (versionInfo.major >= 16) {
// FIXME: workaround since we can't inject resolveType into SDL
// @ts-expect-error
assertInterfaceType(schema.getType('Pet')).resolveType = () => schema.getType('Cat');
expectError({ forTypeName: undefined }).toEqual(
'Support for returning GraphQLObjectType from resolveType was removed in [email protected] please return type name instead.',
);
}
});
});
7 changes: 7 additions & 0 deletions packages/executor/src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
SchemaMetaFieldDef,
TypeMetaFieldDef,
TypeNameMetaFieldDef,
versionInfo,
} from 'graphql';
import { ValueOrPromise } from 'value-or-promise';
import {
Expand Down Expand Up @@ -1234,7 +1235,13 @@ function ensureValidRuntimeType(
}

// releases before 16.0.0 supported returning `GraphQLObjectType` from `resolveType`
// TODO: remove in 17.0.0 release
if (isObjectType(runtimeTypeName)) {
if (versionInfo.major >= 16) {
throw createGraphQLError(
'Support for returning GraphQLObjectType from resolveType was removed in [email protected] please return type name instead.',
);
}
runtimeTypeName = runtimeTypeName.name;
}

Expand Down

0 comments on commit cd1ab96

Please sign in to comment.