From 818d3fb46a1bc82eb23036d2deddef2ed515b886 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Tue, 31 Oct 2023 15:51:58 -0400 Subject: [PATCH 01/26] chore: update mongoose 8 --- .editorconfig | 57 + jest.config.js | 11 +- package.json | 31 +- src/__mocks__/mongooseCommon.ts | 4 +- src/__tests__/github_issues/268-test.ts | 4 +- src/__tests__/github_issues/286-test.ts | 30 +- .../helpers/__tests__/filter-test.ts | 6 +- .../helpers/__tests__/filterOperators-test.ts | 4 +- src/resolvers/helpers/validate.ts | 5 +- src/resolvers/updateMany.ts | 1 + yarn.lock | 3244 ++++++++--------- 11 files changed, 1541 insertions(+), 1856 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..e1003543 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,57 @@ +root = true + +[*] +charset = utf-8 +max_line_length = 120 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[{Makefile, makefile}] +indent_style = tab + +[*.go] +indent_style = tab + +[*.proto] +indent_size = 2 + +[*.swift] +indent_size = 4 + +[*.tmpl] +indent_size = 2 + +[{*.js, *.ts, *.jsx, *.tsx}] +indent_size = 2 + +[*.html] +indent_size = 2 + +[*.bat] +end_of_line = crlf + +[*.{json, yml, yaml}] +indent_size = 2 + +[.{babelrc, eslintrc}] +indent_size = 2 + +[{Fastfile, .buckconfig, BUCK}] +indent_size = 2 + +[*.diff] +indent_size = 1 + +[*.m] +indent_size = 1 +indent_style = space + +[*.java] +indent_size = 4 +indent_style = space + +[*.md] +trim_trailing_whitespace = false diff --git a/jest.config.js b/jest.config.js index 21f6e291..64c814ad 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,16 +1,13 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', - globals: { - 'ts-jest': { + moduleFileExtensions: ['ts', 'js'], + transform: { + '^.+\\.ts$': ['ts-jest', { tsconfig: '/tsconfig.json', isolatedModules: true, diagnostics: false, - }, - }, - moduleFileExtensions: ['ts', 'js'], - transform: { - '^.+\\.ts$': 'ts-jest', + }], '^.+\\.js$': 'babel-jest', }, roots: ['/src'], diff --git a/package.json b/package.json index 9d1d70bd..57a7bbad 100644 --- a/package.json +++ b/package.json @@ -33,24 +33,24 @@ "mongoose": "^7.0.0 || ^6.0.0 || ^5.0.0 || ^4.4.0" }, "devDependencies": { - "@types/jest": "28.1.8", - "@typescript-eslint/eslint-plugin": "5.54.0", - "@typescript-eslint/parser": "5.54.0", - "eslint": "8.35.0", + "@types/jest": "29.5.7", + "@typescript-eslint/eslint-plugin": "6.9.1", + "@typescript-eslint/parser": "6.9.1", + "eslint": "8.52.0", "eslint-config-airbnb-base": "15.0.0", - "eslint-config-prettier": "8.6.0", - "eslint-plugin-import": "2.27.5", - "eslint-plugin-prettier": "4.2.1", - "graphql": "16.6.0", + "eslint-config-prettier": "9.0.0", + "eslint-plugin-import": "2.29.0", + "eslint-plugin-prettier": "5.0.1", + "graphql": "16.8.1", "graphql-compose": "9.0.10", - "jest": "28.1.3", - "mongodb-memory-server": "8.11.5", - "mongoose": "7.0.0", - "prettier": "2.8.4", + "jest": "29.7.0", + "mongodb-memory-server": "9.0.1", + "mongoose": "8.0.0", + "prettier": "3.0.3", "request": "2.88.2", - "rimraf": "4.1.3", - "ts-jest": "28.0.8", - "typescript": "4.9.5" + "rimraf": "5.0.5", + "ts-jest": "29.1.1", + "typescript": "5.2.2" }, "scripts": { "prepare": "tsc -p ./tsconfig.build.json", @@ -64,6 +64,7 @@ "link": "yarn build && yarn link graphql-compose && yarn link graphql-compose-connection && yarn link graphql-compose-pagination && yarn link mongoose && yarn link", "unlink": "rimraf node_modules && yarn install", "semantic-release": "semantic-release", + "test-prev-vers-7": "yarn add mongoose@7.6.4 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock", "test-prev-vers-6": "yarn add mongoose@6.1.2 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock", "test-prev-vers-5": "yarn add mongoose@5.13.8 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock" } diff --git a/src/__mocks__/mongooseCommon.ts b/src/__mocks__/mongooseCommon.ts index eb8cfb95..ef375225 100644 --- a/src/__mocks__/mongooseCommon.ts +++ b/src/__mocks__/mongooseCommon.ts @@ -1,6 +1,6 @@ /* eslint-disable no-param-reassign, no-console */ -import mongoose from 'mongoose'; +import mongoose, {version as MongooseVersion} from 'mongoose'; import MongoMemoryServer from 'mongodb-memory-server-core'; const { Schema, Types } = mongoose; @@ -15,7 +15,7 @@ mongoose.createConnection = (async () => { // originalConnect.bind(mongoose)(mongoUri, { useMongoClient: true }); // mongoose 4 originalConnect.bind(mongoose)( mongoUri, - { + Number(MongooseVersion.charAt(0)) > 7 ? {} : { useNewUrlParser: true, useUnifiedTopology: true, } as any /* for tests compatibility with mongoose v5 & v6 */ diff --git a/src/__tests__/github_issues/268-test.ts b/src/__tests__/github_issues/268-test.ts index 97c9f97b..dd4e6291 100644 --- a/src/__tests__/github_issues/268-test.ts +++ b/src/__tests__/github_issues/268-test.ts @@ -38,7 +38,7 @@ describe('issue #268 - Allow to provide `suffix` option for resolvers configs', const createOne1 = UserTC.mongooseResolvers.createOne(); expect(createOne1.getTypeName()).toBe('CreateOneUserPayload'); expect(createOne1.getArgITC('record').toSDL()).toMatchInlineSnapshot(` - "\\"\\"\\"\\"\\"\\" + """"""" input CreateOneUserInput { name: String! age: Float @@ -53,7 +53,7 @@ describe('issue #268 - Allow to provide `suffix` option for resolvers configs', }); expect(createOne2.getTypeName()).toBe('CreateOneUserShortPayload'); expect(createOne2.getArgITC('record').toSDL()).toMatchInlineSnapshot(` - "\\"\\"\\"\\"\\"\\" + """"""" input CreateOneUserShortInput { _id: Int name: String! diff --git a/src/__tests__/github_issues/286-test.ts b/src/__tests__/github_issues/286-test.ts index 2b14f83b..571b238c 100644 --- a/src/__tests__/github_issues/286-test.ts +++ b/src/__tests__/github_issues/286-test.ts @@ -40,13 +40,13 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type CreateManyUserPayload { - \\"\\"\\"Documents IDs\\"\\"\\" + """Documents IDs""" recordIds: [Int!]! - \\"\\"\\"Created documents\\"\\"\\" + """Created documents""" records: [User!] - \\"\\"\\"Number of created documents\\"\\"\\" + """Number of created documents""" createdCount: Int! }" `); @@ -58,10 +58,10 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type CreateOneUserPayload { - \\"\\"\\"Document ID\\"\\"\\" + """Document ID""" recordId: Int - \\"\\"\\"Created document\\"\\"\\" + """Created document""" record: User }" `); @@ -73,10 +73,10 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type RemoveByIdUserPayload { - \\"\\"\\"Document ID\\"\\"\\" + """Document ID""" recordId: Int - \\"\\"\\"Removed document\\"\\"\\" + """Removed document""" record: User }" `); @@ -88,7 +88,7 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type RemoveManyUserPayload { - \\"\\"\\"Affected documents number\\"\\"\\" + """Affected documents number""" numAffected: Int }" `); @@ -100,10 +100,10 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type RemoveOneUserPayload { - \\"\\"\\"Document ID\\"\\"\\" + """Document ID""" recordId: Int - \\"\\"\\"Removed document\\"\\"\\" + """Removed document""" record: User }" `); @@ -115,10 +115,10 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type UpdateByIdUserPayload { - \\"\\"\\"Document ID\\"\\"\\" + """Document ID""" recordId: Int - \\"\\"\\"Updated document\\"\\"\\" + """Updated document""" record: User }" `); @@ -130,7 +130,7 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type UpdateManyUserPayload { - \\"\\"\\"Affected documents number\\"\\"\\" + """Affected documents number""" numAffected: Int }" `); @@ -142,10 +142,10 @@ describe('issue #286 - Allow to provide `disableErrorField` option for mutation }); expect(resolver.getTypeComposer().toSDL()).toMatchInlineSnapshot(` "type UpdateOneUserPayload { - \\"\\"\\"Document ID\\"\\"\\" + """Document ID""" recordId: Int - \\"\\"\\"Updated document\\"\\"\\" + """Updated document""" record: User }" `); diff --git a/src/resolvers/helpers/__tests__/filter-test.ts b/src/resolvers/helpers/__tests__/filter-test.ts index b190e446..3ae95316 100644 --- a/src/resolvers/helpers/__tests__/filter-test.ts +++ b/src/resolvers/helpers/__tests__/filter-test.ts @@ -89,8 +89,8 @@ describe('Resolver helper `filter` ->', () => { }); const itc = args.filter.type as InputTypeComposer; expect(itc.hasField('_id')).toBe(true); - expect(itc.hasField('name')).toBe(true); - expect(itc.hasField('age')).toBe(false); + expect(itc.hasField('name')).toBe(false); + expect(itc.hasField('age')).toBe(true); expect(itc.hasField('gender')).toBe(false); }); @@ -104,7 +104,7 @@ describe('Resolver helper `filter` ->', () => { const itc = args.filter.type as InputTypeComposer; expect(itc.hasField('_id')).toBe(true); expect(itc.hasField('name')).toBe(false); - expect(itc.hasField('age')).toBe(false); + expect(itc.hasField('age')).toBe(true); expect(itc.hasField('gender')).toBe(false); }); diff --git a/src/resolvers/helpers/__tests__/filterOperators-test.ts b/src/resolvers/helpers/__tests__/filterOperators-test.ts index fd0405ed..9294666a 100644 --- a/src/resolvers/helpers/__tests__/filterOperators-test.ts +++ b/src/resolvers/helpers/__tests__/filterOperators-test.ts @@ -137,12 +137,13 @@ describe('Resolver helper `filter` ->', () => { '_id', 'employment', 'name', + 'age', 'billingAddress', ]); expect(itc.getFieldITC('_operators').getFieldITC('name').getFieldNames()).toEqual(['exists']); }); it('should respect operators configuration and allow onlyIndexed', () => { - // By default when using onlyIndex, add all indexed fields, then if operators are supplied allow them as well + // By default, when using onlyIndex, add all indexed fields, then if operators are supplied allow them as well addFilterOperators(itc, UserModel, { baseTypeName: 'User', onlyIndexed: true, @@ -155,6 +156,7 @@ describe('Resolver helper `filter` ->', () => { '_id', 'employment', 'name', + 'age', 'billingAddress', ]); expect(itc.getFieldITC('_operators').getFieldITC('name').getFieldNames()).toEqual(['exists']); diff --git a/src/resolvers/helpers/validate.ts b/src/resolvers/helpers/validate.ts index 34763a2f..63ee7d96 100644 --- a/src/resolvers/helpers/validate.ts +++ b/src/resolvers/helpers/validate.ts @@ -1,6 +1,6 @@ import type { Error as MongooseError } from 'mongoose'; import type { Document } from 'mongoose'; -import { version as MongooseVersion } from 'mongoose'; +import { version as MongooseVersion} from 'mongoose'; import { ValidationError } from '../../errors'; export type ValidationErrorData = { @@ -20,7 +20,8 @@ export type ValidationsWithMessage = { }; export async function validateDoc(doc: Document): Promise { - const validations: MongooseError.ValidationError | null = MongooseVersion.startsWith('7') + + const validations: MongooseError.ValidationError | null = Number(MongooseVersion.charAt(0)) > 7 ? doc.validateSync() : await new Promise((resolve) => doc.validate(resolve as any)); diff --git a/src/resolvers/updateMany.ts b/src/resolvers/updateMany.ts index 0e82c23e..488f0545 100644 --- a/src/resolvers/updateMany.ts +++ b/src/resolvers/updateMany.ts @@ -126,6 +126,7 @@ export function updateMany Date: Tue, 31 Oct 2023 15:55:29 -0400 Subject: [PATCH 02/26] chore: update mongoose 8 --- .github/workflows/nodejs.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 6bf97cd0..6742d56f 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -13,7 +13,7 @@ jobs: contents: write strategy: matrix: - node-version: [14.x, 16.x, 18.x] + node-version: [16.x, 18.x, 20.x] steps: - run: echo "🎉 The job was triggered by a ${{ github.event_name }} event." - uses: styfle/cancel-workflow-action@0.11.0 @@ -21,9 +21,9 @@ jobs: workflow_id: nodejs.yml access_token: ${{ secrets.GITHUB_TOKEN }} - uses: FranzDiebold/github-env-vars-action@v2 - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Install node_modules @@ -32,6 +32,10 @@ jobs: run: yarn test env: CI: true + - name: Testing with previous mongoose versions 7 + run: yarn test-prev-vers-7 + env: + CI: true - name: Testing with previous mongoose versions 6 run: yarn test-prev-vers-6 env: @@ -41,7 +45,7 @@ jobs: env: CI: true - name: Send codecov.io stats - if: matrix.node-version == '14.x' + if: matrix.node-version == '18.x' run: bash <(curl -s https://codecov.io/bash) || echo '' publish: @@ -52,11 +56,11 @@ jobs: packages: write contents: write steps: - - uses: actions/checkout@v3 - - name: Use Node.js 14 - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - name: Use Node.js 18 + uses: actions/setup-node@v4 with: - node-version: 14.x + node-version: 18.x - name: Install node_modules run: yarn install - name: Build From 61509046f9ea42ce423b2c9339d310bbdd36e5a6 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Wed, 1 Nov 2023 00:18:02 -0400 Subject: [PATCH 03/26] chore: update mongoose 8 --- src/__mocks__/mongooseCommon.ts | 12 +++++++----- src/resolvers/__tests__/count-test.ts | 2 +- src/resolvers/__tests__/findMany-test.ts | 4 ++-- src/resolvers/__tests__/removeById-test.ts | 6 +++--- .../helpers/__tests__/filter-test.ts | 2 +- src/resolvers/helpers/sort.ts | 12 ++++++------ src/resolvers/helpers/validate.ts | 10 +++++----- src/utils/getIndexesFromModel.ts | 19 +++++++++++++------ 8 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/__mocks__/mongooseCommon.ts b/src/__mocks__/mongooseCommon.ts index ef375225..9c43cfd5 100644 --- a/src/__mocks__/mongooseCommon.ts +++ b/src/__mocks__/mongooseCommon.ts @@ -1,6 +1,6 @@ /* eslint-disable no-param-reassign, no-console */ -import mongoose, {version as MongooseVersion} from 'mongoose'; +import mongoose, { version as MongooseVersion } from 'mongoose'; import MongoMemoryServer from 'mongodb-memory-server-core'; const { Schema, Types } = mongoose; @@ -15,10 +15,12 @@ mongoose.createConnection = (async () => { // originalConnect.bind(mongoose)(mongoUri, { useMongoClient: true }); // mongoose 4 originalConnect.bind(mongoose)( mongoUri, - Number(MongooseVersion.charAt(0)) > 7 ? {} : { - useNewUrlParser: true, - useUnifiedTopology: true, - } as any /* for tests compatibility with mongoose v5 & v6 */ + Number(MongooseVersion[0]) > 7 + ? {} + : ({ + useNewUrlParser: true, + useUnifiedTopology: true, + } as any) /* for tests compatibility with mongoose v5 & v6 */ ); // mongoose 5 // originalConnect.bind(mongoose)(mongoUri, {}); // mongoose 6 diff --git a/src/resolvers/__tests__/count-test.ts b/src/resolvers/__tests__/count-test.ts index 67a4ca23..29b7ba6b 100644 --- a/src/resolvers/__tests__/count-test.ts +++ b/src/resolvers/__tests__/count-test.ts @@ -112,7 +112,7 @@ describe('count() ->', () => { 'users', 'countDocuments', {}, - version.startsWith('7') + Number(version[0]) == 7 ? undefined : { limit: 1, diff --git a/src/resolvers/__tests__/findMany-test.ts b/src/resolvers/__tests__/findMany-test.ts index dfad7099..46630c81 100644 --- a/src/resolvers/__tests__/findMany-test.ts +++ b/src/resolvers/__tests__/findMany-test.ts @@ -1,5 +1,5 @@ -import { Resolver, schemaComposer, ObjectTypeComposer, EnumTypeComposer } from 'graphql-compose'; -import { UserModel, IUser } from '../../__mocks__/userModel'; +import { EnumTypeComposer, ObjectTypeComposer, Resolver, schemaComposer } from 'graphql-compose'; +import { IUser, UserModel } from '../../__mocks__/userModel'; import { findMany } from '../findMany'; import { convertModelToGraphQL } from '../../fieldsConverter'; import { ExtendedResolveParams } from '..'; diff --git a/src/resolvers/__tests__/removeById-test.ts b/src/resolvers/__tests__/removeById-test.ts index bc219b0c..6af769c8 100644 --- a/src/resolvers/__tests__/removeById-test.ts +++ b/src/resolvers/__tests__/removeById-test.ts @@ -1,8 +1,8 @@ /* eslint-disable no-param-reassign */ -import { Resolver, schemaComposer, ObjectTypeComposer } from 'graphql-compose'; +import { ObjectTypeComposer, Resolver, schemaComposer } from 'graphql-compose'; import { GraphQLNonNull } from 'graphql-compose/lib/graphql'; -import { UserModel, IUser } from '../../__mocks__/userModel'; +import { IUser, UserModel } from '../../__mocks__/userModel'; import { removeById } from '../removeById'; import GraphQLMongoID from '../../types/MongoID'; import { convertModelToGraphQL } from '../../fieldsConverter'; @@ -192,7 +192,7 @@ describe('removeById() ->', () => { 'users', 'findOne', { _id: user._id, gender: 'some' }, - version.startsWith('7') ? undefined : { projection: {} }, + Number(version[0]) == 8 ? {} : Number(version[0]) == 8 ? undefined : { projection: {} }, ].filter(Boolean), ]); diff --git a/src/resolvers/helpers/__tests__/filter-test.ts b/src/resolvers/helpers/__tests__/filter-test.ts index 3ae95316..656c270d 100644 --- a/src/resolvers/helpers/__tests__/filter-test.ts +++ b/src/resolvers/helpers/__tests__/filter-test.ts @@ -89,7 +89,7 @@ describe('Resolver helper `filter` ->', () => { }); const itc = args.filter.type as InputTypeComposer; expect(itc.hasField('_id')).toBe(true); - expect(itc.hasField('name')).toBe(false); + expect(itc.hasField('name')).toBe(true); expect(itc.hasField('age')).toBe(true); expect(itc.hasField('gender')).toBe(false); }); diff --git a/src/resolvers/helpers/sort.ts b/src/resolvers/helpers/sort.ts index 31259786..a10f31f2 100644 --- a/src/resolvers/helpers/sort.ts +++ b/src/resolvers/helpers/sort.ts @@ -1,15 +1,15 @@ /* eslint-disable no-use-before-define */ -import type { Model, Document } from 'mongoose'; +import type { Document, Model } from 'mongoose'; import { - ObjectTypeComposerArgumentConfigMapDefinition, - ObjectTypeComposer, - InterfaceTypeComposer, - SchemaComposer, EnumTypeComposer, + InterfaceTypeComposer, isObject, + ObjectTypeComposer, + ObjectTypeComposerArgumentConfigMapDefinition, + SchemaComposer, } from 'graphql-compose'; -import { getIndexesFromModel, extendByReversedIndexes } from '../../utils/getIndexesFromModel'; +import { extendByReversedIndexes, getIndexesFromModel } from '../../utils'; import type { ExtendedResolveParams } from '../index'; export type SortHelperArgsOpts = { diff --git a/src/resolvers/helpers/validate.ts b/src/resolvers/helpers/validate.ts index 63ee7d96..78f63fa2 100644 --- a/src/resolvers/helpers/validate.ts +++ b/src/resolvers/helpers/validate.ts @@ -1,6 +1,6 @@ import type { Error as MongooseError } from 'mongoose'; import type { Document } from 'mongoose'; -import { version as MongooseVersion} from 'mongoose'; +import { version as MongooseVersion } from 'mongoose'; import { ValidationError } from '../../errors'; export type ValidationErrorData = { @@ -20,10 +20,10 @@ export type ValidationsWithMessage = { }; export async function validateDoc(doc: Document): Promise { - - const validations: MongooseError.ValidationError | null = Number(MongooseVersion.charAt(0)) > 7 - ? doc.validateSync() - : await new Promise((resolve) => doc.validate(resolve as any)); + const validations: MongooseError.ValidationError | null = + Number(MongooseVersion[0]) > 7 + ? doc.validateSync() + : await new Promise((resolve) => doc.validate(resolve as any)); return validations?.errors ? { diff --git a/src/utils/getIndexesFromModel.ts b/src/utils/getIndexesFromModel.ts index 88ae4d82..6e8ee60d 100644 --- a/src/utils/getIndexesFromModel.ts +++ b/src/utils/getIndexesFromModel.ts @@ -39,7 +39,8 @@ export function getIndexesFromModel( // scan all fields on index presence [MONGOOSE FIELDS LEVEL INDEX] Object.keys(mongooseModel.schema.paths).forEach((name) => { if ((mongooseModel.schema.paths[name] as any)._index) { - indexedFields.push({ [name]: 1 }); // ASC by default + const aliasOrName = mongooseModel.schema.paths[name]?.options?.alias || name; + indexedFields.push({ [aliasOrName]: 1 }); // ASC by default } }); @@ -56,14 +57,19 @@ export function getIndexesFromModel( // extract partial indexes from compound index // { name: 1, age: 1, salary: 1} -> [{name:1}, {name:1, age:1}, {name:1, age:1, salary:1}] Object.keys(idxFields).forEach((fieldName: any) => { - partialIndexes[fieldName] = idxFields[fieldName]; + const alias = mongooseModel.schema.paths[fieldName]?.options?.alias; + const aliasOrName = alias || fieldName; + partialIndexes[aliasOrName] = idxFields[fieldName]; indexedFields.push({ ...partialIndexes }); + // push aliases on it's own index if its compound + if (alias) { + indexedFields.push({ [aliasOrName]: idxFields[fieldName] }); + } }); } } }); } - // filter duplicates const tmp: string[] = []; const result = indexedFields.filter((val) => { @@ -149,10 +155,11 @@ export function getIndexedFieldNamesForGraphQL(model: Model): string[] { const fieldNames: string[] = []; indexes.forEach((indexData) => { const keys = Object.keys(indexData); - const clearedName = keys[0].replace(/[^_a-zA-Z0-9]/i, '__'); - fieldNames.push(clearedName); + for (let i = 0; i < keys.length; i++) { + const clearedName = keys[i].replace(/[^_a-zA-Z0-9]/i, '__'); + fieldNames.push(clearedName); + } }); - // filter duplicates const uniqueNames: string[] = []; const result = fieldNames.filter((val) => { From 8248376c7285dc179c4f76a51011e621596cd39c Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Wed, 1 Nov 2023 00:23:50 -0400 Subject: [PATCH 04/26] chore: update mongoose 8 --- .github/workflows/nodejs.yml | 4 ---- package.json | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 6742d56f..1e267492 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -40,10 +40,6 @@ jobs: run: yarn test-prev-vers-6 env: CI: true - - name: Testing with previous mongoose versions 5 - run: yarn test-prev-vers-5 - env: - CI: true - name: Send codecov.io stats if: matrix.node-version == '18.x' run: bash <(curl -s https://codecov.io/bash) || echo '' diff --git a/package.json b/package.json index 57a7bbad..1fd332d4 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ }, "peerDependencies": { "graphql-compose": "^7.21.4 || ^8.0.0 || ^9.0.0", - "mongoose": "^7.0.0 || ^6.0.0 || ^5.0.0 || ^4.4.0" + "mongoose": "^8.0.0 || ^7.0.0 || ^6.0.0" }, "devDependencies": { "@types/jest": "29.5.7", @@ -65,7 +65,9 @@ "unlink": "rimraf node_modules && yarn install", "semantic-release": "semantic-release", "test-prev-vers-7": "yarn add mongoose@7.6.4 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock", - "test-prev-vers-6": "yarn add mongoose@6.1.2 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock", - "test-prev-vers-5": "yarn add mongoose@5.13.8 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock" + "test-prev-vers-6": "yarn add mongoose@6.1.2 --dev --ignore-scripts && yarn coverage && git checkout HEAD -- package.json yarn.lock" + }, + "engines": { + "node": ">=16.0.0" } } From a70b5920834063ea6a69509f19b2c6e3e7f26576 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Wed, 1 Nov 2023 02:40:11 -0400 Subject: [PATCH 05/26] chore: update mongoose 8 --- .../__snapshots__/integration-test.ts.snap | 8 ++++---- src/resolvers/__tests__/findMany-test.ts | 6 ++++-- src/resolvers/helpers/__tests__/sort-test.ts | 13 +++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/__tests__/__snapshots__/integration-test.ts.snap b/src/__tests__/__snapshots__/integration-test.ts.snap index 2717357e..f426d0e9 100644 --- a/src/__tests__/__snapshots__/integration-test.ts.snap +++ b/src/__tests__/__snapshots__/integration-test.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`integration tests projection should request all fields to rawData field: projection from all fields 1`] = ` -Array [ +[ "__v", "_id", "age", @@ -24,9 +24,9 @@ Array [ `; exports[`integration tests projection should request only fields from query: projection from query fields 1`] = ` -Object { - "data": Object { - "user": Object { +{ + "data": { + "user": { "name": "Name", }, }, diff --git a/src/resolvers/__tests__/findMany-test.ts b/src/resolvers/__tests__/findMany-test.ts index 46630c81..98926609 100644 --- a/src/resolvers/__tests__/findMany-test.ts +++ b/src/resolvers/__tests__/findMany-test.ts @@ -173,8 +173,10 @@ describe('findMany() ->', () => { '_ID_DESC', 'NAME_ASC', 'NAME_DESC', - 'NAME__AGE_ASC', - 'NAME__AGE_DESC', + 'AGE__NAME_ASC', + 'AGE__NAME_DESC', + // 'NAME__AGE_ASC', + // 'NAME__AGE_DESC', ]) ); const res = await testFieldConfig({ diff --git a/src/resolvers/helpers/__tests__/sort-test.ts b/src/resolvers/helpers/__tests__/sort-test.ts index bdfa226b..8f81578c 100644 --- a/src/resolvers/helpers/__tests__/sort-test.ts +++ b/src/resolvers/helpers/__tests__/sort-test.ts @@ -3,6 +3,7 @@ import { sortHelperArgs, sortHelper, getSortTypeFromModel } from '../sort'; import { UserModel } from '../../../__mocks__/userModel'; import { convertModelToGraphQL } from '../../../fieldsConverter'; import { getIndexesFromModel } from '../../../utils'; +import * as console from 'console'; describe('Resolver helper `sort` ->', () => { let UserTC: ObjectTypeComposer; @@ -39,13 +40,17 @@ describe('Resolver helper `sort` ->', () => { const enumNames = etc.getFieldNames(); expect(enumNames).toEqual(expect.arrayContaining(['_ID_ASC', '_ID_DESC'])); + // const complexASC = etc.getField('NAME__AGE_ASC'); + // expect(complexASC.value).toEqual({ name: 1, age: -1 }); + // @FIXME mongoose 8 assigning fields schema when they have aliases to last + // should have ASC criteria for mongoose - const complexASC = etc.getField('NAME__AGE_ASC'); - expect(complexASC.value).toEqual({ name: 1, age: -1 }); + const complexASC = etc.getField('AGE__NAME_ASC'); + expect(complexASC.value).toEqual({ age: 1, name: -1 }); // should have DESC criteria for mongoose - const complexDESC = etc.getField('NAME__AGE_DESC'); - expect(complexDESC.value).toEqual({ name: -1, age: 1 }); + const complexDESC = etc.getField('AGE__NAME_DESC'); + expect(complexDESC.value).toEqual({ age: -1, name: 1 }); }); }); From 3e8fa9c5875a899be96be05ad51f2e6b4213637b Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Wed, 1 Nov 2023 03:05:54 -0400 Subject: [PATCH 06/26] chore: update mongoose 8 --- src/composeMongoose.ts | 2 +- src/fieldsConverter.ts | 35 +++++++++++--------- src/resolvers/helpers/__tests__/sort-test.ts | 5 ++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/composeMongoose.ts b/src/composeMongoose.ts index dc243c75..0a3cbbec 100644 --- a/src/composeMongoose.ts +++ b/src/composeMongoose.ts @@ -100,7 +100,7 @@ export type GenerateResolverType = { export type ObjectTypeComposerWithMongooseResolvers< TDoc extends Document, - TContext = any + TContext = any, > = ObjectTypeComposer & { mongooseResolvers: GenerateResolverType; }; diff --git a/src/fieldsConverter.ts b/src/fieldsConverter.ts index 4222d165..3c95dc64 100644 --- a/src/fieldsConverter.ts +++ b/src/fieldsConverter.ts @@ -1,13 +1,13 @@ /* eslint-disable no-use-before-define */ +import type { Model, Schema } from 'mongoose'; import mongoose, { Document } from 'mongoose'; -import type { Schema, Model } from 'mongoose'; import type { - SchemaComposer, - ObjectTypeComposer, - EnumTypeComposer, ComposeOutputTypeDefinition, + EnumTypeComposer, + ObjectTypeComposer, ObjectTypeComposerFieldConfigAsObjectDefinition, + SchemaComposer, } from 'graphql-compose'; import { upperFirst } from 'graphql-compose'; import type { GraphQLScalarType } from 'graphql-compose/lib/graphql'; @@ -386,18 +386,21 @@ export function enumToGraphQL( const desc = _getFieldDescription(field); if (desc) etc.setDescription(desc); - const fields = valueList.reduce((result, value) => { - let key; - if (value === null) { - key = 'NULL'; - } else if (value === '') { - key = 'EMPTY_STRING'; - } else { - key = value.replace(/[^_a-zA-Z0-9]/g, '_').replace(/(^[0-9])(.*)/g, 'a_$1$2'); - } - result[key] = { value }; - return result; - }, {} as Record); + const fields = valueList.reduce( + (result, value) => { + let key; + if (value === null) { + key = 'NULL'; + } else if (value === '') { + key = 'EMPTY_STRING'; + } else { + key = value.replace(/[^_a-zA-Z0-9]/g, '_').replace(/(^[0-9])(.*)/g, 'a_$1$2'); + } + result[key] = { value }; + return result; + }, + {} as Record + ); etc.setFields(fields); }); } diff --git a/src/resolvers/helpers/__tests__/sort-test.ts b/src/resolvers/helpers/__tests__/sort-test.ts index 8f81578c..9accbf8d 100644 --- a/src/resolvers/helpers/__tests__/sort-test.ts +++ b/src/resolvers/helpers/__tests__/sort-test.ts @@ -1,9 +1,8 @@ -import { EnumTypeComposer, schemaComposer, ObjectTypeComposer } from 'graphql-compose'; -import { sortHelperArgs, sortHelper, getSortTypeFromModel } from '../sort'; +import { EnumTypeComposer, ObjectTypeComposer, schemaComposer } from 'graphql-compose'; +import { getSortTypeFromModel, sortHelper, sortHelperArgs } from '../sort'; import { UserModel } from '../../../__mocks__/userModel'; import { convertModelToGraphQL } from '../../../fieldsConverter'; import { getIndexesFromModel } from '../../../utils'; -import * as console from 'console'; describe('Resolver helper `sort` ->', () => { let UserTC: ObjectTypeComposer; From bde388784c050095ac1fd196f6dc20af42fc7401 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 12:30:48 -0400 Subject: [PATCH 07/26] chore: update mongoose --- package.json | 2 +- src/fieldsConverter.ts | 2 +- src/resolvers/__tests__/findMany-test.ts | 7 ++----- .../helpers/__tests__/filterOperators-test.ts | 2 -- src/resolvers/helpers/__tests__/sort-test.ts | 13 ++++--------- yarn.lock | 5 ++--- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 1fd332d4..46000541 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "graphql-compose": "9.0.10", "jest": "29.7.0", "mongodb-memory-server": "9.0.1", - "mongoose": "8.0.0", + "mongoose": "meabed/mongoose#fix-index-alias", "prettier": "3.0.3", "request": "2.88.2", "rimraf": "5.0.5", diff --git a/src/fieldsConverter.ts b/src/fieldsConverter.ts index 3c95dc64..7e1d2053 100644 --- a/src/fieldsConverter.ts +++ b/src/fieldsConverter.ts @@ -47,7 +47,7 @@ export enum ComplexTypes { DECIMAL = 'DECIMAL', } -// In mongoose@6 Embedded type was renamed to Subdocument +// In mongoose@6 Embedded type was renamed to Sub-document // So keep backward compatibility with old mongoose versions const SubdocumentTypeClass = (mongoose.Schema.Types as any)?.Embedded || (mongoose.Schema.Types as any).Subdocument; diff --git a/src/resolvers/__tests__/findMany-test.ts b/src/resolvers/__tests__/findMany-test.ts index 98926609..d761535f 100644 --- a/src/resolvers/__tests__/findMany-test.ts +++ b/src/resolvers/__tests__/findMany-test.ts @@ -7,7 +7,6 @@ import { testFieldConfig } from '../../utils/testHelpers'; beforeAll(() => UserModel.base.createConnection()); afterAll(() => UserModel.base.disconnect()); - describe('findMany() ->', () => { let UserTC: ObjectTypeComposer; @@ -173,10 +172,8 @@ describe('findMany() ->', () => { '_ID_DESC', 'NAME_ASC', 'NAME_DESC', - 'AGE__NAME_ASC', - 'AGE__NAME_DESC', - // 'NAME__AGE_ASC', - // 'NAME__AGE_DESC', + 'NAME__AGE_ASC', + 'NAME__AGE_DESC', ]) ); const res = await testFieldConfig({ diff --git a/src/resolvers/helpers/__tests__/filterOperators-test.ts b/src/resolvers/helpers/__tests__/filterOperators-test.ts index 9294666a..d2569b74 100644 --- a/src/resolvers/helpers/__tests__/filterOperators-test.ts +++ b/src/resolvers/helpers/__tests__/filterOperators-test.ts @@ -137,7 +137,6 @@ describe('Resolver helper `filter` ->', () => { '_id', 'employment', 'name', - 'age', 'billingAddress', ]); expect(itc.getFieldITC('_operators').getFieldITC('name').getFieldNames()).toEqual(['exists']); @@ -156,7 +155,6 @@ describe('Resolver helper `filter` ->', () => { '_id', 'employment', 'name', - 'age', 'billingAddress', ]); expect(itc.getFieldITC('_operators').getFieldITC('name').getFieldNames()).toEqual(['exists']); diff --git a/src/resolvers/helpers/__tests__/sort-test.ts b/src/resolvers/helpers/__tests__/sort-test.ts index 9accbf8d..411de5df 100644 --- a/src/resolvers/helpers/__tests__/sort-test.ts +++ b/src/resolvers/helpers/__tests__/sort-test.ts @@ -39,17 +39,12 @@ describe('Resolver helper `sort` ->', () => { const enumNames = etc.getFieldNames(); expect(enumNames).toEqual(expect.arrayContaining(['_ID_ASC', '_ID_DESC'])); - // const complexASC = etc.getField('NAME__AGE_ASC'); - // expect(complexASC.value).toEqual({ name: 1, age: -1 }); - // @FIXME mongoose 8 assigning fields schema when they have aliases to last - - // should have ASC criteria for mongoose - const complexASC = etc.getField('AGE__NAME_ASC'); - expect(complexASC.value).toEqual({ age: 1, name: -1 }); + const complexASC = etc.getField('NAME__AGE_ASC'); + expect(complexASC.value).toEqual({ name: 1, age: -1 }); // should have DESC criteria for mongoose - const complexDESC = etc.getField('AGE__NAME_DESC'); - expect(complexDESC.value).toEqual({ age: -1, name: 1 }); + const complexDESC = etc.getField('NAME__AGE_DESC'); + expect(complexDESC.value).toEqual({ name: -1, age: 1 }); }); }); diff --git a/yarn.lock b/yarn.lock index 7fc4bb1e..a4da5543 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3498,10 +3498,9 @@ mongodb@^5.9.0: optionalDependencies: "@mongodb-js/saslprep" "^1.1.0" -mongoose@8.0.0: +mongoose@meabed/mongoose#fix-index-alias: version "8.0.0" - resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-8.0.0.tgz#f14175eebfaf5256855d7cbd58bf862819b3fd12" - integrity sha512-PzwkLgm1Jhj0NQdgGfnFsu0QP9V1sBFgbavEgh/IPAUzKAagzvEhuaBuAQOQGjczVWnpIU9tBqyd02cOTgsPlA== + resolved "https://codeload.github.com/meabed/mongoose/tar.gz/a506cc4d78b471d5d1c5d33d399c061e60ea46b4" dependencies: bson "^6.2.0" kareem "2.5.1" From ab4574e6fb7aaebffd50b6fcd85a00b90ee8d34a Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 13:54:18 -0400 Subject: [PATCH 08/26] chore: update mongoose --- jest.config.js | 14 +++++---- package.json | 2 +- src/composeMongoose.ts | 9 ++++-- src/resolvers/__tests__/count-test.ts | 2 +- src/resolvers/helpers/validate.ts | 2 +- src/setupTests.ts | 5 ++++ src/utils/patchMongoose.ts | 42 +++++++++++++++++++++++++++ yarn.lock | 5 ++-- 8 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 src/setupTests.ts create mode 100644 src/utils/patchMongoose.ts diff --git a/jest.config.js b/jest.config.js index 64c814ad..2fb13eed 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,12 +2,16 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', moduleFileExtensions: ['ts', 'js'], + setupFilesAfterEnv: ['/src/setupTests.ts'], transform: { - '^.+\\.ts$': ['ts-jest', { - tsconfig: '/tsconfig.json', - isolatedModules: true, - diagnostics: false, - }], + '^.+\\.ts$': [ + 'ts-jest', + { + tsconfig: '/tsconfig.json', + isolatedModules: true, + diagnostics: false, + }, + ], '^.+\\.js$': 'babel-jest', }, roots: ['/src'], diff --git a/package.json b/package.json index 46000541..1fd332d4 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "graphql-compose": "9.0.10", "jest": "29.7.0", "mongodb-memory-server": "9.0.1", - "mongoose": "meabed/mongoose#fix-index-alias", + "mongoose": "8.0.0", "prettier": "3.0.3", "request": "2.88.2", "rimraf": "5.0.5", diff --git a/src/composeMongoose.ts b/src/composeMongoose.ts index 0a3cbbec..2c13c35c 100644 --- a/src/composeMongoose.ts +++ b/src/composeMongoose.ts @@ -1,9 +1,10 @@ -import type { SchemaComposer, Resolver, InputTypeComposer } from 'graphql-compose'; -import { schemaComposer as globalSchemaComposer, ObjectTypeComposer } from 'graphql-compose'; -import type { Model, Document } from 'mongoose'; +import type { InputTypeComposer, Resolver, SchemaComposer } from 'graphql-compose'; +import { ObjectTypeComposer, schemaComposer as globalSchemaComposer } from 'graphql-compose'; +import type { Document, Model } from 'mongoose'; import { convertModelToGraphQL } from './fieldsConverter'; import { resolverFactory } from './resolvers'; import MongoID from './types/MongoID'; +import { patchMongooseSchemaIndex } from './utils/patchMongoose'; export type TypeConverterInputTypeOpts = { /** @@ -120,6 +121,8 @@ export function composeMongoose( `You try to generate GraphQL Type with name ${name} from mongoose model but this type already exists in SchemaComposer. Please choose another type name "composeWithMongoose(model, { name: 'NewTypeName' })", or reuse existed type "schemaComposer.getOTC('TypeName')", or remove type from SchemaComposer before calling composeWithMongoose method "schemaComposer.delete('TypeName')".` ); } + patchMongooseSchemaIndex(); + if (sc.has(m.schema)) { // looks like you want to generate new TypeComposer from model // so remove cached model (which is used for cross-reference types) diff --git a/src/resolvers/__tests__/count-test.ts b/src/resolvers/__tests__/count-test.ts index 29b7ba6b..6fcd149f 100644 --- a/src/resolvers/__tests__/count-test.ts +++ b/src/resolvers/__tests__/count-test.ts @@ -112,7 +112,7 @@ describe('count() ->', () => { 'users', 'countDocuments', {}, - Number(version[0]) == 7 + Number(version[0]) < 7 ? undefined : { limit: 1, diff --git a/src/resolvers/helpers/validate.ts b/src/resolvers/helpers/validate.ts index 78f63fa2..34edd291 100644 --- a/src/resolvers/helpers/validate.ts +++ b/src/resolvers/helpers/validate.ts @@ -21,7 +21,7 @@ export type ValidationsWithMessage = { export async function validateDoc(doc: Document): Promise { const validations: MongooseError.ValidationError | null = - Number(MongooseVersion[0]) > 7 + Number(MongooseVersion[0]) >= 7 ? doc.validateSync() : await new Promise((resolve) => doc.validate(resolve as any)); diff --git a/src/setupTests.ts b/src/setupTests.ts new file mode 100644 index 00000000..58f75362 --- /dev/null +++ b/src/setupTests.ts @@ -0,0 +1,5 @@ +import { patchMongooseSchemaIndex } from './utils/patchMongoose'; + +global.beforeAll(() => { + patchMongooseSchemaIndex(); +}); diff --git a/src/utils/patchMongoose.ts b/src/utils/patchMongoose.ts new file mode 100644 index 00000000..c62da024 --- /dev/null +++ b/src/utils/patchMongoose.ts @@ -0,0 +1,42 @@ +import mongoose, { IndexDefinition, IndexOptions } from 'mongoose'; + +export function renameObjKey( + oldObj: Record, + oldKey: string, + newKey: string | number +) { + const keys = Object.keys(oldObj); + return keys.reduce( + (acc, val) => { + if (val === oldKey) { + acc[newKey] = oldObj[oldKey]; + } else { + acc[val] = oldObj[val]; + } + return acc; + }, + {} as Record + ); +} + +const oldMongooseSchemaIndexDef = mongoose.Schema.prototype.index; +mongoose.Schema.prototype.index = function (fields: IndexDefinition, options?: IndexOptions) { + // @ts-ignore + if (mongoose.Schema.prototype.indexMethodPatched) { + return oldMongooseSchemaIndexDef.call(this, fields, options); + } + fields || (fields = {}); + options || (options = {}); + for (const key in fields) { + // @ts-ignore + if (this.aliases[key]) { + // @ts-ignore + fields = renameObjKey(fields, key, this.aliases[key]); + } + } + // @ts-ignore + mongoose.Schema.prototype.indexMethodPatched = true; + return oldMongooseSchemaIndexDef.call(this, fields, options); +}; + +export function patchMongooseSchemaIndex() {} diff --git a/yarn.lock b/yarn.lock index a4da5543..7fc4bb1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3498,9 +3498,10 @@ mongodb@^5.9.0: optionalDependencies: "@mongodb-js/saslprep" "^1.1.0" -mongoose@meabed/mongoose#fix-index-alias: +mongoose@8.0.0: version "8.0.0" - resolved "https://codeload.github.com/meabed/mongoose/tar.gz/a506cc4d78b471d5d1c5d33d399c061e60ea46b4" + resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-8.0.0.tgz#f14175eebfaf5256855d7cbd58bf862819b3fd12" + integrity sha512-PzwkLgm1Jhj0NQdgGfnFsu0QP9V1sBFgbavEgh/IPAUzKAagzvEhuaBuAQOQGjczVWnpIU9tBqyd02cOTgsPlA== dependencies: bson "^6.2.0" kareem "2.5.1" From f6799d30f5f16f697081bf0bbceb558737f54803 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 13:58:27 -0400 Subject: [PATCH 09/26] chore: update mongoose --- src/setupTests.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/setupTests.ts b/src/setupTests.ts index 58f75362..9a9935e3 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -1,5 +1,6 @@ import { patchMongooseSchemaIndex } from './utils/patchMongoose'; +import { beforeAll } from '@jest/globals'; -global.beforeAll(() => { +beforeAll(() => { patchMongooseSchemaIndex(); }); From 6f2822d391eb5f483dc1c82c001da2b770076e8f Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 14:04:17 -0400 Subject: [PATCH 10/26] chore: update mongoose --- src/resolvers/__tests__/removeById-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolvers/__tests__/removeById-test.ts b/src/resolvers/__tests__/removeById-test.ts index 6af769c8..edb5baab 100644 --- a/src/resolvers/__tests__/removeById-test.ts +++ b/src/resolvers/__tests__/removeById-test.ts @@ -192,7 +192,7 @@ describe('removeById() ->', () => { 'users', 'findOne', { _id: user._id, gender: 'some' }, - Number(version[0]) == 8 ? {} : Number(version[0]) == 8 ? undefined : { projection: {} }, + Number(version[0]) == 8 ? {} : Number(version[0]) <= 6 ? undefined : { projection: {} }, ].filter(Boolean), ]); From 779864f3243d556cbf01180a132c2d113095871c Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 14:12:11 -0400 Subject: [PATCH 11/26] chore: update mongoose --- src/resolvers/__tests__/removeById-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolvers/__tests__/removeById-test.ts b/src/resolvers/__tests__/removeById-test.ts index edb5baab..432f91b9 100644 --- a/src/resolvers/__tests__/removeById-test.ts +++ b/src/resolvers/__tests__/removeById-test.ts @@ -192,7 +192,7 @@ describe('removeById() ->', () => { 'users', 'findOne', { _id: user._id, gender: 'some' }, - Number(version[0]) == 8 ? {} : Number(version[0]) <= 6 ? undefined : { projection: {} }, + Number(version[0]) >= 7 ? {} : { projection: {} }, ].filter(Boolean), ]); From 07507b2322116111a0b67aa2f92cc64296d74633 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 14:24:47 -0400 Subject: [PATCH 12/26] chore: update mongoose --- src/resolvers/__tests__/count-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolvers/__tests__/count-test.ts b/src/resolvers/__tests__/count-test.ts index 6fcd149f..07610271 100644 --- a/src/resolvers/__tests__/count-test.ts +++ b/src/resolvers/__tests__/count-test.ts @@ -112,7 +112,7 @@ describe('count() ->', () => { 'users', 'countDocuments', {}, - Number(version[0]) < 7 + Number(version[0]) > 6 ? undefined : { limit: 1, From 7f3a71bd315d230129ecace792e56a0d75097d6c Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 14:27:21 -0400 Subject: [PATCH 13/26] chore: update mongoose --- src/resolvers/__tests__/count-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resolvers/__tests__/count-test.ts b/src/resolvers/__tests__/count-test.ts index 07610271..e8b17b87 100644 --- a/src/resolvers/__tests__/count-test.ts +++ b/src/resolvers/__tests__/count-test.ts @@ -112,7 +112,7 @@ describe('count() ->', () => { 'users', 'countDocuments', {}, - Number(version[0]) > 6 + Number(version[0]) === 7 ? undefined : { limit: 1, From 858d96a229801a1833a8f22b821a9caf57691671 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 14:31:52 -0400 Subject: [PATCH 14/26] chore: update mongoose --- src/resolvers/__tests__/count-test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/resolvers/__tests__/count-test.ts b/src/resolvers/__tests__/count-test.ts index e8b17b87..5a0bd114 100644 --- a/src/resolvers/__tests__/count-test.ts +++ b/src/resolvers/__tests__/count-test.ts @@ -112,7 +112,11 @@ describe('count() ->', () => { 'users', 'countDocuments', {}, - Number(version[0]) === 7 + Number(version[0]) > 7 + ? { + limit: 1, + } + : Number(version[0]) === 7 ? undefined : { limit: 1, From ecdfc816e0bf6493e90d0543c705646d24906e96 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 15:01:08 -0400 Subject: [PATCH 15/26] chore: update mongoose --- src/__mocks__/mongooseCommon.ts | 6 ++++-- src/resolvers/__tests__/count-test.ts | 15 ++++----------- src/resolvers/__tests__/removeById-test.ts | 4 +++- src/resolvers/helpers/validate.ts | 9 +++++---- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/__mocks__/mongooseCommon.ts b/src/__mocks__/mongooseCommon.ts index 9c43cfd5..1d97a656 100644 --- a/src/__mocks__/mongooseCommon.ts +++ b/src/__mocks__/mongooseCommon.ts @@ -1,8 +1,10 @@ /* eslint-disable no-param-reassign, no-console */ -import mongoose, { version as MongooseVersion } from 'mongoose'; +import mongoose, { version } from 'mongoose'; import MongoMemoryServer from 'mongodb-memory-server-core'; +const versionNumber = Number(version.charAt(0)); + const { Schema, Types } = mongoose; mongoose.Promise = Promise; @@ -15,7 +17,7 @@ mongoose.createConnection = (async () => { // originalConnect.bind(mongoose)(mongoUri, { useMongoClient: true }); // mongoose 4 originalConnect.bind(mongoose)( mongoUri, - Number(MongooseVersion[0]) > 7 + versionNumber > 7 ? {} : ({ useNewUrlParser: true, diff --git a/src/resolvers/__tests__/count-test.ts b/src/resolvers/__tests__/count-test.ts index 5a0bd114..0c0e9524 100644 --- a/src/resolvers/__tests__/count-test.ts +++ b/src/resolvers/__tests__/count-test.ts @@ -1,10 +1,9 @@ -import { Resolver, schemaComposer, ObjectTypeComposer } from 'graphql-compose'; +import { ObjectTypeComposer, Resolver, schemaComposer } from 'graphql-compose'; import { GraphQLInt } from 'graphql-compose/lib/graphql'; import { UserModel } from '../../__mocks__/userModel'; import { count } from '../count'; import { convertModelToGraphQL } from '../../fieldsConverter'; import { ExtendedResolveParams } from '..'; -import { version } from 'mongoose'; beforeAll(() => UserModel.base.createConnection()); afterAll(() => UserModel.base.disconnect()); @@ -112,15 +111,9 @@ describe('count() ->', () => { 'users', 'countDocuments', {}, - Number(version[0]) > 7 - ? { - limit: 1, - } - : Number(version[0]) === 7 - ? undefined - : { - limit: 1, - }, + { + limit: 1, + }, ].filter(Boolean), ]); diff --git a/src/resolvers/__tests__/removeById-test.ts b/src/resolvers/__tests__/removeById-test.ts index 432f91b9..563e738f 100644 --- a/src/resolvers/__tests__/removeById-test.ts +++ b/src/resolvers/__tests__/removeById-test.ts @@ -10,6 +10,8 @@ import { ExtendedResolveParams } from '..'; import { testFieldConfig } from '../../utils/testHelpers'; import { version } from 'mongoose'; +const versionNumber = Number(version.charAt(0)); + beforeAll(() => UserModel.base.createConnection()); afterAll(() => UserModel.base.disconnect()); @@ -192,7 +194,7 @@ describe('removeById() ->', () => { 'users', 'findOne', { _id: user._id, gender: 'some' }, - Number(version[0]) >= 7 ? {} : { projection: {} }, + versionNumber >= 7 ? {} : { projection: {} }, ].filter(Boolean), ]); diff --git a/src/resolvers/helpers/validate.ts b/src/resolvers/helpers/validate.ts index 34edd291..b7933a3f 100644 --- a/src/resolvers/helpers/validate.ts +++ b/src/resolvers/helpers/validate.ts @@ -1,8 +1,9 @@ -import type { Error as MongooseError } from 'mongoose'; -import type { Document } from 'mongoose'; -import { version as MongooseVersion } from 'mongoose'; +import type { Document, Error as MongooseError } from 'mongoose'; +import { version } from 'mongoose'; import { ValidationError } from '../../errors'; +const versionNumber = Number(version.charAt(0)); + export type ValidationErrorData = { path: string; message: string; @@ -21,7 +22,7 @@ export type ValidationsWithMessage = { export async function validateDoc(doc: Document): Promise { const validations: MongooseError.ValidationError | null = - Number(MongooseVersion[0]) >= 7 + versionNumber >= 7 ? doc.validateSync() : await new Promise((resolve) => doc.validate(resolve as any)); From aff45d1503a777a4ce7e07836e7acbacc15938fd Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 2 Nov 2023 15:10:36 -0400 Subject: [PATCH 16/26] chore: update mongoose --- src/__mocks__/mongooseCommon.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/__mocks__/mongooseCommon.ts b/src/__mocks__/mongooseCommon.ts index 1d97a656..90a73576 100644 --- a/src/__mocks__/mongooseCommon.ts +++ b/src/__mocks__/mongooseCommon.ts @@ -1,10 +1,8 @@ /* eslint-disable no-param-reassign, no-console */ -import mongoose, { version } from 'mongoose'; +import mongoose from 'mongoose'; import MongoMemoryServer from 'mongodb-memory-server-core'; -const versionNumber = Number(version.charAt(0)); - const { Schema, Types } = mongoose; mongoose.Promise = Promise; @@ -14,17 +12,7 @@ mongoose.createConnection = (async () => { const mongoServer = await MongoMemoryServer.create(); const mongoUri = mongoServer.getUri(); - // originalConnect.bind(mongoose)(mongoUri, { useMongoClient: true }); // mongoose 4 - originalConnect.bind(mongoose)( - mongoUri, - versionNumber > 7 - ? {} - : ({ - useNewUrlParser: true, - useUnifiedTopology: true, - } as any) /* for tests compatibility with mongoose v5 & v6 */ - ); // mongoose 5 - // originalConnect.bind(mongoose)(mongoUri, {}); // mongoose 6 + originalConnect.bind(mongoose)(mongoUri, {}); mongoose.connection.on('error', (e) => { if (e.message.code === 'ETIMEDOUT') { From 1c69a0fc9fbd762d67250d58c99fa769a4482be3 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Mon, 6 Nov 2023 09:45:47 -0500 Subject: [PATCH 17/26] chore: update pkgs --- package.json | 2 +- src/resolvers/helpers/__tests__/sort-test.ts | 1 + yarn.lock | 28 ++++++++++---------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 1fd332d4..00faadf3 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@types/jest": "29.5.7", "@typescript-eslint/eslint-plugin": "6.9.1", "@typescript-eslint/parser": "6.9.1", - "eslint": "8.52.0", + "eslint": "8.53.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "9.0.0", "eslint-plugin-import": "2.29.0", diff --git a/src/resolvers/helpers/__tests__/sort-test.ts b/src/resolvers/helpers/__tests__/sort-test.ts index 411de5df..b9288f97 100644 --- a/src/resolvers/helpers/__tests__/sort-test.ts +++ b/src/resolvers/helpers/__tests__/sort-test.ts @@ -39,6 +39,7 @@ describe('Resolver helper `sort` ->', () => { const enumNames = etc.getFieldNames(); expect(enumNames).toEqual(expect.arrayContaining(['_ID_ASC', '_ID_DESC'])); + // should have ASC criteria for mongoose const complexASC = etc.getField('NAME__AGE_ASC'); expect(complexASC.value).toEqual({ name: 1, age: -1 }); diff --git a/yarn.lock b/yarn.lock index 7fc4bb1e..0f15e2db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -373,10 +373,10 @@ resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.10.0.tgz#548f6de556857c8bb73bbee70c35dc82a2e74d63" integrity sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA== -"@eslint/eslintrc@^2.1.2": - version "2.1.2" - resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.2.tgz#c6936b4b328c64496692f76944e755738be62396" - integrity sha512-+wvgpDsrB1YqAMdEUCcnTlpfVBH7Vqn6A/NT3D8WVXFIaKMlErPIZT3oCIAVCOtarRpMtelZLqJeU3t7WY6X6g== +"@eslint/eslintrc@^2.1.3": + version "2.1.3" + resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.1.3.tgz#797470a75fe0fbd5a53350ee715e85e87baff22d" + integrity sha512-yZzuIG+jnVu6hNSzFEN07e8BxF3uAzYtQb6uDkaYZLo6oYZDCq454c5kB8zxnzfCYyP4MIuyBn10L0DqwujTmA== dependencies: ajv "^6.12.4" debug "^4.3.2" @@ -388,10 +388,10 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" -"@eslint/js@8.52.0": - version "8.52.0" - resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c" - integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA== +"@eslint/js@8.53.0": + version "8.53.0" + resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.53.0.tgz#bea56f2ed2b5baea164348ff4d5a879f6f81f20d" + integrity sha512-Kn7K8dx/5U6+cT1yEhpX1w4PCSg0M+XyRILPgvwcEBjerFWCwQj5sbr3/VmxqV0JGHCBCzyd6LxypEuehypY1w== "@humanwhocodes/config-array@^0.11.13": version "0.11.13" @@ -1877,15 +1877,15 @@ eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3: resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== -eslint@8.52.0: - version "8.52.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.52.0.tgz#d0cd4a1fac06427a61ef9242b9353f36ea7062fc" - integrity sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg== +eslint@8.53.0: + version "8.53.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.53.0.tgz#14f2c8244298fcae1f46945459577413ba2697ce" + integrity sha512-N4VuiPjXDUa4xVeV/GC/RV3hQW9Nw+Y463lkWaKKXKYMvmRiRDAtfpuPFLN+E1/6ZhyR8J2ig+eVREnYgUsiag== dependencies: "@eslint-community/eslint-utils" "^4.2.0" "@eslint-community/regexpp" "^4.6.1" - "@eslint/eslintrc" "^2.1.2" - "@eslint/js" "8.52.0" + "@eslint/eslintrc" "^2.1.3" + "@eslint/js" "8.53.0" "@humanwhocodes/config-array" "^0.11.13" "@humanwhocodes/module-importer" "^1.0.1" "@nodelib/fs.walk" "^1.2.8" From 54528d4ea1c32350e6741ea069bef29eb4391cdd Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Mon, 6 Nov 2023 20:04:46 -0500 Subject: [PATCH 18/26] chore: update pkgs --- .github/workflows/nodejs.yml | 2 +- package.json | 4 +- yarn.lock | 100 +++++++++++++++++------------------ 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 1e267492..4a0c49e6 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -16,7 +16,7 @@ jobs: node-version: [16.x, 18.x, 20.x] steps: - run: echo "🎉 The job was triggered by a ${{ github.event_name }} event." - - uses: styfle/cancel-workflow-action@0.11.0 + - uses: styfle/cancel-workflow-action@0.12.0 with: workflow_id: nodejs.yml access_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/package.json b/package.json index 00faadf3..238b9a08 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ }, "devDependencies": { "@types/jest": "29.5.7", - "@typescript-eslint/eslint-plugin": "6.9.1", - "@typescript-eslint/parser": "6.9.1", + "@typescript-eslint/eslint-plugin": "6.10.0", + "@typescript-eslint/parser": "6.10.0", "eslint": "8.53.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "9.0.0", diff --git a/yarn.lock b/yarn.lock index 0f15e2db..9740a6bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -871,16 +871,16 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.9.1.tgz#d8ce497dc0ed42066e195c8ecc40d45c7b1254f4" - integrity sha512-w0tiiRc9I4S5XSXXrMHOWgHgxbrBn1Ro+PmiYhSg2ZVdxrAJtQgzU5o2m1BfP6UOn7Vxcc6152vFjQfmZR4xEg== +"@typescript-eslint/eslint-plugin@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.10.0.tgz#cfe2bd34e26d2289212946b96ab19dcad64b661a" + integrity sha512-uoLj4g2OTL8rfUQVx2AFO1hp/zja1wABJq77P6IclQs6I/m9GLrm7jCdgzZkvWdDCQf1uEvoa8s8CupsgWQgVg== dependencies: "@eslint-community/regexpp" "^4.5.1" - "@typescript-eslint/scope-manager" "6.9.1" - "@typescript-eslint/type-utils" "6.9.1" - "@typescript-eslint/utils" "6.9.1" - "@typescript-eslint/visitor-keys" "6.9.1" + "@typescript-eslint/scope-manager" "6.10.0" + "@typescript-eslint/type-utils" "6.10.0" + "@typescript-eslint/utils" "6.10.0" + "@typescript-eslint/visitor-keys" "6.10.0" debug "^4.3.4" graphemer "^1.4.0" ignore "^5.2.4" @@ -888,72 +888,72 @@ semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/parser@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.9.1.tgz#4f685f672f8b9580beb38d5fb99d52fc3e34f7a3" - integrity sha512-C7AK2wn43GSaCUZ9do6Ksgi2g3mwFkMO3Cis96kzmgudoVaKyt62yNzJOktP0HDLb/iO2O0n2lBOzJgr6Q/cyg== +"@typescript-eslint/parser@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.10.0.tgz#578af79ae7273193b0b6b61a742a2bc8e02f875a" + integrity sha512-+sZwIj+s+io9ozSxIWbNB5873OSdfeBEH/FR0re14WLI6BaKuSOnnwCJ2foUiu8uXf4dRp1UqHP0vrZ1zXGrog== dependencies: - "@typescript-eslint/scope-manager" "6.9.1" - "@typescript-eslint/types" "6.9.1" - "@typescript-eslint/typescript-estree" "6.9.1" - "@typescript-eslint/visitor-keys" "6.9.1" + "@typescript-eslint/scope-manager" "6.10.0" + "@typescript-eslint/types" "6.10.0" + "@typescript-eslint/typescript-estree" "6.10.0" + "@typescript-eslint/visitor-keys" "6.10.0" debug "^4.3.4" -"@typescript-eslint/scope-manager@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.9.1.tgz#e96afeb9a68ad1cd816dba233351f61e13956b75" - integrity sha512-38IxvKB6NAne3g/+MyXMs2Cda/Sz+CEpmm+KLGEM8hx/CvnSRuw51i8ukfwB/B/sESdeTGet1NH1Wj7I0YXswg== +"@typescript-eslint/scope-manager@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.10.0.tgz#b0276118b13d16f72809e3cecc86a72c93708540" + integrity sha512-TN/plV7dzqqC2iPNf1KrxozDgZs53Gfgg5ZHyw8erd6jd5Ta/JIEcdCheXFt9b1NYb93a1wmIIVW/2gLkombDg== dependencies: - "@typescript-eslint/types" "6.9.1" - "@typescript-eslint/visitor-keys" "6.9.1" + "@typescript-eslint/types" "6.10.0" + "@typescript-eslint/visitor-keys" "6.10.0" -"@typescript-eslint/type-utils@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.9.1.tgz#efd5db20ed35a74d3c7d8fba51b830ecba09ce32" - integrity sha512-eh2oHaUKCK58qIeYp19F5V5TbpM52680sB4zNSz29VBQPTWIlE/hCj5P5B1AChxECe/fmZlspAWFuRniep1Skg== +"@typescript-eslint/type-utils@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.10.0.tgz#1007faede067c78bdbcef2e8abb31437e163e2e1" + integrity sha512-wYpPs3hgTFblMYwbYWPT3eZtaDOjbLyIYuqpwuLBBqhLiuvJ+9sEp2gNRJEtR5N/c9G1uTtQQL5AhV0fEPJYcg== dependencies: - "@typescript-eslint/typescript-estree" "6.9.1" - "@typescript-eslint/utils" "6.9.1" + "@typescript-eslint/typescript-estree" "6.10.0" + "@typescript-eslint/utils" "6.10.0" debug "^4.3.4" ts-api-utils "^1.0.1" -"@typescript-eslint/types@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.9.1.tgz#a6cfc20db0fcedcb2f397ea728ef583e0ee72459" - integrity sha512-BUGslGOb14zUHOUmDB2FfT6SI1CcZEJYfF3qFwBeUrU6srJfzANonwRYHDpLBuzbq3HaoF2XL2hcr01c8f8OaQ== +"@typescript-eslint/types@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.10.0.tgz#f4f0a84aeb2ac546f21a66c6e0da92420e921367" + integrity sha512-36Fq1PWh9dusgo3vH7qmQAj5/AZqARky1Wi6WpINxB6SkQdY5vQoT2/7rW7uBIsPDcvvGCLi4r10p0OJ7ITAeg== -"@typescript-eslint/typescript-estree@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.9.1.tgz#8c77910a49a04f0607ba94d78772da07dab275ad" - integrity sha512-U+mUylTHfcqeO7mLWVQ5W/tMLXqVpRv61wm9ZtfE5egz7gtnmqVIw9ryh0mgIlkKk9rZLY3UHygsBSdB9/ftyw== +"@typescript-eslint/typescript-estree@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.10.0.tgz#667381eed6f723a1a8ad7590a31f312e31e07697" + integrity sha512-ek0Eyuy6P15LJVeghbWhSrBCj/vJpPXXR+EpaRZqou7achUWL8IdYnMSC5WHAeTWswYQuP2hAZgij/bC9fanBg== dependencies: - "@typescript-eslint/types" "6.9.1" - "@typescript-eslint/visitor-keys" "6.9.1" + "@typescript-eslint/types" "6.10.0" + "@typescript-eslint/visitor-keys" "6.10.0" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/utils@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.9.1.tgz#763da41281ef0d16974517b5f0d02d85897a1c1e" - integrity sha512-L1T0A5nFdQrMVunpZgzqPL6y2wVreSyHhKGZryS6jrEN7bD9NplVAyMryUhXsQ4TWLnZmxc2ekar/lSGIlprCA== +"@typescript-eslint/utils@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.10.0.tgz#4d76062d94413c30e402c9b0df8c14aef8d77336" + integrity sha512-v+pJ1/RcVyRc0o4wAGux9x42RHmAjIGzPRo538Z8M1tVx6HOnoQBCX/NoadHQlZeC+QO2yr4nNSFWOoraZCAyg== dependencies: "@eslint-community/eslint-utils" "^4.4.0" "@types/json-schema" "^7.0.12" "@types/semver" "^7.5.0" - "@typescript-eslint/scope-manager" "6.9.1" - "@typescript-eslint/types" "6.9.1" - "@typescript-eslint/typescript-estree" "6.9.1" + "@typescript-eslint/scope-manager" "6.10.0" + "@typescript-eslint/types" "6.10.0" + "@typescript-eslint/typescript-estree" "6.10.0" semver "^7.5.4" -"@typescript-eslint/visitor-keys@6.9.1": - version "6.9.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.9.1.tgz#6753a9225a0ba00459b15d6456b9c2780b66707d" - integrity sha512-MUaPUe/QRLEffARsmNfmpghuQkW436DvESW+h+M52w0coICHRfD6Np9/K6PdACwnrq1HmuLl+cSPZaJmeVPkSw== +"@typescript-eslint/visitor-keys@6.10.0": + version "6.10.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.10.0.tgz#b9eaf855a1ac7e95633ae1073af43d451e8f84e3" + integrity sha512-xMGluxQIEtOM7bqFCo+rCMh5fqI+ZxV5RUUOa29iVPz1OgCZrtc7rFnz5cLUazlkPKYqX+75iuDq7m0HQ48nCg== dependencies: - "@typescript-eslint/types" "6.9.1" + "@typescript-eslint/types" "6.10.0" eslint-visitor-keys "^3.4.1" "@ungap/structured-clone@^1.2.0": From 1bd7349dace9bfad93d1d9049676eaf13952a8e4 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Thu, 9 Nov 2023 21:25:42 -0500 Subject: [PATCH 19/26] chore: update --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 238b9a08..9ee53b02 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "mongoose": "^8.0.0 || ^7.0.0 || ^6.0.0" }, "devDependencies": { - "@types/jest": "29.5.7", + "@types/jest": "29.5.8", "@typescript-eslint/eslint-plugin": "6.10.0", "@typescript-eslint/parser": "6.10.0", "eslint": "8.53.0", diff --git a/yarn.lock b/yarn.lock index 9740a6bb..663bc5df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -813,10 +813,10 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jest@29.5.7": - version "29.5.7" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.7.tgz#2c0dafe2715dd958a455bc10e2ec3e1ec47b5036" - integrity sha512-HLyetab6KVPSiF+7pFcUyMeLsx25LDNDemw9mGsJBkai/oouwrjTycocSDYopMEwFhN2Y4s9oPyOCZNofgSt2g== +"@types/jest@29.5.8": + version "29.5.8" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.8.tgz#ed5c256fe2bc7c38b1915ee5ef1ff24a3427e120" + integrity sha512-fXEFTxMV2Co8ZF5aYFJv+YeA08RTYJfhtN5c9JSv/mFEMe+xxjufCb+PHL+bJcMs/ebPUsBu+UNTEz+ydXrR6g== dependencies: expect "^29.0.0" pretty-format "^29.0.0" From 08f74ad410e6d158e701d4fe014a1cef0b3ca4f1 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Mon, 13 Nov 2023 01:50:31 -0500 Subject: [PATCH 20/26] chore: update --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9ee53b02..bf913b2c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "jest": "29.7.0", "mongodb-memory-server": "9.0.1", "mongoose": "8.0.0", - "prettier": "3.0.3", + "prettier": "3.1.0", "request": "2.88.2", "rimraf": "5.0.5", "ts-jest": "29.1.1", diff --git a/yarn.lock b/yarn.lock index 663bc5df..6414b0b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3826,10 +3826,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@3.0.3: - version "3.0.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643" - integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg== +prettier@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.0.tgz#c6d16474a5f764ea1a4a373c593b779697744d5e" + integrity sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw== pretty-format@^29.0.0, pretty-format@^29.7.0: version "29.7.0" From 27e497c7043d0814ef43913735ed402659be31b7 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Mon, 13 Nov 2023 01:53:02 -0500 Subject: [PATCH 21/26] chore: update --- src/resolvers/helpers/payloadRecordId.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resolvers/helpers/payloadRecordId.ts b/src/resolvers/helpers/payloadRecordId.ts index 4425f548..575bdc7e 100644 --- a/src/resolvers/helpers/payloadRecordId.ts +++ b/src/resolvers/helpers/payloadRecordId.ts @@ -51,8 +51,8 @@ export function payloadRecordIds( type: opts?.type ? opts.type : tc.hasField('_id') - ? toInputType(tc.getFieldTC('_id')).NonNull.List.NonNull - : '[MongoID!]!', + ? toInputType(tc.getFieldTC('_id')).NonNull.List.NonNull + : '[MongoID!]!', resolve: (source, _, context) => { const docs = (source as any)?.records; if (opts?.fn) { From 885c40940babe2e446deccfb7e652889c925efe7 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Mon, 13 Nov 2023 02:01:20 -0500 Subject: [PATCH 22/26] chore: fix test port number --- src/__mocks__/mongooseCommon.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/__mocks__/mongooseCommon.ts b/src/__mocks__/mongooseCommon.ts index 90a73576..001843f0 100644 --- a/src/__mocks__/mongooseCommon.ts +++ b/src/__mocks__/mongooseCommon.ts @@ -2,14 +2,29 @@ import mongoose from 'mongoose'; import MongoMemoryServer from 'mongodb-memory-server-core'; +import net, { AddressInfo } from 'net'; const { Schema, Types } = mongoose; mongoose.Promise = Promise; +async function getPortFree() { + return new Promise((res) => { + const srv = net.createServer(); + srv.listen(0, () => { + const port = (srv.address() as AddressInfo).port; + srv.close(() => res(port)); + }); + }); +} + const originalConnect = mongoose.connect; mongoose.createConnection = (async () => { - const mongoServer = await MongoMemoryServer.create(); + const mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); originalConnect.bind(mongoose)(mongoUri, {}); From 1cec3a5742159de908b0fc009d59165c3f89da73 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Mon, 13 Nov 2023 02:07:21 -0500 Subject: [PATCH 23/26] chore: fix test port number --- src/__mocks__/mongooseCommon.ts | 2 +- src/__tests__/github_issues/117-test.ts | 7 +++++- src/__tests__/github_issues/120-test.ts | 7 +++++- src/__tests__/github_issues/128-test.ts | 7 +++++- src/__tests__/github_issues/135-test.ts | 7 +++++- src/__tests__/github_issues/136-test.ts | 7 +++++- src/__tests__/github_issues/157-test.ts | 7 +++++- src/__tests__/github_issues/194-test.ts | 7 +++++- src/__tests__/github_issues/248-test.ts | 31 ++++++++++++++----------- src/__tests__/github_issues/78-test.ts | 7 +++++- 10 files changed, 67 insertions(+), 22 deletions(-) diff --git a/src/__mocks__/mongooseCommon.ts b/src/__mocks__/mongooseCommon.ts index 001843f0..8af4b9f1 100644 --- a/src/__mocks__/mongooseCommon.ts +++ b/src/__mocks__/mongooseCommon.ts @@ -8,7 +8,7 @@ const { Schema, Types } = mongoose; mongoose.Promise = Promise; -async function getPortFree() { +export async function getPortFree() { return new Promise((res) => { const srv = net.createServer(); srv.listen(0, () => { diff --git a/src/__tests__/github_issues/117-test.ts b/src/__tests__/github_issues/117-test.ts index 8c4b3148..d96bc22a 100644 --- a/src/__tests__/github_issues/117-test.ts +++ b/src/__tests__/github_issues/117-test.ts @@ -1,10 +1,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/120-test.ts b/src/__tests__/github_issues/120-test.ts index ebbe58f7..b51b699a 100644 --- a/src/__tests__/github_issues/120-test.ts +++ b/src/__tests__/github_issues/120-test.ts @@ -3,10 +3,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/128-test.ts b/src/__tests__/github_issues/128-test.ts index 1cf9bca3..254b9ef1 100644 --- a/src/__tests__/github_issues/128-test.ts +++ b/src/__tests__/github_issues/128-test.ts @@ -3,10 +3,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/135-test.ts b/src/__tests__/github_issues/135-test.ts index d0a866aa..793ce061 100644 --- a/src/__tests__/github_issues/135-test.ts +++ b/src/__tests__/github_issues/135-test.ts @@ -4,10 +4,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { schemaComposer, graphql } from 'graphql-compose'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/136-test.ts b/src/__tests__/github_issues/136-test.ts index cc930b01..4b985ce7 100644 --- a/src/__tests__/github_issues/136-test.ts +++ b/src/__tests__/github_issues/136-test.ts @@ -4,10 +4,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { schemaComposer, graphql } from 'graphql-compose'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/157-test.ts b/src/__tests__/github_issues/157-test.ts index 26d3d31c..945a8889 100644 --- a/src/__tests__/github_issues/157-test.ts +++ b/src/__tests__/github_issues/157-test.ts @@ -4,10 +4,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { schemaComposer, graphql } from 'graphql-compose'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/194-test.ts b/src/__tests__/github_issues/194-test.ts index 9b767f78..a10402c8 100644 --- a/src/__tests__/github_issues/194-test.ts +++ b/src/__tests__/github_issues/194-test.ts @@ -4,10 +4,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { schemaComposer, graphql } from 'graphql-compose'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, diff --git a/src/__tests__/github_issues/248-test.ts b/src/__tests__/github_issues/248-test.ts index ae9163b5..65477576 100644 --- a/src/__tests__/github_issues/248-test.ts +++ b/src/__tests__/github_issues/248-test.ts @@ -2,10 +2,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { schemaComposer, graphql } from 'graphql-compose'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, @@ -49,9 +54,9 @@ describe("issue #248 - payloads' errors", () => { const res = await graphql.graphql({ schema, source: ` - mutation { - createOne(record: { name: "John", someStrangeField: "Test" }) { - record { + mutation { + createOne(record: { name: "John", someStrangeField: "Test" }) { + record { name } error { @@ -94,9 +99,9 @@ describe("issue #248 - payloads' errors", () => { const res = await graphql.graphql({ schema, source: ` - mutation { - createOne(record: { name: "John", someStrangeField: "Test" }) { - record { + mutation { + createOne(record: { name: "John", someStrangeField: "Test" }) { + record { name } } @@ -131,9 +136,9 @@ describe("issue #248 - payloads' errors", () => { const res = await graphql.graphql({ schema, source: ` - mutation { - createMany(records: [{ name: "Ok"}, { name: "John", someStrangeField: "Test" }]) { - records { + mutation { + createMany(records: [{ name: "Ok"}, { name: "John", someStrangeField: "Test" }]) { + records { name } error { @@ -178,9 +183,9 @@ describe("issue #248 - payloads' errors", () => { const res = await graphql.graphql({ schema, source: ` - mutation { - createMany(records: [{ name: "Ok"}, { name: "John", someStrangeField: "Test" }]) { - records { + mutation { + createMany(records: [{ name: "Ok"}, { name: "John", someStrangeField: "Test" }]) { + records { name } } diff --git a/src/__tests__/github_issues/78-test.ts b/src/__tests__/github_issues/78-test.ts index 527a3085..ae71eb3a 100644 --- a/src/__tests__/github_issues/78-test.ts +++ b/src/__tests__/github_issues/78-test.ts @@ -2,10 +2,15 @@ import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; import { schemaComposer, graphql } from 'graphql-compose'; import { composeWithMongoose } from '../../index'; +import { getPortFree } from '../../__mocks__/mongooseCommon'; let mongoServer: MongoMemoryServer; beforeAll(async () => { - mongoServer = await MongoMemoryServer.create(); + mongoServer = await MongoMemoryServer.create({ + instance: { + port: await getPortFree(), + }, + }); const mongoUri = mongoServer.getUri(); await mongoose.connect( mongoUri, From c35cbbfcf00bc1f316cb50532383d37a893d9159 Mon Sep 17 00:00:00 2001 From: Mohamed Meabed Date: Tue, 14 Nov 2023 13:28:26 -0500 Subject: [PATCH 24/26] chore: update pkhs --- package.json | 4 +-- yarn.lock | 100 +++++++++++++++++++++++++-------------------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/package.json b/package.json index bf913b2c..61f2baa7 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ }, "devDependencies": { "@types/jest": "29.5.8", - "@typescript-eslint/eslint-plugin": "6.10.0", - "@typescript-eslint/parser": "6.10.0", + "@typescript-eslint/eslint-plugin": "6.11.0", + "@typescript-eslint/parser": "6.11.0", "eslint": "8.53.0", "eslint-config-airbnb-base": "15.0.0", "eslint-config-prettier": "9.0.0", diff --git a/yarn.lock b/yarn.lock index 6414b0b3..ceaed30c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -871,16 +871,16 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.10.0.tgz#cfe2bd34e26d2289212946b96ab19dcad64b661a" - integrity sha512-uoLj4g2OTL8rfUQVx2AFO1hp/zja1wABJq77P6IclQs6I/m9GLrm7jCdgzZkvWdDCQf1uEvoa8s8CupsgWQgVg== +"@typescript-eslint/eslint-plugin@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.11.0.tgz#52aae65174ff526576351f9ccd41cea01001463f" + integrity sha512-uXnpZDc4VRjY4iuypDBKzW1rz9T5YBBK0snMn8MaTSNd2kMlj50LnLBABELjJiOL5YHk7ZD8hbSpI9ubzqYI0w== dependencies: "@eslint-community/regexpp" "^4.5.1" - "@typescript-eslint/scope-manager" "6.10.0" - "@typescript-eslint/type-utils" "6.10.0" - "@typescript-eslint/utils" "6.10.0" - "@typescript-eslint/visitor-keys" "6.10.0" + "@typescript-eslint/scope-manager" "6.11.0" + "@typescript-eslint/type-utils" "6.11.0" + "@typescript-eslint/utils" "6.11.0" + "@typescript-eslint/visitor-keys" "6.11.0" debug "^4.3.4" graphemer "^1.4.0" ignore "^5.2.4" @@ -888,72 +888,72 @@ semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/parser@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.10.0.tgz#578af79ae7273193b0b6b61a742a2bc8e02f875a" - integrity sha512-+sZwIj+s+io9ozSxIWbNB5873OSdfeBEH/FR0re14WLI6BaKuSOnnwCJ2foUiu8uXf4dRp1UqHP0vrZ1zXGrog== +"@typescript-eslint/parser@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.11.0.tgz#9640d9595d905f3be4f278bf515130e6129b202e" + integrity sha512-+whEdjk+d5do5nxfxx73oanLL9ghKO3EwM9kBCkUtWMRwWuPaFv9ScuqlYfQ6pAD6ZiJhky7TZ2ZYhrMsfMxVQ== dependencies: - "@typescript-eslint/scope-manager" "6.10.0" - "@typescript-eslint/types" "6.10.0" - "@typescript-eslint/typescript-estree" "6.10.0" - "@typescript-eslint/visitor-keys" "6.10.0" + "@typescript-eslint/scope-manager" "6.11.0" + "@typescript-eslint/types" "6.11.0" + "@typescript-eslint/typescript-estree" "6.11.0" + "@typescript-eslint/visitor-keys" "6.11.0" debug "^4.3.4" -"@typescript-eslint/scope-manager@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.10.0.tgz#b0276118b13d16f72809e3cecc86a72c93708540" - integrity sha512-TN/plV7dzqqC2iPNf1KrxozDgZs53Gfgg5ZHyw8erd6jd5Ta/JIEcdCheXFt9b1NYb93a1wmIIVW/2gLkombDg== +"@typescript-eslint/scope-manager@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.11.0.tgz#621f603537c89f4d105733d949aa4d55eee5cea8" + integrity sha512-0A8KoVvIURG4uhxAdjSaxy8RdRE//HztaZdG8KiHLP8WOXSk0vlF7Pvogv+vlJA5Rnjj/wDcFENvDaHb+gKd1A== dependencies: - "@typescript-eslint/types" "6.10.0" - "@typescript-eslint/visitor-keys" "6.10.0" + "@typescript-eslint/types" "6.11.0" + "@typescript-eslint/visitor-keys" "6.11.0" -"@typescript-eslint/type-utils@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.10.0.tgz#1007faede067c78bdbcef2e8abb31437e163e2e1" - integrity sha512-wYpPs3hgTFblMYwbYWPT3eZtaDOjbLyIYuqpwuLBBqhLiuvJ+9sEp2gNRJEtR5N/c9G1uTtQQL5AhV0fEPJYcg== +"@typescript-eslint/type-utils@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.11.0.tgz#d0b8b1ab6c26b974dbf91de1ebc5b11fea24e0d1" + integrity sha512-nA4IOXwZtqBjIoYrJcYxLRO+F9ri+leVGoJcMW1uqr4r1Hq7vW5cyWrA43lFbpRvQ9XgNrnfLpIkO3i1emDBIA== dependencies: - "@typescript-eslint/typescript-estree" "6.10.0" - "@typescript-eslint/utils" "6.10.0" + "@typescript-eslint/typescript-estree" "6.11.0" + "@typescript-eslint/utils" "6.11.0" debug "^4.3.4" ts-api-utils "^1.0.1" -"@typescript-eslint/types@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.10.0.tgz#f4f0a84aeb2ac546f21a66c6e0da92420e921367" - integrity sha512-36Fq1PWh9dusgo3vH7qmQAj5/AZqARky1Wi6WpINxB6SkQdY5vQoT2/7rW7uBIsPDcvvGCLi4r10p0OJ7ITAeg== +"@typescript-eslint/types@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.11.0.tgz#8ad3aa000cbf4bdc4dcceed96e9b577f15e0bf53" + integrity sha512-ZbEzuD4DwEJxwPqhv3QULlRj8KYTAnNsXxmfuUXFCxZmO6CF2gM/y+ugBSAQhrqaJL3M+oe4owdWunaHM6beqA== -"@typescript-eslint/typescript-estree@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.10.0.tgz#667381eed6f723a1a8ad7590a31f312e31e07697" - integrity sha512-ek0Eyuy6P15LJVeghbWhSrBCj/vJpPXXR+EpaRZqou7achUWL8IdYnMSC5WHAeTWswYQuP2hAZgij/bC9fanBg== +"@typescript-eslint/typescript-estree@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.11.0.tgz#7b52c12a623bf7f8ec7f8a79901b9f98eb5c7990" + integrity sha512-Aezzv1o2tWJwvZhedzvD5Yv7+Lpu1by/U1LZ5gLc4tCx8jUmuSCMioPFRjliN/6SJIvY6HpTtJIWubKuYYYesQ== dependencies: - "@typescript-eslint/types" "6.10.0" - "@typescript-eslint/visitor-keys" "6.10.0" + "@typescript-eslint/types" "6.11.0" + "@typescript-eslint/visitor-keys" "6.11.0" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/utils@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.10.0.tgz#4d76062d94413c30e402c9b0df8c14aef8d77336" - integrity sha512-v+pJ1/RcVyRc0o4wAGux9x42RHmAjIGzPRo538Z8M1tVx6HOnoQBCX/NoadHQlZeC+QO2yr4nNSFWOoraZCAyg== +"@typescript-eslint/utils@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.11.0.tgz#11374f59ef4cea50857b1303477c08aafa2ca604" + integrity sha512-p23ibf68fxoZy605dc0dQAEoUsoiNoP3MD9WQGiHLDuTSOuqoTsa4oAy+h3KDkTcxbbfOtUjb9h3Ta0gT4ug2g== dependencies: "@eslint-community/eslint-utils" "^4.4.0" "@types/json-schema" "^7.0.12" "@types/semver" "^7.5.0" - "@typescript-eslint/scope-manager" "6.10.0" - "@typescript-eslint/types" "6.10.0" - "@typescript-eslint/typescript-estree" "6.10.0" + "@typescript-eslint/scope-manager" "6.11.0" + "@typescript-eslint/types" "6.11.0" + "@typescript-eslint/typescript-estree" "6.11.0" semver "^7.5.4" -"@typescript-eslint/visitor-keys@6.10.0": - version "6.10.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.10.0.tgz#b9eaf855a1ac7e95633ae1073af43d451e8f84e3" - integrity sha512-xMGluxQIEtOM7bqFCo+rCMh5fqI+ZxV5RUUOa29iVPz1OgCZrtc7rFnz5cLUazlkPKYqX+75iuDq7m0HQ48nCg== +"@typescript-eslint/visitor-keys@6.11.0": + version "6.11.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.11.0.tgz#d991538788923f92ec40d44389e7075b359f3458" + integrity sha512-+SUN/W7WjBr05uRxPggJPSzyB8zUpaYo2hByKasWbqr3PM8AXfZt8UHdNpBS1v9SA62qnSSMF3380SwDqqprgQ== dependencies: - "@typescript-eslint/types" "6.10.0" + "@typescript-eslint/types" "6.11.0" eslint-visitor-keys "^3.4.1" "@ungap/structured-clone@^1.2.0": From 2b80ad2bf9b541266428d751d126ddc225f9f628 Mon Sep 17 00:00:00 2001 From: nodkz Date: Wed, 15 Nov 2023 01:03:01 +0100 Subject: [PATCH 25/26] fix: alias in compound index ```diff - UserSchema.index({ name: 1, age: -1 }); + UserSchema.index({ n: 1, age: -1 }); ``` --- jest.config.js | 1 - src/__mocks__/userModel.ts | 2 +- src/composeMongoose.ts | 2 -- .../helpers/__tests__/filter-test.ts | 4 ++-- src/setupTests.ts | 6 ----- src/utils/getIndexesFromModel.ts | 24 ++++++++----------- 6 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 src/setupTests.ts diff --git a/jest.config.js b/jest.config.js index 2fb13eed..fcb3f76e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,6 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', moduleFileExtensions: ['ts', 'js'], - setupFilesAfterEnv: ['/src/setupTests.ts'], transform: { '^.+\\.ts$': [ 'ts-jest', diff --git a/src/__mocks__/userModel.ts b/src/__mocks__/userModel.ts index 671c7f70..31e1b9c0 100644 --- a/src/__mocks__/userModel.ts +++ b/src/__mocks__/userModel.ts @@ -139,7 +139,7 @@ const UserSchema = new Schema( ); UserSchema.set('autoIndex', false); -UserSchema.index({ name: 1, age: -1 }); +UserSchema.index({ n: 1, age: -1 }); // eslint-disable-next-line UserSchema.virtual('nameVirtual').get(function (this: any) { diff --git a/src/composeMongoose.ts b/src/composeMongoose.ts index 2c13c35c..ca199724 100644 --- a/src/composeMongoose.ts +++ b/src/composeMongoose.ts @@ -4,7 +4,6 @@ import type { Document, Model } from 'mongoose'; import { convertModelToGraphQL } from './fieldsConverter'; import { resolverFactory } from './resolvers'; import MongoID from './types/MongoID'; -import { patchMongooseSchemaIndex } from './utils/patchMongoose'; export type TypeConverterInputTypeOpts = { /** @@ -121,7 +120,6 @@ export function composeMongoose( `You try to generate GraphQL Type with name ${name} from mongoose model but this type already exists in SchemaComposer. Please choose another type name "composeWithMongoose(model, { name: 'NewTypeName' })", or reuse existed type "schemaComposer.getOTC('TypeName')", or remove type from SchemaComposer before calling composeWithMongoose method "schemaComposer.delete('TypeName')".` ); } - patchMongooseSchemaIndex(); if (sc.has(m.schema)) { // looks like you want to generate new TypeComposer from model diff --git a/src/resolvers/helpers/__tests__/filter-test.ts b/src/resolvers/helpers/__tests__/filter-test.ts index 656c270d..b190e446 100644 --- a/src/resolvers/helpers/__tests__/filter-test.ts +++ b/src/resolvers/helpers/__tests__/filter-test.ts @@ -90,7 +90,7 @@ describe('Resolver helper `filter` ->', () => { const itc = args.filter.type as InputTypeComposer; expect(itc.hasField('_id')).toBe(true); expect(itc.hasField('name')).toBe(true); - expect(itc.hasField('age')).toBe(true); + expect(itc.hasField('age')).toBe(false); expect(itc.hasField('gender')).toBe(false); }); @@ -104,7 +104,7 @@ describe('Resolver helper `filter` ->', () => { const itc = args.filter.type as InputTypeComposer; expect(itc.hasField('_id')).toBe(true); expect(itc.hasField('name')).toBe(false); - expect(itc.hasField('age')).toBe(true); + expect(itc.hasField('age')).toBe(false); expect(itc.hasField('gender')).toBe(false); }); diff --git a/src/setupTests.ts b/src/setupTests.ts deleted file mode 100644 index 9a9935e3..00000000 --- a/src/setupTests.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { patchMongooseSchemaIndex } from './utils/patchMongoose'; -import { beforeAll } from '@jest/globals'; - -beforeAll(() => { - patchMongooseSchemaIndex(); -}); diff --git a/src/utils/getIndexesFromModel.ts b/src/utils/getIndexesFromModel.ts index 6e8ee60d..d1a3d43c 100644 --- a/src/utils/getIndexesFromModel.ts +++ b/src/utils/getIndexesFromModel.ts @@ -1,4 +1,5 @@ import type { Model } from 'mongoose'; +import { prepareAliasesReverse } from '../resolvers/helpers/aliases'; export type getIndexesFromModelOpts = { extractCompound?: boolean; // true by default @@ -36,11 +37,13 @@ export function getIndexesFromModel( indexedFields.push({ _id: 1 }); } + const reversedAliases = prepareAliasesReverse(mongooseModel.schema); + // scan all fields on index presence [MONGOOSE FIELDS LEVEL INDEX] Object.keys(mongooseModel.schema.paths).forEach((name) => { if ((mongooseModel.schema.paths[name] as any)._index) { - const aliasOrName = mongooseModel.schema.paths[name]?.options?.alias || name; - indexedFields.push({ [aliasOrName]: 1 }); // ASC by default + const fieldName = (reversedAliases && reversedAliases[name]) || name; + indexedFields.push({ [fieldName]: 1 }); // ASC by default } }); @@ -56,15 +59,10 @@ export function getIndexesFromModel( } else { // extract partial indexes from compound index // { name: 1, age: 1, salary: 1} -> [{name:1}, {name:1, age:1}, {name:1, age:1, salary:1}] - Object.keys(idxFields).forEach((fieldName: any) => { - const alias = mongooseModel.schema.paths[fieldName]?.options?.alias; - const aliasOrName = alias || fieldName; - partialIndexes[aliasOrName] = idxFields[fieldName]; + Object.keys(idxFields).forEach((name: any) => { + const fieldName = (reversedAliases && reversedAliases[name]) || name; + partialIndexes[fieldName] = idxFields[name]; indexedFields.push({ ...partialIndexes }); - // push aliases on it's own index if its compound - if (alias) { - indexedFields.push({ [aliasOrName]: idxFields[fieldName] }); - } }); } } @@ -155,10 +153,8 @@ export function getIndexedFieldNamesForGraphQL(model: Model): string[] { const fieldNames: string[] = []; indexes.forEach((indexData) => { const keys = Object.keys(indexData); - for (let i = 0; i < keys.length; i++) { - const clearedName = keys[i].replace(/[^_a-zA-Z0-9]/i, '__'); - fieldNames.push(clearedName); - } + const clearedName = keys[0].replace(/[^_a-zA-Z0-9]/i, '__'); + fieldNames.push(clearedName); }); // filter duplicates const uniqueNames: string[] = []; From bc859d951cb66f989a4f6d16007d91f8822d4ead Mon Sep 17 00:00:00 2001 From: nodkz Date: Wed, 15 Nov 2023 01:26:46 +0100 Subject: [PATCH 26/26] remove patchMongoose.ts --- src/utils/patchMongoose.ts | 42 -------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/utils/patchMongoose.ts diff --git a/src/utils/patchMongoose.ts b/src/utils/patchMongoose.ts deleted file mode 100644 index c62da024..00000000 --- a/src/utils/patchMongoose.ts +++ /dev/null @@ -1,42 +0,0 @@ -import mongoose, { IndexDefinition, IndexOptions } from 'mongoose'; - -export function renameObjKey( - oldObj: Record, - oldKey: string, - newKey: string | number -) { - const keys = Object.keys(oldObj); - return keys.reduce( - (acc, val) => { - if (val === oldKey) { - acc[newKey] = oldObj[oldKey]; - } else { - acc[val] = oldObj[val]; - } - return acc; - }, - {} as Record - ); -} - -const oldMongooseSchemaIndexDef = mongoose.Schema.prototype.index; -mongoose.Schema.prototype.index = function (fields: IndexDefinition, options?: IndexOptions) { - // @ts-ignore - if (mongoose.Schema.prototype.indexMethodPatched) { - return oldMongooseSchemaIndexDef.call(this, fields, options); - } - fields || (fields = {}); - options || (options = {}); - for (const key in fields) { - // @ts-ignore - if (this.aliases[key]) { - // @ts-ignore - fields = renameObjKey(fields, key, this.aliases[key]); - } - } - // @ts-ignore - mongoose.Schema.prototype.indexMethodPatched = true; - return oldMongooseSchemaIndexDef.call(this, fields, options); -}; - -export function patchMongooseSchemaIndex() {}