Skip to content

Commit

Permalink
feat: support binding generation with sdl file
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyendu Singh committed Jul 13, 2018
1 parent 00c5c97 commit 84828ec
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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')) {
Expand Down

0 comments on commit 84828ec

Please sign in to comment.