Skip to content

Commit b2d0079

Browse files
committed
fix(Flowtype): More strict type checks
1 parent 1e68e69 commit b2d0079

File tree

8 files changed

+32
-89
lines changed

8 files changed

+32
-89
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
}],
2929
"no-unused-expressions": 0,
3030
"no-restricted-syntax": 0,
31+
"prefer-destructuring": 0,
3132
},
3233
"env": {
3334
"jasmine": true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"watch": "jest --watch",
7070
"coverage": "jest --coverage",
7171
"lint": "eslint --ext .js ./src",
72-
"flow": "./node_modules/.bin/flow stop && ./node_modules/.bin/flow",
72+
"flow": "./node_modules/.bin/flow",
7373
"test": "npm run coverage && npm run lint && npm run flow",
7474
"link": "yarn build && yarn link graphql-compose && yarn link",
7575
"unlink": "yarn unlink graphql-compose && yarn add graphql-compose",

src/__tests__/composeWithPagination-test.js

Lines changed: 14 additions & 14 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(() => composeWithPagination(123)).toThrowError('should provide TypeComposer instance');
23+
expect(() => {
24+
const args: any = [123];
25+
composeWithPagination(...args);
26+
}).toThrowError('should provide TypeComposer instance');
2527
});
2628

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

3436
it('should not change `pagination` resolver if exists', () => {
@@ -51,8 +53,7 @@ describe('composeWithRelay', () => {
5153

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

5859
it('should exists', () => {
@@ -123,7 +124,7 @@ describe('composeWithRelay', () => {
123124
});
124125

125126
it('should pass `countResolveParams` to top resolverParams', async () => {
126-
let topResolveParams;
127+
let topResolveParams: any = {};
127128

128129
rootQueryTC.setField(
129130
'userPagination',
@@ -142,18 +143,17 @@ describe('composeWithRelay', () => {
142143
}
143144
}`;
144145
await graphql(schema, query);
145-
// $FlowFixMe
146+
146147
expect(Object.keys(topResolveParams.countResolveParams)).toEqual(
147148
expect.arrayContaining(['source', 'args', 'context', 'info', 'projection'])
148149
);
149-
// $FlowFixMe
150150
expect(topResolveParams.countResolveParams.args).toEqual({
151151
filter: { age: 45 },
152152
});
153153
});
154154

155155
it('should pass `findManyResolveParams` to top resolverParams', async () => {
156-
let topResolveParams;
156+
let topResolveParams: any = {};
157157

158158
rootQueryTC.setField(
159159
'userPagination',
@@ -172,11 +172,11 @@ describe('composeWithRelay', () => {
172172
}
173173
}`;
174174
await graphql(schema, query);
175-
// $FlowFixMe
175+
176176
expect(Object.keys(topResolveParams.findManyResolveParams)).toEqual(
177177
expect.arrayContaining(['source', 'args', 'context', 'info', 'projection'])
178178
);
179-
// $FlowFixMe
179+
180180
expect(topResolveParams.findManyResolveParams.args).toEqual({
181181
filter: { age: 45 },
182182
limit: 6,

src/__tests__/paginationResolver-test.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ describe('paginationResolver', () => {
2121
});
2222

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

3030
it('should throw error if opts.countResolverName are empty', () => {
31-
// $FlowFixMe
32-
expect(() => preparePaginationResolver(userTypeComposer, {})).toThrowError(
33-
'should have option `opts.countResolverName`'
34-
);
31+
expect(() => {
32+
const args: any = [userTypeComposer, {}];
33+
preparePaginationResolver(...args);
34+
}).toThrowError('should have option `opts.countResolverName`');
3535
});
3636

3737
it('should throw error if resolver opts.countResolverName does not exists', () => {
@@ -44,12 +44,10 @@ describe('paginationResolver', () => {
4444
});
4545

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

5553
it('should throw error if resolver opts.countResolverName does not exists', () => {
@@ -72,19 +70,16 @@ describe('paginationResolver', () => {
7270
});
7371

7472
it('should have type to be ConnectionType', () => {
75-
// $FlowFixMe
76-
expect(paginationResolver.type.name).toBe('UserPagination');
73+
expect((paginationResolver.type: any).name).toBe('UserPagination');
7774
});
7875
});
7976

8077
describe('resolver args', () => {
8178
it('should have `page` arg', () => {
82-
// $FlowFixMe
8379
expect(paginationResolver.getArg('page').type).toBe(GraphQLInt);
8480
});
8581

8682
it('should have `perPage` arg', () => {
87-
// $FlowFixMe
8883
expect(paginationResolver.getArg('perPage').type).toBe(GraphQLInt);
8984
});
9085
});

src/paginationResolver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function preparePaginationResolver<TSource, TContext>(
107107
description: '',
108108
defaultValue: opts.perPage || DEFAULT_PER_PAGE,
109109
},
110-
...additionalArgs,
110+
...(additionalArgs: any),
111111
},
112112
// eslint-disable-next-line
113113
resolve: async (resolveParams: $Shape<PaginationResolveParams<TSource, TContext>>) => {

src/types/__tests__/paginationType-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ describe('types/paginationType.js', () => {
3939
const tc = new TypeComposer(preparePaginationType(userTypeComposer));
4040
expect(tc.getFieldType('items')).toBeInstanceOf(GraphQLList);
4141

42-
const items = getNamedType(tc.getFieldType('items'));
43-
// $FlowFixMe
42+
const items: any = getNamedType(tc.getFieldType('items'));
4443
expect(items.name).toEqual('User');
4544
});
4645

4746
it('should have `ofType` property (like GraphQLList, GraphQLNonNull)', () => {
4847
// this behavior needed for `graphql-compose` module in `projection` helper
4948
// otherwise it incorrectly construct projectionMapper for tricky fields
50-
const connectionType = preparePaginationType(userTypeComposer);
51-
// $FlowFixMe
49+
const connectionType: any = preparePaginationType(userTypeComposer);
5250
expect(connectionType.ofType).toEqual(userTypeComposer.getType());
5351
});
5452

src/utils/deepmerge.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/utils/is.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)