diff --git a/frontend/src/lib/components/Editor.svelte b/frontend/src/lib/components/Editor.svelte index 2d7e85a544..fac81b88f9 100644 --- a/frontend/src/lib/components/Editor.svelte +++ b/frontend/src/lib/components/Editor.svelte @@ -235,8 +235,14 @@ let command: Disposable | undefined = undefined let sqlSchemaCompletor: Disposable | undefined = undefined - $: args && - (dbSchema = $dbSchemas[(lang === 'graphql' ? args.api : args.database)?.replace('$res:', '')]) + + function updateSchema(lang, args) { + const schemaRes = lang === 'graphql' ? args.api : args.database + if (schemaRes instanceof String) { + dbSchema = $dbSchemas[schemaRes.replace('$res:', '')] + } + } + $: args && updateSchema(lang, args) $: dbSchema && ['sql', 'graphql'].includes(lang) && addDBSchemaCompletions() $: (!dbSchema || lang !== 'sql') && sqlSchemaCompletor && sqlSchemaCompletor.dispose() $: (!dbSchema || lang !== 'graphql') && graphqlService && graphqlService.setSchemaConfig([]) diff --git a/frontend/src/lib/components/copilot/ScriptFix.svelte b/frontend/src/lib/components/copilot/ScriptFix.svelte index 66fb4bd5b7..0dba249ca2 100644 --- a/frontend/src/lib/components/copilot/ScriptFix.svelte +++ b/frontend/src/lib/components/copilot/ScriptFix.svelte @@ -104,7 +104,13 @@ $: !$generatedCode && hideDiff() - $: dbSchema = $dbSchemas[(lang === 'graphql' ? args.api : args.database)?.replace('$res:', '')] + function updateSchema(lang, args) { + const schemaRes = lang === 'graphql' ? args.api : args.database + if (schemaRes instanceof String) { + dbSchema = $dbSchemas[schemaRes.replace('$res:', '')] + } + } + $: updateSchema(lang, args) {#if SUPPORTED_LANGUAGES.has(lang)} diff --git a/frontend/src/lib/components/copilot/ScriptGen.svelte b/frontend/src/lib/components/copilot/ScriptGen.svelte index 81dafe7f86..301952e152 100644 --- a/frontend/src/lib/components/copilot/ScriptGen.svelte +++ b/frontend/src/lib/components/copilot/ScriptGen.svelte @@ -146,7 +146,13 @@ $: editor && setSelectionHandler() $: selection && (isEdit = !selection.isEmpty()) - $: dbSchema = $dbSchemas[(lang === 'graphql' ? args.api : args.database)?.replace('$res:', '')] + function updateSchema(lang, args) { + const schemaRes = lang === 'graphql' ? args.api : args.database + if (schemaRes instanceof String) { + dbSchema = $dbSchemas[schemaRes.replace('$res:', '')] + } + } + $: updateSchema(lang, args) {#if $generatedCode.length > 0 && !genLoading}