feat: Create credentials model and graphQL mutation

This commit is contained in:
Faruk AYDIN
2021-10-12 17:51:43 +02:00
committed by Ali BARIN
parent e569b188a9
commit 981ea6d163
10 changed files with 174 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
import { GraphQLSchema } from 'graphql';
import rootQuery from './root-query';
import rootMutation from './root-mutation';
const graphQLSchema = new GraphQLSchema({
query: rootQuery,
mutation: rootMutation
});
export default graphQLSchema;

View File

@@ -0,0 +1,37 @@
import { GraphQLString, GraphQLNonNull, GraphQLObjectType, GraphQLCompositeType } from 'graphql';
import Credential from '../../models/credential';
import credentialType from '../types/credential';
import twitterCredentialInputType from '../types/twitter-credential-input';
import User from '../../models/user';
type Params = {
key: string,
displayName: string,
data: object
}
const createCredentialResolver = async (params: Params) => {
const user = await User.query().findOne({
email: 'user@automatisch.com'
})
const credential = await Credential.query().insert({
displayName: params.displayName,
key: params.key,
data: params.data,
userId: user.id
});
return credential;
}
const createCredential = {
type: credentialType,
args: {
key: { type: GraphQLNonNull(GraphQLString) },
displayName: { type: GraphQLNonNull(GraphQLString) },
data: { type: GraphQLNonNull(twitterCredentialInputType) }
},
resolve: (_: any, params: Params) => createCredentialResolver(params)
};
export default createCredential;

View File

@@ -0,0 +1,11 @@
import { GraphQLObjectType } from 'graphql';
import createCredential from './mutations/create-credential';
const rootMutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
createCredential: createCredential
}
});
export default rootMutation;

View File

@@ -0,0 +1,13 @@
import { GraphQLObjectType, GraphQLString } from 'graphql';
import twitterCredentialType from './twitter-credential';
const credentialType = new GraphQLObjectType({
name: 'credential',
fields: {
key: { type: GraphQLString },
displayName: { type: GraphQLString },
data: { type: twitterCredentialType },
}
})
export default credentialType;

View File

@@ -0,0 +1,11 @@
import { GraphQLString, GraphQLInputObjectType } from 'graphql';
const twitterCredentialInputType = new GraphQLInputObjectType({
name: 'twitterCredentialInput',
fields: {
consumerKey: { type: GraphQLString },
consumerSecret: { type: GraphQLString },
}
})
export default twitterCredentialInputType;

View File

@@ -0,0 +1,11 @@
import { GraphQLString, GraphQLObjectType } from 'graphql';
const twitterCredentialInputType = new GraphQLObjectType({
name: 'twitterCredential',
fields: {
consumerKey: { type: GraphQLString },
consumerSecret: { type: GraphQLString },
}
})
export default twitterCredentialInputType;