Skip to content
Closed
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
22 changes: 13 additions & 9 deletions src/type/__tests__/definition-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ describe('Type System: Scalars', () => {
},
});

// @ts-expect-error FIXME: TS Conversion
expect(scalar.parseLiteral(parseValue('null'))).to.equal(
'parseValue: null',
);
// @ts-expect-error FIXME: TS Conversion
expect(scalar.parseLiteral(parseValue('{ foo: "bar" }'))).to.equal(
'parseValue: { foo: "bar" }',
);
Expand Down Expand Up @@ -335,6 +333,7 @@ describe('Type System: Objects', () => {
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {
// TODO ts-expect-error (must not be undefined)
f: undefined,
},
});
Expand All @@ -357,7 +356,7 @@ describe('Type System: Objects', () => {
it('rejects an Object type with a field function that returns incorrect type', () => {
const objType = new GraphQLObjectType({
name: 'SomeObject',
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Wrong type of return)
fields() {
return [{ field: ScalarType }];
},
Expand Down Expand Up @@ -397,7 +396,7 @@ describe('Type System: Objects', () => {
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {},
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Expected interfaces to return array)
interfaces() {
return {};
},
Expand All @@ -411,7 +410,7 @@ describe('Type System: Objects', () => {
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Expected resolve to be a function)
field: { type: ScalarType, resolve: {} },
},
});
Expand All @@ -425,7 +424,7 @@ describe('Type System: Objects', () => {
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Expected resolve to be a function)
field: { type: ScalarType, resolve: 0 },
},
});
Expand Down Expand Up @@ -500,7 +499,7 @@ describe('Type System: Interfaces', () => {
const objType = new GraphQLInterfaceType({
name: 'AnotherInterface',
fields: {},
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Expected Array return)
interfaces() {
return {};
},
Expand Down Expand Up @@ -698,6 +697,7 @@ describe('Type System: Enums', () => {
() =>
new GraphQLEnumType({
name: 'SomeEnum',
// TODO ts-expect-error (must not be null)
values: { FOO: null },
}),
).to.throw(
Expand Down Expand Up @@ -796,7 +796,7 @@ describe('Type System: Input Objects', () => {
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields: {
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Input fields cannot have resolvers)
f: { type: ScalarType, resolve: dummyFunc },
},
});
Expand All @@ -809,7 +809,7 @@ describe('Type System: Input Objects', () => {
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields: {
// @ts-expect-error FIXME: TS Conversion
// @ts-expect-error (Input fields cannot have resolvers)
f: { type: ScalarType, resolve: {} },
},
});
Expand Down Expand Up @@ -843,7 +843,9 @@ describe('Type System: List', () => {
expectList(String).to.throw(
'Expected [function String] to be a GraphQL type.',
);
// TODO ts-expect-error (must provide type)
expectList(null).to.throw('Expected null to be a GraphQL type.');
// TODO ts-expect-error (must provide type)
expectList(undefined).to.throw('Expected undefined to be a GraphQL type.');
});
});
Expand Down Expand Up @@ -874,9 +876,11 @@ describe('Type System: Non-Null', () => {
expectNonNull(String).to.throw(
'Expected [function String] to be a GraphQL nullable type.',
);
// TODO ts-expect-error (must provide type)
expectNonNull(null).to.throw(
'Expected null to be a GraphQL nullable type.',
);
// TODO ts-expect-error (must provide type)
expectNonNull(undefined).to.throw(
'Expected undefined to be a GraphQL nullable type.',
);
Expand Down
11 changes: 9 additions & 2 deletions src/type/__tests__/introspection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getIntrospectionQuery } from '../../utilities/getIntrospectionQuery';

import { graphqlSync } from '../../graphql';

import type { GraphQLResolveInfo } from '../definition';

describe('Introspection', () => {
it('executes an introspection query', () => {
const schema = buildSchema(`
Expand Down Expand Up @@ -1566,12 +1568,17 @@ describe('Introspection', () => {
});

// istanbul ignore next (Called only to fail test)
function fieldResolver(_1, _2, _3, info): never {
function fieldResolver(
_1: any,
_2: any,
_3: any,
info: GraphQLResolveInfo,
): never {
expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`);
}

// istanbul ignore next (Called only to fail test)
function typeResolver(_1, _2, info): never {
function typeResolver(_1: any, _2: any, info: GraphQLResolveInfo): never {
expect.fail(`Called on ${info.parentType.name}::${info.fieldName}`);
}

Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/scalars-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ describe('Type System: Specified scalar types', () => {
serialize({
value: true,
valueOf() {
return this.value;
return (this as { value: boolean }).value;
},
}),
).to.equal(true);
Expand Down
4 changes: 2 additions & 2 deletions src/type/__tests__/schema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Type System: Schema', () => {
},
});

const BlogAuthor = new GraphQLObjectType({
const BlogAuthor: GraphQLObjectType = new GraphQLObjectType({
name: 'Author',
fields: () => ({
id: { type: GraphQLString },
Expand All @@ -40,7 +40,7 @@ describe('Type System: Schema', () => {
}),
});

const BlogArticle = new GraphQLObjectType({
const BlogArticle: GraphQLObjectType = new GraphQLObjectType({
name: 'Article',
fields: {
id: { type: GraphQLString },
Expand Down
5 changes: 5 additions & 0 deletions src/type/__tests__/validation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ describe('Type System: Object fields must have output types', () => {
}

it('rejects an empty Object field type', () => {
// TODO ts-expect-error (type field must not be undefined)
const schema = schemaWithObjectField({ type: undefined });
expect(validateSchema(schema)).to.deep.equal([
{
Expand Down Expand Up @@ -1097,6 +1098,7 @@ describe('Type System: Objects can only implement unique interfaces', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'BadObject',
// TODO ts-expect-error (interfaces must not contain undefined)
interfaces: [undefined],
fields: { f: { type: GraphQLString } },
}),
Expand Down Expand Up @@ -1355,6 +1357,7 @@ describe('Type System: Interface fields must have output types', () => {
}

it('rejects an empty Interface field type', () => {
// TODO ts-expect-error (type field must not be undefined)
const schema = schemaWithInterfaceField({ type: undefined });
expect(validateSchema(schema)).to.deep.equal([
{
Expand Down Expand Up @@ -1490,6 +1493,7 @@ describe('Type System: Arguments must have input types', () => {
}

it('rejects an empty field arg type', () => {
// TODO ts-expect-error (type field must not be undefined)
const schema = schemaWithArg({ type: undefined });
expect(validateSchema(schema)).to.deep.equal([
{
Expand Down Expand Up @@ -1627,6 +1631,7 @@ describe('Type System: Input Object fields must have input types', () => {
}

it('rejects an empty input field type', () => {
// TODO ts-expect-error (type field must not be undefined)
const schema = schemaWithInputField({ type: undefined });
expect(validateSchema(schema)).to.deep.equal([
{
Expand Down
12 changes: 5 additions & 7 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ export type GraphQLScalarValueParser<TInternal> = (

export type GraphQLScalarLiteralParser<TInternal> = (
valueNode: ValueNode,
variables: Maybe<ObjMap<unknown>>,
variables?: Maybe<ObjMap<unknown>>,
) => Maybe<TInternal>;

export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
Expand Down Expand Up @@ -758,8 +758,8 @@ export class GraphQLObjectType<TSource = any, TContext = any> {
this.astNode = config.astNode;
this.extensionASTNodes = config.extensionASTNodes ?? [];

this._fields = defineFieldMap.bind(undefined, config);
this._interfaces = defineInterfaces.bind(undefined, config);
this._fields = () => defineFieldMap(config);
this._interfaces = () => defineInterfaces(config);
devAssert(typeof config.name === 'string', 'Must provide name.');
devAssert(
config.isTypeOf == null || typeof config.isTypeOf === 'function',
Expand Down Expand Up @@ -810,8 +810,7 @@ export class GraphQLObjectType<TSource = any, TContext = any> {

function defineInterfaces(
config: Readonly<
| GraphQLObjectTypeConfig<unknown, unknown>
| GraphQLInterfaceTypeConfig<unknown, unknown>
GraphQLObjectTypeConfig<any, any> | GraphQLInterfaceTypeConfig<any, any>
>,
): Array<GraphQLInterfaceType> {
const interfaces = resolveArrayThunk(config.interfaces ?? []);
Expand All @@ -834,7 +833,6 @@ function defineFieldMap<TSource, TContext>(
`${config.name} fields must be an object with field names as keys or a function which returns such an object.`,
);

// @ts-expect-error FIXME: TS Conversion
return mapValue(fieldMap, (fieldConfig, fieldName) => {
devAssert(
isPlainObj(fieldConfig),
Expand Down Expand Up @@ -1048,7 +1046,7 @@ export interface GraphQLField<
name: string;
description: Maybe<string>;
type: GraphQLOutputType;
args: Array<GraphQLArgument>;
args: ReadonlyArray<GraphQLArgument>;
resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
deprecationReason: Maybe<string>;
Expand Down
14 changes: 5 additions & 9 deletions src/type/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,18 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
},
name: {
type: GraphQLString,
// @ts-expect-error FIXME: TS Conversion
resolve: (type) => (type.name !== undefined ? type.name : undefined),
resolve: (type) => ('name' in type ? type.name : undefined),
},
description: {
type: GraphQLString,
resolve: (type) =>
// @ts-expect-error FIXME: TS Conversion
type.description !== undefined ? type.description : undefined,
// istanbul ignore next (FIXME: add test case)
'description' in type ? type.description : undefined,
},
specifiedByURL: {
type: GraphQLString,
resolve: (obj) =>
// @ts-expect-error FIXME: TS Conversion
obj.specifiedByURL !== undefined ? obj.specifiedByURL : undefined,
'specifiedByURL' in obj ? obj.specifiedByURL : undefined,
},
fields: {
type: new GraphQLList(new GraphQLNonNull(__Field)),
Expand Down Expand Up @@ -312,9 +310,7 @@ export const __Type: GraphQLObjectType = new GraphQLObjectType({
},
ofType: {
type: __Type,
resolve: (type) =>
// @ts-expect-error FIXME: TS Conversion
type.ofType !== undefined ? type.ofType : undefined,
resolve: (type) => ('ofType' in type ? type.ofType : undefined),
},
} as GraphQLFieldConfigMap<GraphQLType, unknown>),
});
Expand Down
Loading