From 01b6439587332d44cd28f5e650f44203484c56b1 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 29 Mar 2017 19:37:27 +0300 Subject: [PATCH] concat ASTs instead of IDLs --- src/index.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 8f410b5..f037c63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,9 @@ import { Source, - buildSchema, + parse, + concatAST, + buildASTSchema, } from 'graphql'; import * as fs from 'fs'; @@ -67,7 +69,7 @@ let fileName = fileArg || (argv.extend ? './schema_extension.faker.graphql' : './schema.faker.graphql'); -const fakeDefinitionIDL = readIDL(path.join(__dirname, 'fake_definition.graphql')); +const fakeDefinitionAST = readAST(path.join(__dirname, 'fake_definition.graphql')); let userIDL; if (existsSync(fileName)) { @@ -87,6 +89,10 @@ function readIDL(filepath) { ); } +function readAST(filepath) { + return parse(readIDL(filepath)); +} + function saveIDL(idl) { fs.writeFileSync(fileName, idl); log(`${chalk.green('✚')} schema saved to ${chalk.magenta(fileName)} on ${(new Date()).toLocaleString()}`); @@ -113,10 +119,8 @@ if (argv.e) { } function buildServerSchema(idl) { - return buildSchema(new Source( - idl.body + '\n' + fakeDefinitionIDL.body, - idl.name - ).body); + var ast = concatAST([parse(idl), fakeDefinitionAST]); + return buildASTSchema(ast); } function runServer(schemaIDL: Source, extensionIDL: Source, optionsCB) {