From 0f84f8a96bfdfd99a4ce493c863169eb593c9567 Mon Sep 17 00:00:00 2001 From: uhyo Date: Sat, 28 Dec 2024 20:05:41 +0900 Subject: [PATCH] fix: use pathToFileURL in loadSchemaJs --- packages/core/src/loader.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/src/loader.ts b/packages/core/src/loader.ts index 4123a789..1a2a0d8b 100644 --- a/packages/core/src/loader.ts +++ b/packages/core/src/loader.ts @@ -1,3 +1,4 @@ +import { pathToFileURL } from "node:url"; import type { GraphQLNamedType } from "graphql"; export type LoadSchemaResult = { @@ -14,8 +15,10 @@ export type LoadSchemaResult = { /** * Loads given JS module as a schema and returns the schema as a SDL string. */ -export async function loadSchemaJs(module: string): Promise { - let loaded = await import(module); +export async function loadSchemaJs( + schemaPath: string +): Promise { + let loaded = await import(pathToFileURL(schemaPath).toString()); while (loaded?.default) { loaded = loaded.default; } @@ -44,7 +47,7 @@ export async function loadSchemaJs(module: string): Promise { return { schema: graphql.printSchema(loaded), typeExtensions }; } throw new Error( - `Failed to load schema from '${module}'. The module must export a string or a GraphQLSchema object.` + `Failed to load schema from '${schemaPath}'. The module must export a string or a GraphQLSchema object.` ); }