Replies: 2 comments 5 replies
-
What does your code look like for the two entities? Also, this should be in discussions, as it isn't clear it is an issue. Converting. Scott |
Beta Was this translation helpful? Give feedback.
0 replies
-
Sorry for posting this as an issue and not a discussion. These are my two entities and their DTOs. story.entity.tsimport { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
@Schema({ collection: 'stories' })
export class StoryEntity extends Document {
@Prop({ required: true })
title!: string;
@Prop({ required: true })
text!: string;
}
export const StorySchema = SchemaFactory.createForClass(StoryEntity);
StorySchema.virtual('comments', {
ref: 'CommentEntity',
localField: '_id',
foreignField: 'story',
}); story.dto.tsimport {
CursorConnection,
FilterableField,
IDField,
KeySet,
} from '@nestjs-query/query-graphql';
import { ID, ObjectType } from '@nestjs/graphql';
import { CommentDTO } from 'src/comments/comment.dto';
@ObjectType('Story')
@KeySet(['id'])
@CursorConnection('comments', () => CommentDTO, { disableRemove: true })
export class StoryDTO {
@IDField(() => ID)
id!: string;
@FilterableField()
title!: string;
@FilterableField()
text!: string;
} comment.entity.tsimport { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, SchemaTypes, Types } from 'mongoose';
@Schema({ collection: 'comments' })
export class CommentEntity extends Document {
@Prop({ type: SchemaTypes.ObjectId, ref: 'StoryEntity', required: true })
story!: Types.ObjectId;
@Prop({ required: true })
text!: string;
}
export const CommentSchema = SchemaFactory.createForClass(CommentEntity); comment.dto.tsimport {
FilterableField,
IDField,
KeySet,
Relation,
} from '@nestjs-query/query-graphql';
import { ID, ObjectType } from '@nestjs/graphql';
import { StoryDTO } from 'src/stories/story.dto';
@ObjectType('Comment')
@KeySet(['id'])
@Relation('story', () => StoryDTO, { disableRemove: true })
export class CommentDTO {
@IDField(() => ID)
id!: string;
@FilterableField()
text!: string;
} My question is how I can create and link these two together through the relation. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have read the docs for relations with mongoose but I'm lost. I have created the relation between two DTOs but how do I actually link them together in GraphQL? I can create two individual entries but not figure out how to link them together. What mutations should I use and in what order?
Consider these two entries,
Story
andComment
. One of each can be created withcreateOne(Story/Comment)
but when I try to useaddCommentsToStory
it returnsAddRelations not supported for virtual relation comments
. What am I doing wrong?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions