nestjs-query
nestjs-query copied to clipboard
GraphQL Mutation, Error when subset contains entity that was not created
Describe the bug When mutation is used to generate an object and ones query in the subset a relation an error occurs.
- Use relation for graphql: @Relation('campaignMetrics', () => CampaignMetricsEntity, { disableRemove: true, nullable: true}) export class CampaignDTO { ... }
- campaignmetrics mongoose reference in in campaign:
@Prop({ type: SchemaTypes.ObjectId, ref: 'CampaignMetricsEntity' })
campaignMetrics!: Types.ObjectId
- Use mutation to create one campaign, with subset of a relation:
mutation {
createOneCampaign(input: {
campaign: {
campaignName:"test",
campaignType: "cpc",
}
}) {campaignMetrics {budget{range{maximumAmount{value}}}}}
}
- following error occurs: "message": "foundEntity.populate(...).execPopulate is not a function",
the found entity is campaign metrics but its empty because there is no entity created on the mutation
Expected behavior Not to throw an error on relations
it seems there is a check missing in reference query service that
foundEntity[relationName] is given
backend/node_modules/@nestjs-query/query-mongoose/dist/src/services/reference-query.service.js:70
Desktop (please complete the following information): "@nestjs-query/core": "^0.30.0",
Additional context If a mutation also queries a relation but the mutation will not create the related object this error is thrown
I also added nullable: true on the mongoose property and this error occurs this makes no sense to me.
**** Addtion ****
Seems nestjs upgraded to mongoose 6 and this library is still incompatible. Makes it very difficult to implement then. Sad
Same bug for nestjs-typegoose
package:
(https://github.com/doug-martin/nestjs-query/blob/master/packages/query-typegoose/src/services/reference-query.service.ts#L160)
Must be updated following the migration guide: https://mongoosejs.com/docs/migrating_to_6.html#removed-execpopulate