Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrrt committed Dec 17, 2023
1 parent b28aa32 commit 0c4105c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 2 additions & 10 deletions packages/cli/src/commands/generate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,33 @@ export const generateSchemaAction = async ({
const outputPath = path.resolve(rootPath, hydraSchemaRawPath); // Construct absolute path for output

try {
// Compiler options (optional)
const tsConfig = {
target: ts.ScriptTarget.ESNext,
module: ts.ModuleKind.CommonJS,
};

// Create TypeScript compiler host and program
const compilerHost = ts.createCompilerHost({});
const program = ts.createProgram([configPath], tsConfig, compilerHost);

// Get the source file
const sourceFile = program.getSourceFile(configPath);

if (!sourceFile) {
return logError(`Config [${config}] not found`);
}

// Emit the transpiled code
const { outputText } = ts.transpileModule(sourceFile.getText(), {
compilerOptions: tsConfig,
});

// // Evaluate the transpiled code
const module_ = eval(outputText);
const demoConfig = module_.default || module_;
const validatedConfig = validateConfig(demoConfig);

if (!validatedConfig) {
return logError(`Invalid config [${config}]`);
}

try {
await buildSchemaIntrospection(validatedConfig.schemas, outputPath);
} catch (error) {
return logError("Error generating schema");
} catch (error: any) {
return logError(error.message);
}

logSuccess("Schema generated successfully");
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/handlers/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createYoga } from "graphql-yoga";
import { schema } from "../schema";

export const GraphQLHandler = async (req: Request, env: any, ctx: any): Promise<any> => {
export const GraphQLHandler = async (
req: Request,
env: any,
ctx: any,
): Promise<any> => {
const yoga = createYoga({
schema,
context: async (event) => {
Expand Down

0 comments on commit 0c4105c

Please sign in to comment.