feat: Implement getAll and getAllByName graphQL queries

This commit is contained in:
Faruk AYDIN
2021-10-08 21:24:27 +02:00
committed by Ali BARIN
parent a39ae93ca4
commit 0e684570f8
7 changed files with 121 additions and 4 deletions

View File

@@ -0,0 +1,40 @@
{
"name": "Twitch",
"iconUrl": "https://automatisch.io/apps/twitch.png",
"docUrl": "https://automatisch.io/docs/twitch",
"fields": [
{
"key": "oAuthRedirectUrl",
"label": "OAuth Redirect URL",
"type": "string",
"required": true,
"readOnly": true,
"placeholder": "http://localhost:3000/sample",
"description": "When asked to input an OAuth callback or redirect URL in Twitch OAuth, enter the URL above.",
"docUrl": "https://automatisch.io/docs/twitch#oauth-redirect-url",
"clickToCopy": true
},
{
"key": "consumerKey",
"label": "Consumer Key",
"type": "string",
"required": true,
"readOnly": false,
"placeholder": null,
"description": null,
"docUrl": "https://automatisch.io/docs/twitch#consumer-key",
"clickToCopy": false
},
{
"key": "consumerSecret",
"label": "Consumer Secret",
"type": "string",
"required": true,
"readOnly": false,
"placeholder": null,
"description": null,
"docUrl": "https://automatisch.io/docs/twitch#consumer-secret",
"clickToCopy": false
}
]
}

View File

@@ -0,0 +1,40 @@
{
"name": "Twitter",
"iconUrl": "https://automatisch.io/apps/twitter.png",
"docUrl": "https://automatisch.io/docs/twitter",
"fields": [
{
"key": "oAuthRedirectUrl",
"label": "OAuth Redirect URL",
"type": "string",
"required": true,
"readOnly": true,
"placeholder": "http://localhost:3000/sample",
"description": "When asked to input an OAuth callback or redirect URL in Twitter OAuth, enter the URL above.",
"docUrl": "https://automatisch.io/docs/twitter#oauth-redirect-url",
"clickToCopy": true
},
{
"key": "consumerKey",
"label": "Consumer Key",
"type": "string",
"required": true,
"readOnly": false,
"placeholder": null,
"description": null,
"docUrl": "https://automatisch.io/docs/twitter#consumer-key",
"clickToCopy": false
},
{
"key": "consumerSecret",
"label": "Consumer Secret",
"type": "string",
"required": true,
"readOnly": false,
"placeholder": null,
"description": null,
"docUrl": "https://automatisch.io/docs/twitter#consumer-secret",
"clickToCopy": false
}
]
}

View File

@@ -2,7 +2,8 @@ import { buildSchema } from 'graphql';
const graphQLSchema = buildSchema(` const graphQLSchema = buildSchema(`
type Query { type Query {
hello: String getApps: [String!]
getAppsByName(name: String!): [String!]
} }
`); `);

View File

@@ -0,0 +1,11 @@
import App from '../../models/app';
type Params = {
name: string
}
const getAppsByName = (params: Params) => {
return App.findAllByName(params.name)
}
export default getAppsByName;

View File

@@ -0,0 +1,7 @@
import App from '../../models/app';
const getApps = () => {
return App.findAll()
}
export default getApps;

View File

@@ -1,7 +1,9 @@
import getApps from './queries/get-apps';
import getAppsByName from './queries/get-apps-by-name';
const rootResolver = { const rootResolver = {
hello: () => { getApps: getApps,
return 'Hello world!'; getAppsByName: getAppsByName
},
}; };
export default rootResolver; export default rootResolver;

View File

@@ -0,0 +1,16 @@
import fs from 'fs';
class App {
static folderPath = __dirname + '/../apps'
static list = fs.readdirSync(this.folderPath);
static findAll(): string[] {
return this.list;
}
static findAllByName(name: string): string[] {
return this.list.filter((app) => app.includes(name.toLowerCase()));
}
}
export default App;