Skip to content

Commit 307946c

Browse files
committed
chore: update
1 parent d391104 commit 307946c

File tree

9 files changed

+27
-24
lines changed

9 files changed

+27
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"lint": "yarn eslint && yarn tscheck",
6161
"eslint": "eslint --ext .ts ./src",
6262
"tscheck": "tsc --noEmit",
63-
"test": "yarn coverage && yarn lint",
63+
"test": "jest",
6464
"link": "yarn build && yarn link graphql-compose && yarn link graphql-compose-connection && yarn link graphql-compose-pagination && yarn link mongoose && yarn link",
6565
"unlink": "rimraf node_modules && yarn install",
6666
"semantic-release": "semantic-release",

src/__tests__/github_issues/117-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('issue #117', () => {
6060

6161
const player1 = await PlayerModel.create({ name: '1', surname: '1', sex: 'm' });
6262
const player2 = await PlayerModel.create({ name: '2', surname: '2', sex: 'f' });
63-
const game = await GameModel.create({ players: [player1, player2] });
63+
const game = await GameModel.create({ players: [player1._id, player2._id] });
6464

6565
const id = game._id;
6666
const g1 = await GameModel.findOne({ _id: id }).populate('players');

src/fieldsConverter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import GraphQLBSONDecimal from './types/BSONDecimal';
1717
type MongooseFieldT = {
1818
path?: string;
1919
instance: string;
20+
// mongoose 8
2021
caster?: any;
22+
// mongoose 9
23+
embeddedSchemaType?: any;
2124
options?: {
2225
description?: string;
2326
alias?: string;
@@ -330,14 +333,14 @@ export function arrayToGraphQL(
330333
prefix: string = '',
331334
schemaComposer: SchemaComposer<any>
332335
): ComposeOutputTypeDefinition<any> {
333-
if (!field || !field.caster) {
336+
if (!field || (!field.caster && !field.embeddedSchemaType)) {
334337
throw new Error(
335338
'You provide incorrect mongoose field to `arrayToGraphQL()`. ' +
336339
'Correct field should contain `caster` property.'
337340
);
338341
}
339342

340-
const unwrappedField = { ...field.caster };
343+
const unwrappedField = { ...(field.caster || field.embeddedSchemaType) } as MongooseFieldT;
341344

342345
const outputType: any = convertFieldToGraphQL(unwrappedField, prefix, schemaComposer);
343346
return [outputType];

src/resolvers/helpers/__tests__/filter-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ describe('Resolver helper `filter` ->', () => {
146146

147147
it('should not call query.where if args.filter is empty', () => {
148148
filterHelper(resolveParams, aliases);
149-
expect(spyWhereFn).not.toBeCalled();
149+
expect(spyWhereFn).not.toHaveBeenCalled();
150150
});
151151

152152
it('should call query.where if args.filter is provided', () => {
153153
resolveParams.args = {
154154
filter: { name: 'nodkz' },
155155
};
156156
filterHelper(resolveParams, aliases);
157-
expect(spyWhereFn).toBeCalledWith({ n: 'nodkz' });
157+
expect(spyWhereFn).toHaveBeenCalledWith({ n: 'nodkz' });
158158
});
159159

160160
it('should convert deep object in args.filter to dotted object', () => {
@@ -167,7 +167,7 @@ describe('Resolver helper `filter` ->', () => {
167167
},
168168
};
169169
filterHelper(resolveParams, aliases);
170-
expect(spyWhereFn).toBeCalledWith({
170+
expect(spyWhereFn).toHaveBeenCalledWith({
171171
'n.first': 'Pavel',
172172
age: 30,
173173
});
@@ -180,7 +180,7 @@ describe('Resolver helper `filter` ->', () => {
180180
},
181181
};
182182
filterHelper(resolveParams, aliases);
183-
expect(spyWhereFn).toBeCalledWith({ age: { $gt: 10, $lt: 20 } });
183+
expect(spyWhereFn).toHaveBeenCalledWith({ age: { $gt: 10, $lt: 20 } });
184184
});
185185

186186
it('should add rawQuery to query', () => {

src/resolvers/helpers/__tests__/limit-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ describe('Resolver helper `limit` ->', () => {
3333

3434
it('should not call query.limit if args.limit is empty', () => {
3535
limitHelper(resolveParams);
36-
expect(spyFn).not.toBeCalled();
36+
expect(spyFn).not.toHaveBeenCalled();
3737
});
3838
it('should call query.limit if args.limit is provided', () => {
3939
resolveParams.args = { limit: 333 };
4040
limitHelper(resolveParams);
41-
expect(spyFn).toBeCalledWith(333);
41+
expect(spyFn).toHaveBeenCalledWith(333);
4242
});
4343
it('should convert string to int in args.limit', () => {
4444
resolveParams.args = { limit: '444' };
4545
limitHelper(resolveParams);
46-
expect(spyFn).toBeCalledWith(444);
46+
expect(spyFn).toHaveBeenCalledWith(444);
4747
});
4848
});
4949
});

src/resolvers/helpers/__tests__/projection-test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,51 @@ describe('Resolver helper `projection` ->', () => {
1616

1717
it('should not call query.select if projection is empty', () => {
1818
projectionHelper(resolveParams);
19-
expect(spyFn).not.toBeCalled();
19+
expect(spyFn).not.toHaveBeenCalled();
2020
});
2121

2222
it('should call query.select if projection is provided', () => {
2323
resolveParams.projection = { name: 1, age: 1 };
2424
projectionHelper(resolveParams, { name: 'n' });
25-
expect(spyFn).toBeCalledWith({ n: true, age: true });
25+
expect(spyFn).toHaveBeenCalledWith({ n: true, age: true });
2626
});
2727

2828
it('should make projection fields flat', () => {
2929
resolveParams.projection = { name: { first: 1, last: 1 } };
3030
projectionHelper(resolveParams, { name: 'n' });
31-
expect(spyFn).toBeCalledWith({ 'n.first': true, 'n.last': true });
31+
expect(spyFn).toHaveBeenCalledWith({ 'n.first': true, 'n.last': true });
3232
});
3333

3434
it('should make projection fields flat with nested aliases', () => {
3535
resolveParams.projection = { name: { first: 1, last: 1 } };
3636
projectionHelper(resolveParams, { name: { __selfAlias: 'n', first: 'f', last: 'l' } });
37-
expect(spyFn).toBeCalledWith({ 'n.f': true, 'n.l': true });
37+
expect(spyFn).toHaveBeenCalledWith({ 'n.f': true, 'n.l': true });
3838
});
3939

4040
it('should not call query.select if projection has * key', () => {
4141
resolveParams.projection = { '*': true };
4242
projectionHelper(resolveParams);
43-
expect(spyFn).not.toBeCalled();
43+
expect(spyFn).not.toHaveBeenCalled();
4444
});
4545

4646
describe('projection operators', () => {
4747
// see more details here https://docs.mongodb.com/v3.2/reference/operator/projection/meta/
4848
it('should pass $meta non-flatten', () => {
4949
resolveParams.projection = { score: { $meta: 'textScore' } };
5050
projectionHelper(resolveParams);
51-
expect(spyFn).toBeCalledWith({ score: { $meta: 'textScore' } });
51+
expect(spyFn).toHaveBeenCalledWith({ score: { $meta: 'textScore' } });
5252
});
5353

5454
it('should pass $slice non-flatten', () => {
5555
resolveParams.projection = { comments: { $slice: 5 } };
5656
projectionHelper(resolveParams);
57-
expect(spyFn).toBeCalledWith({ comments: { $slice: 5 } });
57+
expect(spyFn).toHaveBeenCalledWith({ comments: { $slice: 5 } });
5858
});
5959

6060
it('should pass $elemMatch non-flatten', () => {
6161
resolveParams.projection = { students: { $elemMatch: { school: 102 } } };
6262
projectionHelper(resolveParams);
63-
expect(spyFn).toBeCalledWith({ students: { $elemMatch: { school: 102 } } });
63+
expect(spyFn).toHaveBeenCalledWith({ students: { $elemMatch: { school: 102 } } });
6464
});
6565
});
6666
});

src/resolvers/helpers/__tests__/skip-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ describe('Resolver helper `skip` ->', () => {
2323

2424
it('should not call query.skip if args.skip is empty', () => {
2525
skipHelper(resolveParams);
26-
expect(spyFn).not.toBeCalled();
26+
expect(spyFn).not.toHaveBeenCalled();
2727
});
2828
it('should call query.skip if args.skip is provided', () => {
2929
resolveParams.args = { skip: 333 };
3030
skipHelper(resolveParams);
31-
expect(spyFn).toBeCalledWith(333);
31+
expect(spyFn).toHaveBeenCalledWith(333);
3232
});
3333
it('should convert skip to int in args.skip', () => {
3434
resolveParams.args = { skip: '444' };
3535
skipHelper(resolveParams);
36-
expect(spyFn).toBeCalledWith(444);
36+
expect(spyFn).toHaveBeenCalledWith(444);
3737
});
3838
});
3939
});

src/resolvers/helpers/__tests__/sort-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('Resolver helper `sort` ->', () => {
111111
const sortValue = { _id: 1 };
112112
resolveParams.args = { sort: sortValue };
113113
sortHelper(resolveParams);
114-
expect(spyFn).toBeCalledWith(sortValue);
114+
expect(spyFn).toHaveBeenCalledWith(sortValue);
115115
});
116116
});
117117
});

src/types/MongoID.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const GraphQLMongoID = new GraphQLScalarType({
1212
'But MongoDB also may accepts string or integer as correct values for _id field.',
1313
serialize: String,
1414
parseValue(value: any) {
15-
if (!ObjectId.isValid(value) && typeof value !== 'string') {
15+
if (!ObjectId.isValid(value) && (typeof value !== 'string' && typeof value !== 'number')) {
1616
throw new TypeError('Field error: value is an invalid ObjectId');
1717
}
1818
return value;

0 commit comments

Comments
 (0)