chore: Rename credentials as connections
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||
import Credential from '../../models/credential';
|
||||
import Connection from '../../models/connection';
|
||||
import authLinkType from '../types/auth-link';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
@@ -7,19 +7,19 @@ type Params = {
|
||||
id: number,
|
||||
}
|
||||
const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const credential = await Credential.query().findOne({
|
||||
const connection = await Connection.query().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.id
|
||||
})
|
||||
|
||||
const appClass = (await import(`../../apps/${credential.key}`)).default;
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
|
||||
const appInstance = new appClass(credential.data)
|
||||
const appInstance = new appClass(connection.data)
|
||||
const authLink = await appInstance.createAuthLink();
|
||||
|
||||
await credential.$query().patch({
|
||||
await connection.$query().patch({
|
||||
data: {
|
||||
...credential.data,
|
||||
...connection.data,
|
||||
url: authLink.url,
|
||||
accessToken: authLink.oauth_token,
|
||||
accessSecret: authLink.oauth_token_secret,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Credential from '../../models/credential';
|
||||
import credentialType from '../types/credential';
|
||||
import Connection from '../../models/connection';
|
||||
import connectionType from '../types/connection';
|
||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
@@ -8,23 +8,23 @@ type Params = {
|
||||
key: string,
|
||||
data: object
|
||||
}
|
||||
const createCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const credential = await Credential.query().insert({
|
||||
const createConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const connection = await Connection.query().insert({
|
||||
key: params.key,
|
||||
data: params.data,
|
||||
userId: req.currentUser.id
|
||||
});
|
||||
|
||||
return credential;
|
||||
return connection;
|
||||
}
|
||||
|
||||
const createCredential = {
|
||||
type: credentialType,
|
||||
const createConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
key: { type: GraphQLNonNull(GraphQLString) },
|
||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createCredentialResolver(params, req)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createConnectionResolver(params, req)
|
||||
};
|
||||
|
||||
export default createCredential;
|
||||
export default createConnection;
|
@@ -1,6 +1,6 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Credential from '../../models/credential';
|
||||
import credentialType from '../types/credential';
|
||||
import Connection from '../../models/connection';
|
||||
import connectionType from '../types/connection';
|
||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
@@ -8,38 +8,38 @@ type Params = {
|
||||
id: string,
|
||||
data: object
|
||||
}
|
||||
const updateCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
let credential = await Credential.query().findOne({
|
||||
const updateConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
let connection = await Connection.query().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.id
|
||||
})
|
||||
|
||||
credential = await credential.$query().patchAndFetch({
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: {
|
||||
...credential.data,
|
||||
...connection.data,
|
||||
...params.data
|
||||
}
|
||||
})
|
||||
|
||||
const appClass = (await import(`../../apps/${credential.key}`)).default;
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
|
||||
const appInstance = new appClass(credential.data)
|
||||
const appInstance = new appClass(connection.data)
|
||||
const verifiedCredentials = await appInstance.verifyCredentials();
|
||||
|
||||
credential = await credential.$query().patchAndFetch({
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: verifiedCredentials
|
||||
})
|
||||
|
||||
return credential;
|
||||
return connection;
|
||||
}
|
||||
|
||||
const updateCredential = {
|
||||
type: credentialType,
|
||||
const updateConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLString) },
|
||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateCredentialResolver(params, req)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateConnectionResolver(params, req)
|
||||
};
|
||||
|
||||
export default updateCredential;
|
||||
export default updateConnection;
|
@@ -1,14 +1,14 @@
|
||||
import { GraphQLObjectType } from 'graphql';
|
||||
import createCredential from './mutations/create-credential';
|
||||
import createConnection from './mutations/create-connection';
|
||||
import createAuthLink from './mutations/create-auth-link';
|
||||
import updateCredential from './mutations/update-credential';
|
||||
import updateConnection from './mutations/update-connection';
|
||||
|
||||
const rootMutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: {
|
||||
createCredential: createCredential,
|
||||
createConnection: createConnection,
|
||||
createAuthLink: createAuthLink,
|
||||
updateCredential: updateCredential
|
||||
updateConnection: updateConnection
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql';
|
||||
import twitterCredentialType from './twitter-credential';
|
||||
|
||||
const credentialType = new GraphQLObjectType({
|
||||
name: 'credential',
|
||||
const connectionType = new GraphQLObjectType({
|
||||
name: 'connection',
|
||||
fields: {
|
||||
id: { type: GraphQLString },
|
||||
key: { type: GraphQLString },
|
||||
@@ -11,4 +11,4 @@ const credentialType = new GraphQLObjectType({
|
||||
}
|
||||
})
|
||||
|
||||
export default credentialType;
|
||||
export default connectionType;
|
Reference in New Issue
Block a user