feat: custom objects delete one (#2278)
* feat: custom objects delete one * fix: delete one issue
This commit is contained in:
@ -88,4 +88,19 @@ export class EntityResolverService {
|
|||||||
|
|
||||||
return runner.updateOne(args);
|
return runner.updateOne(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteOne(
|
||||||
|
args: { id: string },
|
||||||
|
context: SchemaBuilderContext,
|
||||||
|
info: GraphQLResolveInfo,
|
||||||
|
) {
|
||||||
|
const runner = new PGGraphQLQueryRunner(this.dataSourceService, {
|
||||||
|
tableName: context.tableName,
|
||||||
|
workspaceId: context.workspaceId,
|
||||||
|
info,
|
||||||
|
fields: context.fields,
|
||||||
|
});
|
||||||
|
|
||||||
|
return runner.deleteOne(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ type CommandArgs = {
|
|||||||
findOne: { filter?: any };
|
findOne: { filter?: any };
|
||||||
createMany: { data: any[] };
|
createMany: { data: any[] };
|
||||||
updateOne: { id: string; data: any };
|
updateOne: { id: string; data: any };
|
||||||
|
deleteOne: { id: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface PGGraphQLQueryBuilderOptions {
|
export interface PGGraphQLQueryBuilderOptions {
|
||||||
@ -115,4 +116,20 @@ export class PGGraphQLQueryBuilder {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteOne(args: CommandArgs['deleteOne']) {
|
||||||
|
const { tableName } = this.options;
|
||||||
|
const fieldsString = this.getFieldsString();
|
||||||
|
|
||||||
|
return `
|
||||||
|
mutation {
|
||||||
|
deleteFrom${tableName}Collection(filter: { id: { eq: "${args.id}" } }) {
|
||||||
|
affectedCount
|
||||||
|
records {
|
||||||
|
${fieldsString}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,4 +103,11 @@ export class PGGraphQLQueryRunner {
|
|||||||
|
|
||||||
return this.parseResult(result, 'update')?.records?.[0];
|
return this.parseResult(result, 'update')?.records?.[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteOne(args: { id: string }): Promise<any> {
|
||||||
|
const query = this.queryBuilder.deleteOne(args);
|
||||||
|
const result = await this.execute(query, this.options.workspaceId);
|
||||||
|
|
||||||
|
return this.parseResult(result, 'deleteFrom')?.records?.[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -156,6 +156,19 @@ export class SchemaBuilderService {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
[`deleteOne${upperFirst(entityName.singular)}`]: {
|
||||||
|
type: new GraphQLNonNull(ObjectType),
|
||||||
|
args: {
|
||||||
|
id: { type: new GraphQLNonNull(GraphQLID) },
|
||||||
|
},
|
||||||
|
resolve: (root, args, context, info) => {
|
||||||
|
return this.entityResolverService.deleteOne(
|
||||||
|
args,
|
||||||
|
schemaBuilderContext,
|
||||||
|
info,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
} as GraphQLFieldConfigMap<any, any>;
|
} as GraphQLFieldConfigMap<any, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user