Skip to content

Commit 0acc6b9

Browse files
committed
fix(Flowtype): more strict type checks
1 parent d9c946d commit 0acc6b9

File tree

5 files changed

+130
-138
lines changed

5 files changed

+130
-138
lines changed

src/__tests__/composeWithConnection-test.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ describe('composeWithRelay', () => {
2020
});
2121

2222
it('should throw error if first arg is not TypeComposer', () => {
23-
// $FlowFixMe
24-
expect(() => composeWithConnection(123)).toThrowError('should provide TypeComposer instance');
23+
expect(() => {
24+
const wrongArgs: any = [123];
25+
composeWithConnection(...wrongArgs);
26+
}).toThrowError('should provide TypeComposer instance');
2527
});
2628

2729
it('should throw error if options are empty', () => {
28-
// $FlowFixMe
29-
expect(() => composeWithConnection(userTypeComposer)).toThrowError(
30-
'should provide non-empty options'
31-
);
30+
expect(() => {
31+
const wrongArgs: any = [userTypeComposer];
32+
composeWithConnection(...wrongArgs);
33+
}).toThrowError('should provide non-empty options');
3234
});
3335

3436
it('should not change `connection` resolver if exists', () => {
@@ -52,8 +54,7 @@ describe('composeWithRelay', () => {
5254

5355
describe('check `connection` resolver props', () => {
5456
const rsv = userComposer.getResolver('connection');
55-
const type = rsv.getType();
56-
// $FlowFixMe
57+
const type: any = rsv.getType();
5758
const tc = new TypeComposer(type);
5859

5960
it('should exists', () => {
@@ -94,9 +95,8 @@ describe('composeWithRelay', () => {
9495
}
9596
}
9697
}`;
97-
const result = await graphql(schema, query);
98+
const result: any = await graphql(schema, query);
9899

99-
// $FlowFixMe
100100
expect(result.data.userConnection).toEqual({
101101
count: 15,
102102
pageInfo: {
@@ -149,9 +149,8 @@ describe('composeWithRelay', () => {
149149
}
150150
}
151151
}`;
152-
const result = await graphql(schema, query);
152+
const result: any = await graphql(schema, query);
153153

154-
// $FlowFixMe
155154
expect(result.data.userConnection).toEqual({
156155
count: 15,
157156
pageInfo: {
@@ -243,7 +242,7 @@ describe('composeWithRelay', () => {
243242
});
244243

245244
it('should pass `countResolveParams` to top resolverParams', async () => {
246-
let topResolveParams;
245+
let topResolveParams: any = {};
247246

248247
rootQueryTC.setField(
249248
'userConnection',
@@ -265,18 +264,18 @@ describe('composeWithRelay', () => {
265264
}
266265
}`;
267266
await graphql(schema, query);
268-
// $FlowFixMe
267+
269268
expect(Object.keys(topResolveParams.countResolveParams)).toEqual(
270269
expect.arrayContaining(['source', 'args', 'context', 'info', 'projection'])
271270
);
272-
// $FlowFixMe
271+
273272
expect(topResolveParams.countResolveParams.args).toEqual({
274273
filter: { age: 45 },
275274
});
276275
});
277276

278277
it('should pass `findManyResolveParams` to top resolverParams', async () => {
279-
let topResolveParams;
278+
let topResolveParams: any = {};
280279

281280
rootQueryTC.setField(
282281
'userConnection',
@@ -298,11 +297,11 @@ describe('composeWithRelay', () => {
298297
}
299298
}`;
300299
await graphql(schema, query);
301-
// $FlowFixMe
300+
302301
expect(Object.keys(topResolveParams.findManyResolveParams)).toEqual(
303302
expect.arrayContaining(['source', 'args', 'context', 'info', 'projection'])
304303
);
305-
// $FlowFixMe
304+
306305
expect(topResolveParams.findManyResolveParams.args).toEqual({
307306
filter: { age: 45 },
308307
limit: 2,

src/__tests__/connectionResolver-test.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ describe('connectionResolver', () => {
2020
});
2121

2222
it('should throw error if first arg is not TypeComposer', () => {
23-
// $FlowFixMe
24-
expect(() => prepareConnectionResolver(123)).toThrowError(
25-
'should be instance of TypeComposer'
26-
);
23+
expect(() => {
24+
const wrongArgs: any = [123];
25+
prepareConnectionResolver(...wrongArgs);
26+
}).toThrowError('should be instance of TypeComposer');
2727
});
2828

2929
it('should throw error if opts.countResolverName are empty', () => {
30-
// $FlowFixMe
31-
expect(() => prepareConnectionResolver(userTypeComposer, {})).toThrowError(
32-
'should have option `opts.countResolverName`'
33-
);
30+
expect(() => {
31+
const wrongArgs: any = [userTypeComposer, {}];
32+
prepareConnectionResolver(...wrongArgs);
33+
}).toThrowError('should have option `opts.countResolverName`');
3434
});
3535

3636
it('should throw error if resolver opts.countResolverName does not exists', () => {
@@ -44,22 +44,24 @@ describe('connectionResolver', () => {
4444
});
4545

4646
it('should throw error if opts.findResolverName are empty', () => {
47-
expect(() =>
48-
// $FlowFixMe
49-
prepareConnectionResolver(userTypeComposer, {
50-
countResolverName: 'count',
51-
})
52-
).toThrowError('should have option `opts.findResolverName`');
47+
expect(() => {
48+
const wrongArgs: any = [userTypeComposer, { countResolverName: 'count' }];
49+
prepareConnectionResolver(...wrongArgs);
50+
}).toThrowError('should have option `opts.findResolverName`');
5351
});
5452

5553
it('should throw error if resolver opts.countResolverName does not exists', () => {
56-
expect(() =>
57-
prepareConnectionResolver(userTypeComposer, {
58-
countResolverName: 'count',
59-
findResolverName: 'findManyDoesNotExists',
60-
sort: sortOptions,
61-
})
62-
).toThrowError("does not have resolver with name 'findManyDoesNotExists'");
54+
expect(() => {
55+
const wrongArgs: any = [
56+
userTypeComposer,
57+
{
58+
countResolverName: 'count',
59+
findResolverName: 'findManyDoesNotExists',
60+
sort: sortOptions,
61+
},
62+
];
63+
prepareConnectionResolver(...wrongArgs);
64+
}).toThrowError("does not have resolver with name 'findManyDoesNotExists'");
6365
});
6466
});
6567

@@ -73,34 +75,28 @@ describe('connectionResolver', () => {
7375
});
7476

7577
it('should have type to be ConnectionType', () => {
76-
// $FlowFixMe
77-
expect(connectionResolver.type.name).toBe('UserConnection');
78+
expect((connectionResolver.type: any).name).toBe('UserConnection');
7879
});
7980
});
8081

8182
describe('resolver args', () => {
8283
it('should have `first` arg', () => {
83-
// $FlowFixMe
8484
expect(connectionResolver.getArg('first').type).toBe(GraphQLInt);
8585
});
8686

8787
it('should have `last` arg', () => {
88-
// $FlowFixMe
8988
expect(connectionResolver.getArg('last').type).toBe(GraphQLInt);
9089
});
9190

9291
it('should have `after` arg', () => {
93-
// $FlowFixMe
9492
expect(connectionResolver.getArg('after').type).toBe(GraphQLString);
9593
});
9694

9795
it('should have `before` arg', () => {
98-
// $FlowFixMe
9996
expect(connectionResolver.getArg('before').type).toBe(GraphQLString);
10097
});
10198

10299
it('should have `sort` arg', () => {
103-
// $FlowFixMe
104100
expect(connectionResolver.getArg('sort').type.name).toBe('SortConnectionUserEnum');
105101
});
106102
});
@@ -276,11 +272,10 @@ describe('connectionResolver', () => {
276272
};
277273

278274
it('should setup in resolveParams.rawQuery', () => {
279-
const rp = {
275+
const rp: any = {
280276
args: { filter: { id: 123 } },
281277
};
282278
prepareRawQuery(rp, sortConfig);
283-
// $FlowFixMe
284279
expect(rp.rawQuery).toEqual({});
285280
});
286281

@@ -304,26 +299,24 @@ describe('connectionResolver', () => {
304299
});
305300

306301
it('should call afterCursorQuery if provided args.after', () => {
307-
const rp = {
302+
const rp: any = {
308303
args: {
309304
after: dataToCursor({ id: 123 }),
310305
sort: sortConfig,
311306
},
312307
};
313308
prepareRawQuery(rp, sortConfig);
314-
// $FlowFixMe
315309
expect(rp.rawQuery).toEqual({ after: { id: 123 } });
316310
});
317311

318312
it('should call beforeCursorQuery if provided args.before', () => {
319-
const rp = {
313+
const rp: any = {
320314
args: {
321315
before: dataToCursor({ id: 234 }),
322316
sort: sortConfig,
323317
},
324318
};
325319
prepareRawQuery(rp, sortConfig);
326-
// $FlowFixMe
327320
expect(rp.rawQuery).toEqual({ before: { id: 234 } });
328321
});
329322

src/connectionResolver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable no-param-reassign, no-use-before-define */
33

44
import { Resolver, TypeComposer } from 'graphql-compose';
5-
import type { ResolveParams, ProjectionType } from 'graphql-compose';
5+
import type { ResolveParams, ProjectionType, ComposeFieldConfigArgumentMap } from 'graphql-compose';
66
import type { GraphQLResolveInfo } from 'graphql-compose/lib/graphql';
77
import { prepareConnectionType } from './types/connectionType';
88
import { prepareSortType } from './types/sortInputType';
@@ -103,9 +103,9 @@ export function prepareConnectionResolver<TSource, TContext>(
103103
}
104104
const findManyResolve = findManyResolver.getResolve();
105105
106-
const additionalArgs = {};
106+
const additionalArgs: ComposeFieldConfigArgumentMap = {};
107107
if (findManyResolver.hasArg('filter')) {
108-
const filter = findManyResolver.getArg('filter');
108+
const filter: any = findManyResolver.getArg('filter');
109109
if (filter) {
110110
additionalArgs.filter = filter;
111111
}

src/types/__tests__/connectionType-test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ describe('types/connectionType.js', () => {
3838
});
3939

4040
it('should have `ofType` property (like GraphQLList, GraphQLNonNull)', () => {
41-
const edgeType = prepareEdgeType(userTypeComposer);
42-
// $FlowFixMe
41+
const edgeType: any = prepareEdgeType(userTypeComposer);
4342
expect(edgeType.ofType).toEqual(userTypeComposer.getType());
4443
});
4544

@@ -78,16 +77,14 @@ describe('types/connectionType.js', () => {
7877
expect(tc.getFieldType('edges')).toBeInstanceOf(GraphQLNonNull);
7978
expect(tc.getFieldType('edges').ofType).toBeInstanceOf(GraphQLList);
8079

81-
const edges = getNamedType(tc.getFieldType('edges'));
82-
// $FlowFixMe
80+
const edges: any = getNamedType(tc.getFieldType('edges'));
8381
expect(edges.name).toEqual('UserEdge');
8482
});
8583

8684
it('should have `ofType` property (like GraphQLList, GraphQLNonNull)', () => {
8785
// this behavior needed for `graphql-compose` module in `projection` helper
8886
// otherwise it incorrectly construct projectionMapper for tricky fields
89-
const connectionType = prepareConnectionType(userTypeComposer);
90-
// $FlowFixMe
87+
const connectionType: any = prepareConnectionType(userTypeComposer);
9188
expect(connectionType.ofType).toEqual(userTypeComposer.getType());
9289
});
9390

0 commit comments

Comments
 (0)