feat: introduce reconnect feature for connections
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import TwitterApi from 'twitter-api-v2';
|
||||
import App from '../../models/app';
|
||||
import Field from '../../types/field';
|
||||
import appData from './info';
|
||||
|
||||
export default class Twitter {
|
||||
client: any
|
||||
@@ -17,7 +16,7 @@ export default class Twitter {
|
||||
});
|
||||
|
||||
this.connectionData = connectionData;
|
||||
this.appData = appData;
|
||||
this.appData = App.findOneByKey('twitter');
|
||||
}
|
||||
|
||||
async createAuthLink() {
|
||||
|
@@ -14,7 +14,7 @@ const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUse
|
||||
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
|
||||
const appInstance = new appClass(connection.data)
|
||||
const appInstance = new appClass({ consumerKey: connection.data.consumerKey, consumerSecret: connection.data.consumerSecret });
|
||||
const authLink = await appInstance.createAuthLink();
|
||||
|
||||
await connection.$query().patch({
|
||||
|
@@ -21,14 +21,17 @@ const updateConnectionResolver = async (params: Params, req: RequestWithCurrentU
|
||||
}
|
||||
})
|
||||
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
// 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();
|
||||
const appInstance = new appClass(connection.data)
|
||||
const verifiedCredentials = await appInstance.verifyCredentials();
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: verifiedCredentials
|
||||
})
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: verifiedCredentials
|
||||
})
|
||||
} catch {}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
@@ -4,6 +4,12 @@ import graphQLSchema from '../graphql/graphql-schema'
|
||||
const graphQLInstance = graphqlHTTP({
|
||||
schema: graphQLSchema,
|
||||
graphiql: true,
|
||||
customFormatErrorFn: (error) => ({
|
||||
message: error.message,
|
||||
locations: error.locations,
|
||||
stack: error.stack ? error.stack.split('\n') : [],
|
||||
path: error.path,
|
||||
})
|
||||
})
|
||||
|
||||
export default graphQLInstance;
|
||||
|
Reference in New Issue
Block a user