Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4571f6f

Browse files
Esievesunlei
authored andcommitted
feat: Shopify
1 parent 0e96b42 commit 4571f6f

File tree

2 files changed

+23
-49990
lines changed

2 files changed

+23
-49990
lines changed

server/node-service/src/plugins/shopify/index.ts

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,34 @@
1-
import { readYaml } from "../../common/util";
2-
import _ from "lodash";
3-
import path from "path";
4-
import { OpenAPIV3, OpenAPI } from "openapi-types";
5-
import { ConfigToType, DataSourcePlugin } from "openblocks-sdk/dataSource";
6-
import { runOpenApi } from "../openApi";
7-
import { parseOpenApi, ParseOpenApiOptions } from "../openApi/parse";
1+
import { kvToRecord } from "../../common/util";
2+
import { ConfigToType, DataSourcePlugin, PluginContext } from "openblocks-sdk/dataSource";
3+
import { graphQLQueryConfig } from "../graphql/queryConfig";
4+
import { runGraphQL } from "../graphql/run";
85

9-
const spec = readYaml(path.join(__dirname, "./shopify.spec.yaml"));
10-
11-
const dataSourceConfig = {
6+
export const dataSourceConfig = {
127
type: "dataSource",
13-
params: [],
8+
params: [
9+
{
10+
type: "textInput",
11+
label: "Endpoint",
12+
key: "endpoint",
13+
rules: [{ required: true }],
14+
},
15+
],
1416
} as const;
1517

16-
const parseOptions: ParseOpenApiOptions = {
17-
actionLabel: (method: string, path: string, operation: OpenAPI.Operation) => {
18-
return _.upperFirst(operation.operationId || "");
19-
},
20-
};
21-
22-
type DataSourceConfigType = ConfigToType<typeof dataSourceConfig>;
23-
24-
const shopifyPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
18+
const shopifyPlugin: DataSourcePlugin<
19+
ConfigToType<typeof graphQLQueryConfig>,
20+
ConfigToType<typeof dataSourceConfig>
21+
> = {
2522
id: "shopify",
2623
name: "Shopify",
27-
icon: "shopify.svg",
2824
category: "api",
25+
icon: "shopify.svg",
2926
dataSourceConfig,
30-
queryConfig: async () => {
31-
const { actions, categories } = await parseOpenApi(spec, parseOptions);
32-
return {
33-
type: "query",
34-
label: "Action",
35-
categories: {
36-
label: "Category",
37-
items: categories,
38-
},
39-
actions,
40-
};
41-
},
42-
run: function (actionData, dataSourceConfig): Promise<any> {
43-
const runApiDsConfig = {
44-
url: "",
45-
serverURL: "",
46-
dynamicParamsConfig: dataSourceConfig,
47-
};
48-
return runOpenApi(actionData, runApiDsConfig, spec as OpenAPIV3.Document);
27+
queryConfig: graphQLQueryConfig,
28+
run: function (actionData, dataSourceConfig, context: PluginContext): Promise<any> {
29+
const { query, variables: variableKvs, headers: queryHeaders } = actionData;
30+
const variables = kvToRecord(variableKvs);
31+
return runGraphQL(dataSourceConfig.endpoint, query, variables, {});
4932
},
5033
};
5134

0 commit comments

Comments
 (0)