From 84828ec6addca64e6fb4684fbf364d780d1ab1a8 Mon Sep 17 00:00:00 2001 From: Divyendu Singh Date: Fri, 13 Jul 2018 17:36:48 +0530 Subject: [PATCH] feat: support binding generation with sdl file --- src/bin.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 0679b435..b405bd76 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -6,7 +6,7 @@ import * as mkdirp from 'mkdirp' import * as path from 'path' import { Generator } from './codegen/Generator' import { TypescriptGenerator } from './codegen/TypescriptGenerator' -import { printSchema } from 'graphql' +import { buildSchema, printSchema } from 'graphql' const argv = yargs .usage( @@ -70,9 +70,12 @@ async function run(argv) { function getSchemaFromInput(input) { if (input.endsWith('.graphql') || input.endsWith('.gql')) { - throw new Error( - 'graphql-bindings 2.0 can only be generated based on an executable Schema exposed by a .js or .ts file', - ) + const sdl = fs.readFileSync(path.resolve(input), 'utf-8') + const schema = buildSchema(sdl) + return { + isDefaultExport: false, + schema + } } if (input.endsWith('.js') || input.endsWith('.ts')) {