mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-23 16:00:38 +00:00
fix: graphql api not db (#2017)
* fix: graphql api not db * fix: use api instead of db in test connection gql
This commit is contained in:
@@ -8,7 +8,7 @@ use serde::Deserialize;
|
||||
use crate::{transform_json_value, AuthedClient, JobCompleted};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct GraphqlDatabase {
|
||||
struct GraphqlApi {
|
||||
bearer_token: Option<String>,
|
||||
base_url: String,
|
||||
}
|
||||
@@ -37,10 +37,9 @@ pub async fn do_graphql(
|
||||
|
||||
let graphql_args: serde_json::Value = serde_json::from_value(args.unwrap_or_else(|| json!({})))
|
||||
.map_err(|e| Error::ExecutionErr(e.to_string()))?;
|
||||
let database = serde_json::from_value::<GraphqlDatabase>(
|
||||
graphql_args.get("database").unwrap_or(&json!({})).clone(),
|
||||
)
|
||||
.map_err(|e: serde_json::Error| Error::ExecutionErr(e.to_string()))?;
|
||||
let api =
|
||||
serde_json::from_value::<GraphqlApi>(graphql_args.get("api").unwrap_or(&json!({})).clone())
|
||||
.map_err(|e: serde_json::Error| Error::ExecutionErr(e.to_string()))?;
|
||||
|
||||
let args = &job
|
||||
.args
|
||||
@@ -50,12 +49,12 @@ pub async fn do_graphql(
|
||||
.map(|x| x.to_owned())
|
||||
.unwrap_or_else(|| json!({}).as_object().unwrap().to_owned());
|
||||
|
||||
let mut request = HTTP_CLIENT.post(database.base_url).json(&json!({
|
||||
let mut request = HTTP_CLIENT.post(api.base_url).json(&json!({
|
||||
"query": query,
|
||||
"variables": args
|
||||
}));
|
||||
|
||||
if let Some(token) = &database.bearer_token {
|
||||
if let Some(token) = &api.bearer_token {
|
||||
request = request.bearer_auth(token.as_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -174,13 +174,13 @@ export async function main(args: any) {
|
||||
}
|
||||
},
|
||||
timeoutCode: async () => {
|
||||
console.error('Could not query DB schema within 5s')
|
||||
console.error('Could not query schema within 5s')
|
||||
try {
|
||||
await JobService.cancelQueuedJob({
|
||||
workspace: $workspaceStore!,
|
||||
id: job,
|
||||
requestBody: {
|
||||
reason: 'Could not query DB schema within 5s'
|
||||
reason: 'Could not query schema within 5s'
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
@@ -226,10 +226,10 @@ export async function main(args: any) {
|
||||
btnClasses="mt-1"
|
||||
on:click={drawer.openDrawer}
|
||||
>
|
||||
Explore DB schema
|
||||
Explore schema
|
||||
</Button>
|
||||
<Drawer bind:this={drawer} size="800px">
|
||||
<DrawerContent title="DB Schema Explorer" on:close={drawer.closeDrawer}>
|
||||
<DrawerContent title="Schema Explorer" on:close={drawer.closeDrawer}>
|
||||
{#if $dbSchema.lang === 'postgresql'}
|
||||
<ToggleButtonGroup class="mb-4" bind:selected={$dbSchema.publicOnly}>
|
||||
<ToggleButton value={true} label="Public" />
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
[key: string]: {
|
||||
code: string
|
||||
lang: string
|
||||
argName: string
|
||||
}
|
||||
} = {
|
||||
postgresql: {
|
||||
@@ -30,7 +31,8 @@ export async function main(database: any) {
|
||||
const client = new Client(u.toString())
|
||||
await client.connect()
|
||||
}`,
|
||||
lang: 'deno'
|
||||
lang: 'deno',
|
||||
argName: 'database'
|
||||
},
|
||||
mysql: {
|
||||
code: `import { Client } from "https://deno.land/x/mysql@v2.11.0/mod.ts";
|
||||
@@ -44,19 +46,23 @@ export async function main(database: any) {
|
||||
});
|
||||
await conn.query("SELECT 1");
|
||||
}`,
|
||||
lang: 'deno'
|
||||
lang: 'deno',
|
||||
argName: 'database'
|
||||
},
|
||||
bigquery: {
|
||||
code: `select 1`,
|
||||
lang: 'bigquery'
|
||||
lang: 'bigquery',
|
||||
argName: 'database'
|
||||
},
|
||||
snowflake: {
|
||||
code: `select 1`,
|
||||
lang: 'snowflake'
|
||||
lang: 'snowflake',
|
||||
argName: 'database'
|
||||
},
|
||||
graphql: {
|
||||
code: '{ __typename }',
|
||||
lang: 'graphql'
|
||||
lang: 'graphql',
|
||||
argName: 'api'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +79,7 @@ export async function main(database: any) {
|
||||
language: resourceScript.lang as Preview.language,
|
||||
content: resourceScript.code,
|
||||
args: {
|
||||
database: args
|
||||
[resourceScript.argName]: args
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -66,10 +66,7 @@ export async function inferArgs(
|
||||
]
|
||||
} else if (language == 'graphql') {
|
||||
inferedSchema = JSON.parse(parse_graphql(code))
|
||||
inferedSchema.args = [
|
||||
{ name: 'database', typ: { resource: 'graphql' } },
|
||||
...inferedSchema.args
|
||||
]
|
||||
inferedSchema.args = [{ name: 'api', typ: { resource: 'graphql' } }, ...inferedSchema.args]
|
||||
} else if (language == 'go') {
|
||||
inferedSchema = JSON.parse(parse_go(code))
|
||||
} else if (language == 'bash') {
|
||||
|
||||
Reference in New Issue
Block a user