Skip to content

Commit bcefa6f

Browse files
author
sunlei
committed
fauna datasoruce
1 parent 4681390 commit bcefa6f

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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";
5+
6+
export const dataSourceConfig = {
7+
type: "dataSource",
8+
params: [
9+
{
10+
type: "select",
11+
label: "Region",
12+
key: "region",
13+
options: [
14+
{ label: "United States (US)", value: "us" },
15+
{ label: "Europe (EU)", value: "eu" },
16+
{ label: "Classic", value: "classic" },
17+
{ label: "Preview", value: "preview" },
18+
],
19+
defaultValue: "us",
20+
tooltip:
21+
"[Document](https://docs.fauna.com/fauna/current/api/graphql/endpoints) on that you can get more information for GraphQL endpoints of Fauna.",
22+
},
23+
{
24+
type: "password",
25+
label: "Account Key",
26+
key: "apiKey",
27+
rules: [{ required: true }],
28+
},
29+
],
30+
} as const;
31+
32+
const endpoints = {
33+
us: "https://graphql.us.fauna.com/graphql",
34+
es: "https://graphql.eu.fauna.com/graphql",
35+
classic: "https://graphql.fauna.com/graphql",
36+
preview: "https://graphql.fauna-preview.com/graphql",
37+
};
38+
39+
const faunaPlugin: DataSourcePlugin<
40+
ConfigToType<typeof graphQLQueryConfig>,
41+
ConfigToType<typeof dataSourceConfig>
42+
> = {
43+
id: "fauna",
44+
name: "Fauna",
45+
category: "api",
46+
icon: "fauna.svg",
47+
dataSourceConfig,
48+
queryConfig: graphQLQueryConfig,
49+
run: function (actionData, dataSourceConfig, context: PluginContext): Promise<any> {
50+
const { region, apiKey } = dataSourceConfig;
51+
const { query, variables: variableKvs, headers: queryHeaders } = actionData;
52+
const headers = {
53+
...kvToRecord(queryHeaders),
54+
Authorization: `Bearer ${apiKey}`,
55+
};
56+
const variables = kvToRecord(variableKvs);
57+
const endpoint = endpoints[region as keyof typeof endpoints];
58+
return runGraphQL(endpoint, query, variables, headers);
59+
},
60+
};
61+
62+
export default faunaPlugin;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import notionPlugin from "./notion";
2828
import datadogPlugin from "./datadog";
2929
import twilioPlugin from "./twilio";
3030
import gitlabPlugin from "./gitlab";
31+
import faunaPlugin from "./fauna";
3132

3233
let plugins: (DataSourcePlugin | DataSourcePluginFactory)[] = [
3334
s3Plugin,
@@ -60,6 +61,7 @@ let plugins: (DataSourcePlugin | DataSourcePluginFactory)[] = [
6061
datadogPlugin,
6162
twilioPlugin,
6263
gitlabPlugin,
64+
faunaPlugin,
6365
];
6466

6567
try {

0 commit comments

Comments
 (0)