diff --git a/typegate/tests/runtimes/deno/deno_test.ts b/typegate/tests/runtimes/deno/deno_test.ts index 927788548..ad365139a 100644 --- a/typegate/tests/runtimes/deno/deno_test.ts +++ b/typegate/tests/runtimes/deno/deno_test.ts @@ -141,12 +141,12 @@ Meta.test("Deno runtime with typescript", async (t) => { await gql` query { hello(name: "World") - helloFn(name: "World!") + helloFn(name: "wOrLd") } ` .expectData({ hello: "Hello World", - helloFn: "Hello World!", + helloFn: "Hello world", }) .on(e); }); diff --git a/typegate/tests/runtimes/deno/deno_typescript.ts b/typegate/tests/runtimes/deno/deno_typescript.ts index 5799a7209..20815d20f 100644 --- a/typegate/tests/runtimes/deno/deno_typescript.ts +++ b/typegate/tests/runtimes/deno/deno_typescript.ts @@ -6,10 +6,10 @@ import { DenoRuntime } from "@typegraph/sdk/runtimes/deno.js"; const hello = ({ name }: any) => `Hello ${name}`; function helloFn({ name }: any) { - return `Hello ${name}`; + return `Hello ${(name as string).toLowerCase()}`; } -typegraph("test-deno-static", (g: any) => { +typegraph("test-deno-tyepscript", (g: any) => { const deno = new DenoRuntime(); const pub = Policy.public(); diff --git a/typegraph/node/sdk/src/runtimes/deno.ts b/typegraph/node/sdk/src/runtimes/deno.ts index 605c07e1c..fd3c17e10 100644 --- a/typegraph/node/sdk/src/runtimes/deno.ts +++ b/typegraph/node/sdk/src/runtimes/deno.ts @@ -39,7 +39,23 @@ export interface DenoImport { } function stringifyFn(code: string | Function) { - return typeof code == "function" ? code.toString() : code; + if (typeof code == "function") { + const source = code.toString(); + const namedFnMatch = source.match(/function\s*(\*?\s*[a-zA-Z0-9_]+)/); + if (namedFnMatch) { + const [, name] = namedFnMatch; + if (name.replace(/s/g, "").startsWith("*")) { + throw new Error(`Generator function "${name}" not supported`); + } + if (/function\s[a-zA-Z0-9_]+\(\) { \[native code\] }/.test(source)) { + throw new Error( + `"${name}" is not supported as it is a native function`, + ); + } + } + return source; + } + return code; } export class DenoRuntime extends Runtime {