11import * as fs from "fs" ;
22import * as path from "path" ;
33import * as pg from "pg" ;
4- //import * as vm from "node:vm";
54
65import { promisify } from "util" ;
76import { ExecutionArgs , GraphQLSchema , parse , validate } from "graphql" ;
@@ -16,47 +15,16 @@ import { execute, hookArgs } from "grafast";
1615import { SchemaResult } from "graphile-build" ;
1716import { makeWithPgClientViaPgClientAlreadyInTransaction } from "@dataplan/pg/adaptors/pg" ;
1817import { exportSchemaAsString } from "graphile-export" ;
19- import _module = require( "module" ) ;
20- import { dirname } from "path" ;
21- const { Module, builtinModules } = _module ;
22- import { transformSync } from "@babel/core" ;
18+ import { importFromStringSync } from "module-from-string" ;
2319
2420// TODO: remove this once Grafast gets it's planning under control :D
25- jest . setTimeout ( 3000000 ) ;
26- /*
27- const vmEval = (code: string) => {
28- const context = {} as GraphQLSchema;
29- // Load the module with the dyanamic script.
30- vm.runInNewContext(code, vm.createContext(context));
31- console.log("Returning context: ", JSON.stringify(context, null, 2));
32- return context;
33- };
34- */
35- let cachedSchema = { } as GraphQLSchema ;
36- let haveCache = false ;
21+ jest . setTimeout ( 300000 ) ;
22+
3723const vmEval = ( code : string ) => {
38- if ( ! haveCache ) {
39- const filename = "exported-v5-schema.mjs" ;
40- // Load the module with the dyanamic script.
41- const replacementModule = new Module ( filename , this ) ;
42- replacementModule . filename = filename ;
43- // @ts -ignore
44- replacementModule . paths = Module . _nodeModulePaths ( dirname ( filename ) ) ;
45- const commonJScode = transformSync ( code , {
46- filename,
47- compact : true ,
48- plugins : [ "@babel/plugin-transform-runtime" ] ,
49- } ) ;
50- // @ts -ignore
51- replacementModule . _compile ( commonJScode . code , filename ) ;
52- replacementModule . loaded = true ;
53- cachedSchema = replacementModule . exports . schema as GraphQLSchema ;
54- haveCache = true ;
55- console . log ( "Schema import done - no cache" ) ;
56- } else {
57- console . log ( "Schema import done - from cache" ) ;
58- }
59- return cachedSchema ;
24+ const { schema } = importFromStringSync ( code , {
25+ transformOptions : { loader : "js" } ,
26+ } ) ;
27+ return schema as GraphQLSchema ;
6028} ;
6129
6230const createPostGraphileSchema = async (
0 commit comments