feat: Implement getAppConnections graphQL query

This commit is contained in:
Faruk AYDIN
2021-10-18 17:05:36 +02:00
committed by Ali BARIN
parent d13470d587
commit 258b523042
4 changed files with 40 additions and 3 deletions

View 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;

View File

@@ -2,13 +2,15 @@ import { GraphQLObjectType } from 'graphql';
import getApps from './queries/get-apps'; import getApps from './queries/get-apps';
import getApp from './queries/get-app'; import getApp from './queries/get-app';
import getConnectedApps from './queries/get-connected-apps'; import getConnectedApps from './queries/get-connected-apps';
import getAppConnections from './queries/get-app-connections';
const rootQuery = new GraphQLObjectType({ const rootQuery = new GraphQLObjectType({
name: 'Query', name: 'Query',
fields: { fields: {
getApps, getApps,
getApp, getApp,
getConnectedApps getConnectedApps,
getAppConnections
} }
}); });

View File

@@ -0,0 +1,10 @@
import { GraphQLString, GraphQLObjectType } from 'graphql';
const connectionDataType = new GraphQLObjectType({
name: 'connectionData',
fields: {
screenName: { type: GraphQLString },
}
})
export default connectionDataType;

View File

@@ -1,12 +1,12 @@
import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql'; import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql';
import twitterCredentialType from './twitter-credential'; import connectionDataType from './connection-data';
const connectionType = new GraphQLObjectType({ const connectionType = new GraphQLObjectType({
name: 'connection', name: 'connection',
fields: { fields: {
id: { type: GraphQLString }, id: { type: GraphQLString },
key: { type: GraphQLString }, key: { type: GraphQLString },
data: { type: twitterCredentialType }, data: { type: connectionDataType },
verified: { type: GraphQLBoolean }, verified: { type: GraphQLBoolean },
} }
}) })