Skip to content

Commit

Permalink
fix: use pathToFileURL in loadSchemaJs
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo committed Dec 28, 2024
1 parent b54a40b commit 0f84f8a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pathToFileURL } from "node:url";
import type { GraphQLNamedType } from "graphql";

export type LoadSchemaResult = {
Expand All @@ -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<LoadSchemaResult> {
let loaded = await import(module);
export async function loadSchemaJs(
schemaPath: string
): Promise<LoadSchemaResult> {
let loaded = await import(pathToFileURL(schemaPath).toString());
while (loaded?.default) {
loaded = loaded.default;
}
Expand Down Expand Up @@ -44,7 +47,7 @@ export async function loadSchemaJs(module: string): Promise<LoadSchemaResult> {
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.`
);
}

Expand Down

0 comments on commit 0f84f8a

Please sign in to comment.