Skip to content

Commit 55959e1

Browse files
committed
chore: update
1 parent 2bd4231 commit 55959e1

File tree

10 files changed

+316
-1408
lines changed

10 files changed

+316
-1408
lines changed

.github/workflows/nodejs.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
1+
# This workflow will do a clean installation of node dependencies, build the source code and run tests across different versions of node
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
33

44
name: Node.js CI
55

66
on: [push, pull_request]
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
tests:
1014
runs-on: ubuntu-latest
@@ -13,17 +17,13 @@ jobs:
1317
contents: write
1418
strategy:
1519
matrix:
16-
node-version: [16.x, 18.x, 20.x]
20+
node-version: [20.x, 22.x, 24.x]
1721
steps:
1822
- run: echo "🎉 The job was triggered by a ${{ github.event_name }} event."
19-
- uses: styfle/cancel-workflow-action@0.12.0
20-
with:
21-
workflow_id: nodejs.yml
22-
access_token: ${{ secrets.GITHUB_TOKEN }}
2323
- uses: FranzDiebold/github-env-vars-action@v2
24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v6
2525
- name: Use Node.js ${{ matrix.node-version }}
26-
uses: actions/setup-node@v4
26+
uses: actions/setup-node@v6
2727
with:
2828
node-version: ${{ matrix.node-version }}
2929
- name: Install node_modules
@@ -41,7 +41,7 @@ jobs:
4141
env:
4242
CI: true
4343
- name: Send codecov.io stats
44-
if: matrix.node-version == '18.x'
44+
if: matrix.node-version == '20.x'
4545
run: bash <(curl -s https://codecov.io/bash) || echo ''
4646

4747
publish:
@@ -53,11 +53,11 @@ jobs:
5353
contents: write
5454
pull-requests: write
5555
steps:
56-
- uses: actions/checkout@v4
57-
- name: Use Node.js 18
58-
uses: actions/setup-node@v4
56+
- uses: actions/checkout@v6
57+
- name: Use Node.js 28.x
58+
uses: actions/setup-node@v6
5959
with:
60-
node-version: 18.x
60+
node-version: 28.x
6161
- name: Install node_modules
6262
run: yarn install
6363
- name: Build

src/__mocks__/userModel.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { mongoose, Schema } from './mongooseCommon';
1+
import mongoose, { Document, Schema } from 'mongoose';
22
import ContactsSchema from './contactsSchema';
33
import enumEmployment from './enumEmployment';
44
import LanguageSchema from './languageSchema';
5-
import { Document } from 'mongoose';
5+
// @ts-ignore
6+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7+
import type { bsonType } from 'bson';
68

79
const UserSchema = new Schema(
810
{
@@ -36,7 +38,7 @@ const UserSchema = new Schema(
3638
description: 'Full years',
3739
required() {
3840
// in graphql this field should be Nullable
39-
return (this as any).name === 'Something special';
41+
return this.name === 'Something special';
4042
},
4143
},
4244

@@ -146,8 +148,8 @@ UserSchema.virtual('nameVirtual').get(function (this: any) {
146148
});
147149

148150
export interface IUser extends Document {
149-
id: any;
150-
_id: any;
151+
id: mongoose.Types.ObjectId;
152+
n?: string;
151153
name?: string;
152154
age?: number;
153155
gender?: string;
@@ -158,6 +160,7 @@ export interface IUser extends Document {
158160
email: string;
159161
skype?: string;
160162
};
163+
salary?: mongoose.Types.Decimal128;
161164
}
162165

163166
const UserModel = mongoose.model<IUser>('User', UserSchema);

src/__tests__/github_issues/253-test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const CarSchema = new Schema(
99
{ s: { type: Number, required: true, alias: 'speed' }, aaa: SubCarSchema },
1010
{ discriminatorKey: 't' }
1111
);
12+
1213
const Car = mongoose.model('Car', CarSchema);
1314

1415
const TimeMachineSchema = new Schema(
1516
{ f: { type: Number, required: true, alias: 'fluxCompensatorVersion' } },
1617
{ discriminatorKey: 't' }
1718
);
19+
1820
const TimeMachine = Car.discriminator('TimeMachine', TimeMachineSchema);
1921

2022
const CarDTC = composeWithMongooseDiscriminators(Car);
@@ -29,8 +31,11 @@ schemaComposer.Query.addFields({
2931
beforeAll(async () => {
3032
await mongoose.createConnection();
3133
// todo find away to get the alias types?
32-
await TimeMachine.create({ speed: 300, fluxCompensatorVersion: 5 });
34+
// await TimeMachine.create({ speed: 300, fluxCompensatorVersion: 5 });
35+
const o = new TimeMachine({ speed: 300, fluxCompensatorVersion: 5 });
36+
await o.save();
3337
});
38+
3439
afterAll(() => mongoose.disconnect());
3540

3641
describe('issue #253 - Consider aliases from discriminators during preparation', () => {

src/__tests__/github_issues/268-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const UserSchema = new mongoose.Schema({
1010
name: { type: String, required: true },
1111
age: { type: Number },
1212
});
13-
interface IUser extends Document {
14-
_id: number;
13+
interface IUser extends Document<number> {
1514
name: string;
1615
age?: number;
1716
}

src/__tests__/github_issues/271-test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ interface IAuthor {
2929
isAlive: boolean;
3030
}
3131

32-
interface IBook extends Document {
33-
_id: number;
32+
interface IBook extends Document<number> {
3433
title: string;
3534
author: IAuthor;
3635
pageCount?: number;
@@ -158,7 +157,7 @@ describe('nested projections with aliases - issue #271', () => {
158157
query {
159158
booksMany {
160159
bookSize
161-
author {
160+
author {
162161
isAbove100
163162
}
164163
}

src/__tests__/github_issues/286-test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const UserSchema = new mongoose.Schema({
1010
name: { type: String, required: true },
1111
age: { type: Number },
1212
});
13-
interface IUser extends Document {
14-
_id: number;
13+
interface IUser extends Document<number> {
1514
name: string;
1615
age?: number;
1716
}

src/resolvers/__tests__/createMany-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ObjectTypeComposer, Resolver, schemaComposer } from 'graphql-compose';
22
import { GraphQLList, GraphQLNonNull } from 'graphql-compose/lib/graphql';
33
import { mongoose } from '../../__mocks__/mongooseCommon';
4-
import { IUser, UserModel } from '../../__mocks__/userModel';
4+
import { IUser, UserModel, UserSchema } from '../../__mocks__/userModel';
55
import { convertModelToGraphQL } from '../../fieldsConverter';
66
import { createMany } from '../createMany';
77
import { ExtendedResolveParams } from '..';
@@ -208,9 +208,9 @@ describe('createMany() ->', () => {
208208

209209
it('should execute hooks on save', async () => {
210210
schemaComposer.clear();
211-
const ClonedUserSchema = UserModel.schema.clone();
211+
const ClonedUserSchema: typeof UserSchema = UserModel.schema.clone();
212212

213-
ClonedUserSchema.pre<IUser>('save', function () {
213+
ClonedUserSchema.pre<IUser>('save', function (this: IUser) {
214214
this.name = 'ChangedAgain';
215215
this.age = 18;
216216
});

src/resolvers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const resolverFactory = {
6969
connection,
7070
};
7171

72-
export {
72+
export type {
7373
CountResolverOpts,
7474
FindByIdResolverOpts,
7575
FindByIdsResolverOpts,

tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
"forceConsistentCasingInFileNames": true,
1919
"isolatedModules": true,
2020
"lib": ["es2017", "esnext.asynciterable"],
21-
"types": ["node", "jest"],
21+
"types": ["node", "jest", "bson"],
2222
"baseUrl": ".",
2323
"rootDir": "./src"
2424
},
2525
"include": ["src/**/*"],
26-
"exclude": [
27-
"./node_modules"
28-
]
26+
"exclude": ["./node_modules"]
2927
}

0 commit comments

Comments
 (0)