Skip to content

Commit 5accb29

Browse files
committed
TS: Fix strict issues in src/utilities
1 parent 6b95561 commit 5accb29

15 files changed

+52
-48
lines changed

src/type/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class GraphQLSchema {
274274
return this._typeMap;
275275
}
276276

277-
getType(name: string): Maybe<GraphQLNamedType> {
277+
getType(name: string): GraphQLNamedType | undefined {
278278
return this.getTypeMap()[name];
279279
}
280280

src/utilities/TypeInfo.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,12 @@ export function visitWithTypeInfo(
337337
visitor: ASTVisitor,
338338
): ASTVisitor {
339339
return {
340-
enter(node) {
340+
enter(...args) {
341+
const node = args[0];
341342
typeInfo.enter(node);
342343
const fn = getVisitFn(visitor, node.kind, /* isLeaving */ false);
343344
if (fn) {
344-
const result = fn.apply(visitor, arguments);
345+
const result = fn.apply(visitor, args);
345346
if (result !== undefined) {
346347
typeInfo.leave(node);
347348
if (isNode(result)) {
@@ -351,11 +352,12 @@ export function visitWithTypeInfo(
351352
return result;
352353
}
353354
},
354-
leave(node) {
355+
leave(...args) {
356+
const node = args[0];
355357
const fn = getVisitFn(visitor, node.kind, /* isLeaving */ true);
356358
let result;
357359
if (fn) {
358-
result = fn.apply(visitor, arguments);
360+
result = fn.apply(visitor, args);
359361
}
360362
typeInfo.leave(node);
361363
return result;

src/utilities/__tests__/TypeInfo-test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('visitWithTypeInfo', () => {
5858
`);
5959
const typeInfo = new TypeInfo(schema);
6060

61-
const rootTypes = {};
61+
const rootTypes: any = {};
6262
visit(
6363
ast,
6464
visitWithTypeInfo(typeInfo, {
@@ -80,7 +80,7 @@ describe('visitWithTypeInfo', () => {
8080
'{ human(id: 4) { name, pets { ... { name } }, unknown } }',
8181
);
8282

83-
const visitorArgs = [];
83+
const visitorArgs: Array<any> = [];
8484
visit(ast, {
8585
enter(...args) {
8686
visitorArgs.push(['enter', ...args]);
@@ -90,7 +90,7 @@ describe('visitWithTypeInfo', () => {
9090
},
9191
});
9292

93-
const wrappedVisitorArgs = [];
93+
const wrappedVisitorArgs: Array<any> = [];
9494
const typeInfo = new TypeInfo(testSchema);
9595
visit(
9696
ast,
@@ -108,7 +108,7 @@ describe('visitWithTypeInfo', () => {
108108
});
109109

110110
it('maintains type info during visit', () => {
111-
const visited = [];
111+
const visited: Array<any> = [];
112112

113113
const typeInfo = new TypeInfo(testSchema);
114114

@@ -193,7 +193,7 @@ describe('visitWithTypeInfo', () => {
193193
});
194194

195195
it('maintains type info during edit', () => {
196-
const visited = [];
196+
const visited: Array<any> = [];
197197
const typeInfo = new TypeInfo(testSchema);
198198

199199
const ast = parse('{ human(id: 4) { name, pets }, alien }');
@@ -314,7 +314,7 @@ describe('visitWithTypeInfo', () => {
314314

315315
const typeInfo = new TypeInfo(testSchema, complexInputType);
316316

317-
const visited = [];
317+
const visited: Array<any> = [];
318318
visit(
319319
ast,
320320
visitWithTypeInfo(typeInfo, {
@@ -363,7 +363,7 @@ describe('visitWithTypeInfo', () => {
363363
const operationNode = ast.definitions[0];
364364
invariant(operationNode.kind === 'OperationDefinition');
365365

366-
const visited = [];
366+
const visited: Array<any> = [];
367367
visit(
368368
operationNode.selectionSet,
369369
visitWithTypeInfo(typeInfo, {

src/utilities/__tests__/buildASTSchema-test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Schema Builder', () => {
8989

9090
const source = '{ add(x: 34, y: 55) }';
9191
const rootValue = {
92-
add: ({ x, y }) => x + y,
92+
add: ({ x, y }: { x: number; y: number }) => x + y,
9393
};
9494
expect(graphqlSync({ schema, source, rootValue })).to.deep.equal({
9595
data: { add: 89 },
@@ -1095,6 +1095,7 @@ describe('Schema Builder', () => {
10951095
});
10961096

10971097
it('Rejects invalid AST', () => {
1098+
// TODO ts-expect-error (First parameter expected to be DocumentNode)
10981099
expect(() => buildASTSchema(null)).to.throw(
10991100
'Must provide valid Document AST',
11001101
);

src/utilities/__tests__/buildClientSchema-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ describe('Type System: build schema from introspection', () => {
629629
`);
630630

631631
it('throws when introspection is missing __schema property', () => {
632+
// TODO ts-expect-error (First parameter expected to be introspection results)
632633
expect(() => buildClientSchema(null)).to.throw(
633634
'Invalid or incomplete introspection result. Ensure that you are passing "data" property of introspection response and no "errors" was returned alongside: null.',
634635
);

src/utilities/__tests__/coerceInputValue-test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ import { coerceInputValue } from '../coerceInputValue';
1515

1616
interface CoerceResult {
1717
value: unknown;
18-
errors: ReadonlyArray<{
19-
path: ReadonlyArray<string | number>;
20-
value: unknown;
21-
error: string;
22-
}>;
18+
errors: ReadonlyArray<CoerceError>;
19+
}
20+
21+
interface CoerceError {
22+
path: ReadonlyArray<string | number>;
23+
value: unknown;
24+
error: string;
2325
}
2426

2527
function coerceValue(
2628
inputValue: unknown,
2729
type: GraphQLInputType,
2830
): CoerceResult {
29-
const errors = [];
31+
const errors: Array<CoerceError> = [];
3032
const value = coerceInputValue(
3133
inputValue,
3234
type,
@@ -82,7 +84,7 @@ describe('coerceInputValue', () => {
8284
describe('for GraphQLScalar', () => {
8385
const TestScalar = new GraphQLScalarType({
8486
name: 'TestScalar',
85-
parseValue(input: { error?: string; value?: unknown }) {
87+
parseValue(input: any) {
8688
if (input.error != null) {
8789
throw new Error(input.error);
8890
}
@@ -272,7 +274,7 @@ describe('coerceInputValue', () => {
272274
});
273275

274276
describe('for GraphQLInputObject with default value', () => {
275-
const makeTestInputObject = (defaultValue) =>
277+
const makeTestInputObject = (defaultValue: any) =>
276278
new GraphQLInputObjectType({
277279
name: 'TestInputObject',
278280
fields: {

src/utilities/__tests__/extendSchema-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ describe('extendSchema', () => {
11431143
it('Rejects invalid AST', () => {
11441144
const schema = new GraphQLSchema({});
11451145

1146+
// TODO ts-expect-error (Second argument expects DocumentNode)
11461147
expect(() => extendSchema(schema, null)).to.throw(
11471148
'Must provide valid Document AST',
11481149
);

src/utilities/coerceInputValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function coerceInputValueImpl(
9595
return;
9696
}
9797

98-
const coercedValue = {};
98+
const coercedValue: any = {};
9999
const fieldDefs = type.getFields();
100100

101101
for (const field of Object.values(fieldDefs)) {

src/utilities/concatAST.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DocumentNode } from '../language/ast';
1+
import type { DocumentNode, DefinitionNode } from '../language/ast';
22

33
/**
44
* Provided a collection of ASTs, presumably each from different files,
@@ -8,9 +8,9 @@ import type { DocumentNode } from '../language/ast';
88
export function concatAST(
99
documents: ReadonlyArray<DocumentNode>,
1010
): DocumentNode {
11-
let definitions = [];
11+
const definitions: Array<DefinitionNode> = [];
1212
for (const doc of documents) {
13-
definitions = definitions.concat(doc.definitions);
13+
definitions.push(...doc.definitions);
1414
}
1515
return { kind: 'Document', definitions };
1616
}

src/utilities/extendSchema.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export function extendSchemaImpl(
379379
return {
380380
...field,
381381
type: replaceType(field.type),
382-
args: mapValue(field.args, extendArg),
382+
args: field.args && mapValue(field.args, extendArg),
383383
};
384384
}
385385

@@ -393,24 +393,24 @@ export function extendSchemaImpl(
393393
function getOperationTypes(
394394
nodes: ReadonlyArray<SchemaDefinitionNode | SchemaExtensionNode>,
395395
): {
396-
query: Maybe<GraphQLObjectType>;
397-
mutation: Maybe<GraphQLObjectType>;
398-
subscription: Maybe<GraphQLObjectType>;
396+
query?: Maybe<GraphQLObjectType>;
397+
mutation?: Maybe<GraphQLObjectType>;
398+
subscription?: Maybe<GraphQLObjectType>;
399399
} {
400400
const opTypes = {};
401401
for (const node of nodes) {
402402
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
403403
const operationTypesNodes = node.operationTypes ?? [];
404404

405405
for (const operationType of operationTypesNodes) {
406+
// Note: While this could make early assertions to get the correctly
407+
// typed values below, that would throw immediately while type system
408+
// validation with validateSchema() will produce more actionable results.
409+
// TODO ts-expect-error
406410
opTypes[operationType.operation] = getNamedType(operationType.type);
407411
}
408412
}
409413

410-
// Note: While this could make early assertions to get the correctly
411-
// typed values below, that would throw immediately while type system
412-
// validation with validateSchema() will produce more actionable results.
413-
// @ts-expect-error
414414
return opTypes;
415415
}
416416

@@ -656,8 +656,7 @@ export function extendSchemaImpl(
656656
}
657657

658658
const stdTypeMap = keyMap(
659-
// @ts-expect-error FIXME: TS Conversion
660-
specifiedScalarTypes.concat(introspectionTypes),
659+
[...specifiedScalarTypes, ...introspectionTypes],
661660
(type) => type.name,
662661
);
663662

0 commit comments

Comments
 (0)