feat: Implement deleteConnection mutation
This commit is contained in:
26
packages/backend/src/graphql/mutations/delete-connection.ts
Normal file
26
packages/backend/src/graphql/mutations/delete-connection.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { GraphQLString, GraphQLNonNull, GraphQLBoolean } from 'graphql';
|
||||||
|
import Connection from '../../models/connection';
|
||||||
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
id: string,
|
||||||
|
data: object
|
||||||
|
}
|
||||||
|
const deleteConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
|
await Connection.query().delete().findOne({
|
||||||
|
user_id: req.currentUser.id,
|
||||||
|
id: params.id
|
||||||
|
})
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteConnection = {
|
||||||
|
type: GraphQLBoolean,
|
||||||
|
args: {
|
||||||
|
id: { type: GraphQLNonNull(GraphQLString) }
|
||||||
|
},
|
||||||
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => deleteConnectionResolver(params, req)
|
||||||
|
};
|
||||||
|
|
||||||
|
export default deleteConnection;
|
@@ -2,13 +2,15 @@ import { GraphQLObjectType } from 'graphql';
|
|||||||
import createConnection from './mutations/create-connection';
|
import createConnection from './mutations/create-connection';
|
||||||
import createAuthLink from './mutations/create-auth-link';
|
import createAuthLink from './mutations/create-auth-link';
|
||||||
import updateConnection from './mutations/update-connection';
|
import updateConnection from './mutations/update-connection';
|
||||||
|
import deleteConnection from './mutations/delete-connection';
|
||||||
|
|
||||||
const rootMutation = new GraphQLObjectType({
|
const rootMutation = new GraphQLObjectType({
|
||||||
name: 'Mutation',
|
name: 'Mutation',
|
||||||
fields: {
|
fields: {
|
||||||
createConnection: createConnection,
|
createConnection,
|
||||||
createAuthLink: createAuthLink,
|
createAuthLink,
|
||||||
updateConnection: updateConnection
|
updateConnection,
|
||||||
|
deleteConnection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user