Open dannydi12 opened 2 years ago
I found a solution! I did the following:
import { composeWithMongoose } from 'graphql-compose-mongoose'
import { Schema, model } from 'mongoose'
import { v4 as uuid } from 'uuid'
export type TestType = {
_id: string;
text: string;
type: 'captionLibrary' | 'dashboard';
}
export const TestSchema = new Schema<TestType>({
_id: { type: String, default: uuid },
text: { type: String, required: true },
type: { type: String, required: true }
})
export const Test = model('Test', TestSchema)
export const TestTC = composeWithMongoose(Test)
Turns out you can just define a default function in your Mongoose schema. That did the trick for me. I now have string UUIDs being generated from all my createOne mutations!
Thank you!
Hi, thank you for building such a great framework!
I need to be able to generate mutations that will automatically create _id. This functionality already exists but it builds a Mongo ObjectId. I need the ID to be a string.
The behavior I want to achieve:
ex: _id: 'some-UUID-234'
I think I can modify the default behavior by using
setRecordIdFn
on my object type composer but I can't get it to work.Shouldn't this work considering this excerpt from
payloadRecordId.ts
in this repo:Thank you for your time!