feat: Implement getAppConnections graphQL query
This commit is contained in:
25
packages/backend/src/graphql/queries/get-app-connections.ts
Normal file
25
packages/backend/src/graphql/queries/get-app-connections.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { GraphQLList, GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Connection from '../../models/connection';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import connectionType from '../types/connection';
|
||||
|
||||
type Params = {
|
||||
key: string
|
||||
}
|
||||
|
||||
const getAppConnectionsResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const connections = await Connection.query()
|
||||
.where({ user_id: req.currentUser.id, verified: true, key: params.key })
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
const getAppConnections = {
|
||||
type: GraphQLList(connectionType),
|
||||
args: {
|
||||
key: { type: GraphQLNonNull(GraphQLString) }
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getAppConnectionsResolver(params, req)
|
||||
}
|
||||
|
||||
export default getAppConnections;
|
@@ -2,13 +2,15 @@ import { GraphQLObjectType } from 'graphql';
|
||||
import getApps from './queries/get-apps';
|
||||
import getApp from './queries/get-app';
|
||||
import getConnectedApps from './queries/get-connected-apps';
|
||||
import getAppConnections from './queries/get-app-connections';
|
||||
|
||||
const rootQuery = new GraphQLObjectType({
|
||||
name: 'Query',
|
||||
fields: {
|
||||
getApps,
|
||||
getApp,
|
||||
getConnectedApps
|
||||
getConnectedApps,
|
||||
getAppConnections
|
||||
}
|
||||
});
|
||||
|
||||
|
10
packages/backend/src/graphql/types/connection-data.ts
Normal file
10
packages/backend/src/graphql/types/connection-data.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { GraphQLString, GraphQLObjectType } from 'graphql';
|
||||
|
||||
const connectionDataType = new GraphQLObjectType({
|
||||
name: 'connectionData',
|
||||
fields: {
|
||||
screenName: { type: GraphQLString },
|
||||
}
|
||||
})
|
||||
|
||||
export default connectionDataType;
|
@@ -1,12 +1,12 @@
|
||||
import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql';
|
||||
import twitterCredentialType from './twitter-credential';
|
||||
import connectionDataType from './connection-data';
|
||||
|
||||
const connectionType = new GraphQLObjectType({
|
||||
name: 'connection',
|
||||
fields: {
|
||||
id: { type: GraphQLString },
|
||||
key: { type: GraphQLString },
|
||||
data: { type: twitterCredentialType },
|
||||
data: { type: connectionDataType },
|
||||
verified: { type: GraphQLBoolean },
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user