feat: custom objects delete one (#2278)

* feat: custom objects delete one

* fix: delete one issue
This commit is contained in:
Jérémy M
2023-10-30 12:05:03 +01:00
committed by GitHub
parent 6640f2a651
commit 80a6223d7d
4 changed files with 52 additions and 0 deletions

View File

@ -88,4 +88,19 @@ export class EntityResolverService {
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);
}
}

View File

@ -19,6 +19,7 @@ type CommandArgs = {
findOne: { filter?: any };
createMany: { data: any[] };
updateOne: { id: string; data: any };
deleteOne: { id: string };
};
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}
}
}
}
`;
}
}

View File

@ -103,4 +103,11 @@ export class PGGraphQLQueryRunner {
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];
}
}

View File

@ -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>;
}