feat: Introduce reset and verify connection mutations
This commit is contained in:
@@ -110,12 +110,34 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 5,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{createConnection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"reconnectionSteps": [
|
"reconnectionSteps": [
|
||||||
{
|
{
|
||||||
"step": 1,
|
"step": 1,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
|
"name": "resetConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 2,
|
||||||
|
"type": "mutation",
|
||||||
"name": "updateConnection",
|
"name": "updateConnection",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -139,7 +161,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step": 2,
|
"step": 3,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
"name": "createAuthLink",
|
"name": "createAuthLink",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -150,7 +172,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step": 3,
|
"step": 4,
|
||||||
"type": "openWithPopup",
|
"type": "openWithPopup",
|
||||||
"name": "openAuthPopup",
|
"name": "openAuthPopup",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -161,7 +183,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step": 4,
|
"step": 5,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
"name": "updateConnection",
|
"name": "updateConnection",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -180,6 +202,17 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 6,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -110,12 +110,34 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 5,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{createConnection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"reconnectionSteps": [
|
"reconnectionSteps": [
|
||||||
{
|
{
|
||||||
"step": 1,
|
"step": 1,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
|
"name": "resetConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 2,
|
||||||
|
"type": "mutation",
|
||||||
"name": "updateConnection",
|
"name": "updateConnection",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -139,7 +161,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step": 2,
|
"step": 3,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
"name": "createAuthLink",
|
"name": "createAuthLink",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -150,7 +172,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step": 3,
|
"step": 4,
|
||||||
"type": "openWithPopup",
|
"type": "openWithPopup",
|
||||||
"name": "openTwitterAuthPopup",
|
"name": "openTwitterAuthPopup",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -161,7 +183,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"step": 4,
|
"step": 5,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
"name": "updateConnection",
|
"name": "updateConnection",
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -180,6 +202,17 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 6,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
31
packages/backend/src/graphql/mutations/reset-connection.ts
Normal file
31
packages/backend/src/graphql/mutations/reset-connection.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
|
import Connection from '../../models/connection';
|
||||||
|
import connectionType from '../types/connection';
|
||||||
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
|
let connection = await Connection.query().findOne({
|
||||||
|
user_id: req.currentUser.id,
|
||||||
|
id: params.id
|
||||||
|
})
|
||||||
|
|
||||||
|
connection = await connection.$query().patchAndFetch({
|
||||||
|
data: { screenName: connection.data.screenName }
|
||||||
|
})
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetConnection = {
|
||||||
|
type: connectionType,
|
||||||
|
args: {
|
||||||
|
id: { type: GraphQLNonNull(GraphQLString) },
|
||||||
|
},
|
||||||
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => resetConnectionResolver(params, req)
|
||||||
|
};
|
||||||
|
|
||||||
|
export default resetConnection;
|
@@ -21,18 +21,6 @@ const updateConnectionResolver = async (params: Params, req: RequestWithCurrentU
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Not every updateConnection mutation can verify credentials as some need to reconnect
|
|
||||||
try {
|
|
||||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
|
||||||
|
|
||||||
const appInstance = new appClass(connection.data)
|
|
||||||
const verifiedCredentials = await appInstance.verifyCredentials();
|
|
||||||
|
|
||||||
connection = await connection.$query().patchAndFetch({
|
|
||||||
data: verifiedCredentials
|
|
||||||
})
|
|
||||||
} catch {}
|
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
35
packages/backend/src/graphql/mutations/verify-connection.ts
Normal file
35
packages/backend/src/graphql/mutations/verify-connection.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
|
import Connection from '../../models/connection';
|
||||||
|
import connectionType from '../types/connection';
|
||||||
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
const verifyConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
|
let connection = await Connection.query().findOne({
|
||||||
|
user_id: req.currentUser.id,
|
||||||
|
id: params.id
|
||||||
|
})
|
||||||
|
|
||||||
|
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||||
|
|
||||||
|
const appInstance = new appClass(connection.data)
|
||||||
|
const verifiedCredentials = await appInstance.verifyCredentials();
|
||||||
|
|
||||||
|
connection = await connection.$query().patchAndFetch({
|
||||||
|
data: verifiedCredentials
|
||||||
|
})
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
const verifyConnection = {
|
||||||
|
type: connectionType,
|
||||||
|
args: {
|
||||||
|
id: { type: GraphQLNonNull(GraphQLString) }
|
||||||
|
},
|
||||||
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => verifyConnectionResolver(params, req)
|
||||||
|
};
|
||||||
|
|
||||||
|
export default verifyConnection;
|
@@ -2,6 +2,8 @@ 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 resetConnection from './mutations/reset-connection';
|
||||||
|
import verifyConnection from './mutations/verify-connection';
|
||||||
import deleteConnection from './mutations/delete-connection';
|
import deleteConnection from './mutations/delete-connection';
|
||||||
|
|
||||||
const rootMutation = new GraphQLObjectType({
|
const rootMutation = new GraphQLObjectType({
|
||||||
@@ -10,6 +12,8 @@ const rootMutation = new GraphQLObjectType({
|
|||||||
createConnection,
|
createConnection,
|
||||||
createAuthLink,
|
createAuthLink,
|
||||||
updateConnection,
|
updateConnection,
|
||||||
|
resetConnection,
|
||||||
|
verifyConnection,
|
||||||
deleteConnection
|
deleteConnection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
import { CREATE_CONNECTION } from './create-connection';
|
import { CREATE_CONNECTION } from './create-connection';
|
||||||
import { UPDATE_CONNECTION } from './update-connection';
|
import { UPDATE_CONNECTION } from './update-connection';
|
||||||
|
import { VERIFY_CONNECTION } from './verify-connection';
|
||||||
|
import { RESET_CONNECTION } from './reset-connection';
|
||||||
import { DELETE_CONNECTION } from './delete-connection';
|
import { DELETE_CONNECTION } from './delete-connection';
|
||||||
import { CREATE_AUTH_LINK } from './create-auth-link';
|
import { CREATE_AUTH_LINK } from './create-auth-link';
|
||||||
|
|
||||||
@@ -10,6 +12,8 @@ type Mutations = {
|
|||||||
const mutations: Mutations = {
|
const mutations: Mutations = {
|
||||||
createConnection: CREATE_CONNECTION,
|
createConnection: CREATE_CONNECTION,
|
||||||
updateConnection: UPDATE_CONNECTION,
|
updateConnection: UPDATE_CONNECTION,
|
||||||
|
verifyConnection: VERIFY_CONNECTION,
|
||||||
|
resetConnection: RESET_CONNECTION,
|
||||||
deleteConnection: DELETE_CONNECTION,
|
deleteConnection: DELETE_CONNECTION,
|
||||||
createAuthLink: CREATE_AUTH_LINK,
|
createAuthLink: CREATE_AUTH_LINK,
|
||||||
};
|
};
|
||||||
|
9
packages/web/src/graphql/mutations/reset-connection.ts
Normal file
9
packages/web/src/graphql/mutations/reset-connection.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const RESET_CONNECTION = gql`
|
||||||
|
mutation ResetConnection($id: String!) {
|
||||||
|
resetConnection(id: $id) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
13
packages/web/src/graphql/mutations/verify-connection.ts
Normal file
13
packages/web/src/graphql/mutations/verify-connection.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const VERIFY_CONNECTION = gql`
|
||||||
|
mutation VerifyConnection($id: String!) {
|
||||||
|
verifyConnection(id: $id) {
|
||||||
|
id
|
||||||
|
verified
|
||||||
|
data {
|
||||||
|
screenName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
Reference in New Issue
Block a user