feat: Create credentials model and graphQL mutation
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Twitch",
|
"name": "Twitch",
|
||||||
|
"key": "twitch",
|
||||||
"iconUrl": "https://automatisch.io/apps/twitch.png",
|
"iconUrl": "https://automatisch.io/apps/twitch.png",
|
||||||
"docUrl": "https://automatisch.io/docs/twitch",
|
"docUrl": "https://automatisch.io/docs/twitch",
|
||||||
"primaryColor": "6441a5",
|
"primaryColor": "6441a5",
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Twitter",
|
"name": "Twitter",
|
||||||
|
"key": "twitter",
|
||||||
"iconUrl": "https://automatisch.io/apps/twitter.png",
|
"iconUrl": "https://automatisch.io/apps/twitter.png",
|
||||||
"docUrl": "https://automatisch.io/docs/twitter",
|
"docUrl": "https://automatisch.io/docs/twitter",
|
||||||
"primaryColor": "2DAAE1",
|
"primaryColor": "2DAAE1",
|
||||||
@@ -15,6 +16,17 @@
|
|||||||
"docUrl": "https://automatisch.io/docs/twitter#oauth-redirect-url",
|
"docUrl": "https://automatisch.io/docs/twitter#oauth-redirect-url",
|
||||||
"clickToCopy": true
|
"clickToCopy": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"key": "displayName",
|
||||||
|
"label": "Name",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"description": "It's the value you can remember later on while changing connection settings.",
|
||||||
|
"docUrl": "https://automatisch.io/docs/twitter#display-name",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"key": "consumerKey",
|
"key": "consumerKey",
|
||||||
"label": "Consumer Key",
|
"label": "Consumer Key",
|
||||||
@@ -37,5 +49,36 @@
|
|||||||
"docUrl": "https://automatisch.io/docs/twitter#consumer-secret",
|
"docUrl": "https://automatisch.io/docs/twitter#consumer-secret",
|
||||||
"clickToCopy": false
|
"clickToCopy": false
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"authenticationSteps": [
|
||||||
|
{
|
||||||
|
"step": 1,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "createCredential",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "displayName",
|
||||||
|
"value": "{fields.displayName}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "key",
|
||||||
|
"value": "{key}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"value": "data",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "consumerKey",
|
||||||
|
"value": "{fields.consumerKey}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "consumerSecret",
|
||||||
|
"value": "{fields.consumerSecret}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
return knex.schema.createTable('credentials', (table) => {
|
||||||
|
table.increments('id');
|
||||||
|
table.string('key').notNullable();
|
||||||
|
table.string('display_name').notNullable();
|
||||||
|
table.text('data').notNullable();
|
||||||
|
table.integer('user_id').references('id').inTable('users');
|
||||||
|
table.boolean('verified').defaultTo(false);
|
||||||
|
|
||||||
|
table.timestamps(true, true);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
return knex.schema.dropTable('credentials');
|
||||||
|
}
|
@@ -1,8 +1,10 @@
|
|||||||
import { GraphQLSchema } from 'graphql';
|
import { GraphQLSchema } from 'graphql';
|
||||||
import rootQuery from './root-query';
|
import rootQuery from './root-query';
|
||||||
|
import rootMutation from './root-mutation';
|
||||||
|
|
||||||
const graphQLSchema = new GraphQLSchema({
|
const graphQLSchema = new GraphQLSchema({
|
||||||
query: rootQuery,
|
query: rootQuery,
|
||||||
|
mutation: rootMutation
|
||||||
});
|
});
|
||||||
|
|
||||||
export default graphQLSchema;
|
export default graphQLSchema;
|
||||||
|
37
packages/backend/src/graphql/mutations/create-credential.ts
Normal file
37
packages/backend/src/graphql/mutations/create-credential.ts
Normal 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;
|
11
packages/backend/src/graphql/root-mutation.ts
Normal file
11
packages/backend/src/graphql/root-mutation.ts
Normal 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;
|
13
packages/backend/src/graphql/types/credential.ts
Normal file
13
packages/backend/src/graphql/types/credential.ts
Normal 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;
|
@@ -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;
|
11
packages/backend/src/graphql/types/twitter-credential.ts
Normal file
11
packages/backend/src/graphql/types/twitter-credential.ts
Normal 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;
|
27
packages/backend/src/models/credential.ts
Normal file
27
packages/backend/src/models/credential.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import Base from './base'
|
||||||
|
|
||||||
|
class Credential extends Base {
|
||||||
|
id!: number
|
||||||
|
displayName!: string
|
||||||
|
key!: string
|
||||||
|
data!: string
|
||||||
|
userId!: number
|
||||||
|
|
||||||
|
static tableName = 'credentials';
|
||||||
|
|
||||||
|
static jsonSchema = {
|
||||||
|
type: 'object',
|
||||||
|
required: ['displayName', 'key', 'data', 'userId'],
|
||||||
|
|
||||||
|
properties: {
|
||||||
|
id: { type: 'integer' },
|
||||||
|
displayName: { type: 'string', minLength: 1, maxLength: 255 },
|
||||||
|
key: { type: 'string', minLength: 1, maxLength: 255 },
|
||||||
|
data: { type: 'object' },
|
||||||
|
userId: { type: 'integer' },
|
||||||
|
verified: { type: 'boolean' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Credential;
|
Reference in New Issue
Block a user