Skip to content

Commit 485115a

Browse files
committed
fix(Flowtype): Resolve Flow errors in tests and fix some definitions
1 parent 5486a9b commit 485115a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+205
-133
lines changed

.flowconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
[ignore]
2-
.*/__tests__/.*
3-
.*/__mocks__/.*
42
.*/coverage/.*
53
.*/resources/.*
64
<PROJECT_ROOT>/lib/.*
@@ -44,5 +42,3 @@
4442
esproposal.class_instance_fields=enable
4543
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
4644
unsafe.enable_getters_and_setters=true
47-
48-
[version]

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
"object-path": "^0.11.4"
2828
},
2929
"peerDependencies": {
30-
"graphql": ">=0.7.1 || >=0.8.0 || >=0.9.0",
31-
"graphql-compose": ">=1.20.1",
32-
"graphql-compose-connection": ">=2.2.0",
30+
"graphql-compose": ">=1.20.3",
31+
"graphql-compose-connection": ">=2.2.1",
3332
"mongoose": ">=4.0.0"
3433
},
3534
"devDependencies": {
@@ -49,8 +48,8 @@
4948
"eslint-plugin-prettier": "^2.1.1",
5049
"flow-bin": "^0.47.0",
5150
"graphql": "^0.10.1",
52-
"graphql-compose": "^1.20.1",
53-
"graphql-compose-connection": "^2.2.0",
51+
"graphql-compose": "^1.20.3",
52+
"graphql-compose-connection": "^2.2.1",
5453
"jest": "^20.0.4",
5554
"mongodb-memory-server": "^1.1.2",
5655
"mongoose": "^4.10.4",
@@ -76,9 +75,10 @@
7675
"lint": "eslint src test *.js",
7776
"test": "jest",
7877
"watch": "jest --watch",
79-
"all": "npm run test && npm run lint && ./node_modules/.bin/flow",
80-
"link": "yarn build && yarn link graphql && yarn link graphql-compose && yarn link graphql-compose-connection && yarn link mongoose && yarn link",
81-
"unlink": "yarn unlink graphql && yarn unlink graphql-compose && yarn unlink graphql-compose-connection && yarn unlink mongoose && yarn add graphql graphql-compose graphql-compose-connection mongoose",
78+
"flow": "./node_modules/.bin/flow stop && ./node_modules/.bin/flow",
79+
"all": "npm run test && npm run lint && npm run flow",
80+
"link": "yarn build && yarn link graphql-compose && yarn link graphql-compose-connection && yarn link mongoose && yarn link",
81+
"unlink": "yarn unlink graphql-compose && yarn unlink graphql-compose-connection && yarn unlink mongoose && yarn add graphql-compose graphql-compose-connection mongoose --dev",
8282
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
8383
}
8484
}

src/__tests__/composeWithMongoose-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ describe('composeWithMongoose ->', () => {
170170
},
171171
});
172172
const filterArgInFindOne = typeComposer.getResolver('findOne').getArg('filter');
173+
// $FlowFixMe
173174
const inputConposer = new InputTypeComposer(filterArgInFindOne.type);
174175
expect(inputConposer.isRequired('age')).toBe(true);
175176
});

src/__tests__/fieldConverter-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ describe('fieldConverter', () => {
4545

4646
it('should throw Exception, if model does `schema.path` property', () => {
4747
expect(() => {
48+
// $FlowFixMe
4849
getFieldsFromModel({ a: 1 });
4950
}).toThrowError(/incorrect mongoose model/);
5051
expect(() => {
52+
// $FlowFixMe
5153
getFieldsFromModel({ schema: {} });
5254
}).toThrowError(/incorrect mongoose model/);
5355
});
@@ -57,15 +59,19 @@ describe('fieldConverter', () => {
5759
it('should throw error on incorrect mongoose field', () => {
5860
const err = /incorrect mongoose field/;
5961
expect(() => {
62+
// $FlowFixMe
6063
deriveComplexType();
6164
}).toThrowError(err);
6265
expect(() => {
66+
// $FlowFixMe
6367
deriveComplexType(123);
6468
}).toThrowError(err);
6569
expect(() => {
70+
// $FlowFixMe
6671
deriveComplexType({ a: 1 });
6772
}).toThrowError(err);
6873
expect(() => {
74+
// $FlowFixMe
6975
deriveComplexType({ path: 'name' });
7076
}).toThrowError(err);
7177
expect(() => {
@@ -90,7 +96,9 @@ describe('fieldConverter', () => {
9096

9197
it('schould derive ENUM', () => {
9298
expect(deriveComplexType(fields.gender)).toBe(ComplexTypes.ENUM);
99+
// $FlowFixMe
93100
expect(deriveComplexType(fields.languages.schema.paths.ln)).toBe(ComplexTypes.ENUM);
101+
// $FlowFixMe
94102
expect(deriveComplexType(fields.languages.schema.paths.sk)).toBe(ComplexTypes.ENUM);
95103
});
96104

@@ -146,6 +154,7 @@ describe('fieldConverter', () => {
146154

147155
it('should has string in ofType', () => {
148156
const skillsType = arrayToGraphQL(fields.skills);
157+
// $FlowFixMe
149158
expect(skillsType.ofType.name).toBe('String');
150159
});
151160
});
@@ -163,7 +172,9 @@ describe('fieldConverter', () => {
163172

164173
it('should pass all enum values to GQ type', () => {
165174
const genderEnum = enumToGraphQL(fields.gender);
175+
// $FlowFixMe
166176
expect(genderEnum._values.length).toBe(fields.gender.enumValues.length);
177+
// $FlowFixMe
167178
expect(genderEnum._values[0].value).toBe(fields.gender.enumValues[0]);
168179
});
169180
});
@@ -176,6 +187,7 @@ describe('fieldConverter', () => {
176187

177188
it('should have embedded fields', () => {
178189
const embeddedType = embeddedToGraphQL(fields.contacts);
190+
// $FlowFixMe
179191
const embeddedFields = embeddedType._typeConfig.fields();
180192
expect(embeddedFields.email).toBeTruthy();
181193
expect(embeddedFields.locationId).toBeTruthy();
@@ -211,6 +223,7 @@ describe('fieldConverter', () => {
211223
}
212224
}`
213225
);
226+
// $FlowFixMe
214227
expect(result.data.user).toEqual({
215228
name: 'Test empty subDoc',
216229
subDoc: null,
@@ -253,6 +266,7 @@ describe('fieldConverter', () => {
253266
}
254267
}`
255268
);
269+
// $FlowFixMe
256270
expect(result2.data.user).toEqual({
257271
name: 'Test non empty subDoc',
258272
subDoc: {
@@ -265,6 +279,7 @@ describe('fieldConverter', () => {
265279

266280
describe('documentArrayToGraphQL()', () => {
267281
const languagesType = documentArrayToGraphQL(fields.languages);
282+
// $FlowFixMe
268283
const languagesFields = languagesType.ofType._typeConfig.fields();
269284

270285
it('should produce GraphQLList', () => {
@@ -273,6 +288,7 @@ describe('fieldConverter', () => {
273288

274289
it('should has Language type in ofType', () => {
275290
// see src/__mocks__/languageSchema.js where type name `Language` is defined
291+
// $FlowFixMe
276292
expect(languagesType.ofType.name).toBe('Language');
277293
});
278294

@@ -323,7 +339,9 @@ describe('fieldConverter', () => {
323339
}
324340
}`;
325341
const result = await graphql.graphql(schema, query);
342+
// $FlowFixMe
326343
expect(result.data.user.name).toBe(user.name);
344+
// $FlowFixMe
327345
expect(result.data.user.someDynamic).toEqual(user.someDynamic);
328346
});
329347
});

src/__tests__/typeStorage-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ describe('typeStorage', () => {
2121
describe('getOrSet() method', () => {
2222
it('should return existed value', () => {
2323
typeStorage.clear();
24-
typeStorage.set(123, 456);
25-
expect(typeStorage.getOrSet(123, 'any')).toBe(456);
24+
typeStorage.set('Type1', 456);
25+
expect(typeStorage.getOrSet('Type1', 'any')).toBe(456);
2626
});
2727

2828
it('should set new value and return it, if key not exists', () => {
2929
typeStorage.clear();
30-
expect(typeStorage.getOrSet(123, 456)).toBe(456);
31-
expect(typeStorage.get(123)).toBe(456);
30+
expect(typeStorage.getOrSet('Type2', 456)).toBe(456);
31+
expect(typeStorage.get('Type2')).toBe(456);
3232
});
3333

3434
it('should not set new value if it is empty', () => {
3535
typeStorage.clear();
36-
expect(typeStorage.getOrSet(123, null)).toBe(null);
37-
expect(typeStorage.has(123)).toBe(false);
36+
expect(typeStorage.getOrSet('Type3', null)).toBe(null);
37+
expect(typeStorage.has('Type3')).toBe(false);
3838
});
3939
});
4040
});

src/composeWithMongoose.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { getUniqueIndexes, extendByReversedIndexes } from './utils/getIndexesFro
99

1010
import type {
1111
MongooseModelT,
12-
typeConverterOpts,
13-
typeConverterResolversOpts,
14-
typeConverterInputTypeOpts,
15-
connectionSortMapOpts,
12+
TypeConverterOpts,
13+
TypeConverterResolversOpts,
14+
TypeConverterInputTypeOpts,
15+
ConnectionSortMapOpts,
1616
} from './definition';
1717

1818
export function composeWithMongoose(
1919
model: MongooseModelT,
20-
opts: typeConverterOpts = {}
20+
opts: TypeConverterOpts = {}
2121
): TypeComposer {
2222
const name: string = (opts && opts.name) || model.modelName;
2323

@@ -86,7 +86,7 @@ export function prepareInputFields(
8686

8787
export function createInputType(
8888
typeComposer: TypeComposer,
89-
inputTypeOpts?: typeConverterInputTypeOpts = {}
89+
inputTypeOpts?: TypeConverterInputTypeOpts = {}
9090
): void {
9191
const inputTypeComposer = typeComposer.getInputTypeComposer();
9292

@@ -106,7 +106,7 @@ export function createInputType(
106106
export function createResolvers(
107107
model: MongooseModelT,
108108
typeComposer: TypeComposer,
109-
opts: typeConverterResolversOpts
109+
opts: TypeConverterResolversOpts
110110
): void {
111111
const names = resolvers.getAvailableNames();
112112
names.forEach(resolverName => {
@@ -127,7 +127,7 @@ export function createResolvers(
127127
export function prepareConnectionResolver(
128128
model: MongooseModelT,
129129
typeComposer: TypeComposer,
130-
opts: connectionSortMapOpts
130+
opts: ConnectionSortMapOpts
131131
) {
132132
const uniqueIndexes = extendByReversedIndexes(getUniqueIndexes(model), { reversedFirst: true });
133133
const sortConfigs = {};

0 commit comments

Comments
 (0)