feat: Implement createAuthLink mutation

This commit is contained in:
Faruk AYDIN
2021-10-14 15:17:58 +02:00
committed by Ali BARIN
parent 7f17420ae0
commit bdd0843d94
11 changed files with 130 additions and 3 deletions

View File

@@ -0,0 +1,35 @@
import { GraphQLNonNull, GraphQLInt } from 'graphql';
import Credential from '../../models/credential';
import authLinkType from '../types/auth-link';
import User from '../../models/user';
type Params = {
credentialId: number,
}
const createAuthLinkResolver = async (params: Params) => {
const user = await User.query().findOne({
email: 'user@automatisch.com'
})
const credential = await Credential.query().findOne({
user_id: user.id,
id: params.credentialId
})
const appClass = (await import(`../../apps/${credential.key}`)).default;
const appInstance = new appClass(credential.data)
const authLink = await appInstance.createAuthLink();
return authLink;
}
const createAuthLink = {
type: authLinkType,
args: {
credentialId: { type: GraphQLNonNull(GraphQLInt) },
},
resolve: (_: any, params: Params) => createAuthLinkResolver(params)
};
export default createAuthLink;

View File

@@ -1,10 +1,12 @@
import { GraphQLObjectType } from 'graphql';
import createCredential from './mutations/create-credential';
import createAuthLink from './mutations/create-auth-link';
const rootMutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
createCredential: createCredential
createCredential: createCredential,
createAuthLink: createAuthLink
}
});

View File

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

View File

@@ -4,6 +4,7 @@ import twitterCredentialType from './twitter-credential';
const credentialType = new GraphQLObjectType({
name: 'credential',
fields: {
id: { type: GraphQLString },
key: { type: GraphQLString },
displayName: { type: GraphQLString },
data: { type: twitterCredentialType },