From 4d37d39983ea6c75c7d3ea403d231bf95c37c9ce Mon Sep 17 00:00:00 2001 From: Eric Kitaif Date: Mon, 21 Oct 2019 08:24:08 -0700 Subject: [PATCH] Fixes on ObjectIdScalar and depreciated warning --- src/app.module.ts | 1 + src/graphql.classes.ts | 4 ++-- src/scalars/object-id.scalar.ts | 2 +- src/users/users.module.ts | 4 ++-- src/users/users.types.graphql | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index e4636aa..ad93811 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -17,6 +17,7 @@ import { ConfigService } from './config/config.service'; useNewUrlParser: true, useCreateIndex: true, useFindAndModify: false, + useUnifiedTopology: true, }; if (configService.mongoAuthEnabled) { diff --git a/src/graphql.classes.ts b/src/graphql.classes.ts index dc7fd13..ba875d0 100644 --- a/src/graphql.classes.ts +++ b/src/graphql.classes.ts @@ -66,7 +66,7 @@ export class User { updatedAt: Date; lastSeenAt: Date; enabled: boolean; - _id: MongoObjectId; + _id: ObjectId; } -export type MongoObjectId = any; +export type ObjectId = any; diff --git a/src/scalars/object-id.scalar.ts b/src/scalars/object-id.scalar.ts index 8a84796..d8bcc30 100644 --- a/src/scalars/object-id.scalar.ts +++ b/src/scalars/object-id.scalar.ts @@ -4,7 +4,7 @@ import { Types } from 'mongoose'; @Scalar('ObjectId') export class ObjectIdScalar { - description = 'Mongo ObjectId scalar type'; + description = 'MongoDB ObjectId scalar type, sent as 24 byte Hex String'; parseValue(value: string) { return new Types.ObjectId(value); // value from the client diff --git a/src/users/users.module.ts b/src/users/users.module.ts index 7d778a9..a941048 100644 --- a/src/users/users.module.ts +++ b/src/users/users.module.ts @@ -6,16 +6,16 @@ import { UserResolver } from './users.resolvers'; import { DateScalar } from '../scalars/date.scalar'; import { ConfigModule } from '../config/config.module'; import { AuthModule } from '../auth/auth.module'; +import { ObjectIdScalar } from '../scalars/object-id.scalar'; @Module({ imports: [ MongooseModule.forFeature([{ name: 'User', schema: UserSchema }]), - UsersModule, ConfigModule, forwardRef(() => AuthModule), ], exports: [UsersService], controllers: [], - providers: [UsersService, UserResolver, DateScalar], + providers: [UsersService, UserResolver, DateScalar, ObjectIdScalar], }) export class UsersModule {} diff --git a/src/users/users.types.graphql b/src/users/users.types.graphql index e73cdbf..79dad70 100644 --- a/src/users/users.types.graphql +++ b/src/users/users.types.graphql @@ -1,5 +1,5 @@ scalar Date -scalar MongoObjectId +scalar ObjectId type Query { users: [User!]! @@ -23,7 +23,7 @@ type User { updatedAt: Date! lastSeenAt: Date! enabled: Boolean! - _id: MongoObjectId! + _id: ObjectId! } input CreateUserInput {