Skip to content

Commit

Permalink
concat ASTs instead of IDLs
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 29, 2017
1 parent cb2a54c commit 01b6439
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import {
Source,
buildSchema,
parse,
concatAST,
buildASTSchema,
} from 'graphql';

import * as fs from 'fs';
Expand Down Expand Up @@ -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)) {
Expand All @@ -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()}`);
Expand All @@ -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) {
Expand Down

0 comments on commit 01b6439

Please sign in to comment.