refactor: Use related query from objectionjs for mutations
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
e7c537f217
commit
86d5cceec7
@@ -1,26 +1,32 @@
|
||||
import { GraphQLInt, GraphQLNonNull, GraphQLBoolean } from 'graphql';
|
||||
import Connection from '../../models/connection';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
type Params = {
|
||||
id: number,
|
||||
data: object
|
||||
}
|
||||
const deleteConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
await Connection.query().delete().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.id
|
||||
}).throwIfNotFound();
|
||||
id: number;
|
||||
data: object;
|
||||
};
|
||||
const deleteConnectionResolver = async (
|
||||
params: Params,
|
||||
req: RequestWithCurrentUser
|
||||
) => {
|
||||
await req.currentUser
|
||||
.$relatedQuery('connections')
|
||||
.delete()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
const deleteConnection = {
|
||||
type: GraphQLBoolean,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLInt) }
|
||||
id: { type: GraphQLNonNull(GraphQLInt) },
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => deleteConnectionResolver(params, req)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
||||
deleteConnectionResolver(params, req),
|
||||
};
|
||||
|
||||
export default deleteConnection;
|
||||
|
Reference in New Issue
Block a user