Skip to content

Commit 1a0c558

Browse files
committed
chore: fix typescript errors for mongoose v6
1 parent df6f259 commit 1a0c558

File tree

6 files changed

+13
-31
lines changed

6 files changed

+13
-31
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"test": "yarn coverage && yarn lint",
6565
"link": "yarn build && yarn link graphql-compose && yarn link graphql-compose-connection && yarn link graphql-compose-pagination && yarn link mongoose && yarn link",
6666
"unlink": "rimraf node_modules && yarn install",
67-
"semantic-release": "semantic-release"
67+
"semantic-release": "semantic-release",
68+
"test-prev-vers": "yarn add [email protected] --dev && yarn lint && git checkout HEAD -- package.json yarn.lock"
6869
}
6970
}

src/__tests__/github_issues/141-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('issue #141 - createOne with custom id (not MongoId)', () => {
111111
_id: { type: ComplexIdSchema },
112112
name: { type: String, required: true },
113113
});
114-
const ComplexModel = mongoose.model('Complex', ComplexSchema);
114+
const ComplexModel = mongoose.model<any>('Complex', ComplexSchema);
115115
const ComplexTC = composeMongoose(ComplexModel);
116116

117117
expect(ComplexTC.getFieldTypeName('_id')).toBe('Complex_id!');

src/__tests__/github_issues/315-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const BookSchema = new mongoose.Schema({
1212
date: { type: Date },
1313
});
1414

15-
const BookModel = mongoose.model('Book', BookSchema);
15+
const BookModel = mongoose.model<any>('Book', BookSchema);
1616

1717
const BookTC = composeMongoose(BookModel, { schemaComposer });
1818
const booksFindMany = BookTC.mongooseResolvers.findMany().addFilterArg({

src/__tests__/github_issues/358-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const WithoutSubSchema = new mongoose.Schema({
1515
},
1616
});
1717

18-
const WithSubModel = mongoose.model('WithSubModel', WithSubSchema);
19-
const WithoutSubModel = mongoose.model('WithoutSubModel', WithoutSubSchema);
18+
const WithSubModel = mongoose.model<any>('WithSubModel', WithSubSchema);
19+
const WithoutSubModel = mongoose.model<any>('WithoutSubModel', WithoutSubSchema);
2020

2121
describe('defaultsAsNonNull falsely reports non-nullability for subdocuments that have a Schema - issue #358', () => {
2222
it('with sub schema', async () => {

src/__tests__/github_issues/370-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const UserSchema = new mongoose.Schema({
2020
},
2121
],
2222
});
23-
const UserModel = mongoose.model('User', UserSchema);
23+
const UserModel = mongoose.model<any>('User', UserSchema);
2424
const UserTC = composeMongoose(UserModel, { schemaComposer });
2525

2626
const OrganizationSchema = new mongoose.Schema({
@@ -29,7 +29,7 @@ const OrganizationSchema = new mongoose.Schema({
2929
required: true,
3030
},
3131
});
32-
const OrganizationModel = mongoose.model('Organization', OrganizationSchema);
32+
const OrganizationModel = mongoose.model<any>('Organization', OrganizationSchema);
3333
const OrganizationTC = composeMongoose(OrganizationModel, { schemaComposer });
3434

3535
UserTC.addRelation('organizations', {

src/resolvers/__tests__/connection-test.ts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -236,41 +236,22 @@ describe('connection() resolver', () => {
236236
});
237237

238238
it('should call `beforeQuery` method with non-executed `query` as arg', async () => {
239-
const mongooseActions: any[] = [];
240-
241-
UserModel.base.set('debug', function debugMongoose(...args: any) {
242-
mongooseActions.push(args);
243-
});
244-
239+
expect.assertions(4);
240+
let extendedQuery: Query<any, any>;
245241
const resolver = connection(UserModel, UserTC);
246-
247-
if (!resolver) {
248-
throw new Error('resolver is undefined');
249-
}
250-
251242
const result = await resolver.resolve({
252243
args: {},
253244
beforeQuery: (query: any, rp: ExtendedResolveParams) => {
254245
expect(query).toBeInstanceOf(Query);
255246
expect(rp.model).toBe(UserModel);
256247
// modify query before execution
257-
return query.where({ _id: user1.id }).limit(1989);
248+
extendedQuery = query.where({ _id: user1.id }).limit(1989);
249+
return extendedQuery;
258250
},
259251
});
260252

261-
expect(mongooseActions).toEqual([
262-
[
263-
'users',
264-
'find',
265-
{ _id: user1._id },
266-
{
267-
limit: 1989,
268-
projection: {},
269-
},
270-
],
271-
]);
272-
273253
expect(result.edges).toHaveLength(1);
254+
expect(result.edges[0].node._id.toString()).toEqual(user1.id.toString());
274255
});
275256

276257
it('should override result with `beforeQuery`', async () => {

0 commit comments

Comments
 (0)