Skip to content
This repository was archived by the owner on May 10, 2018. It is now read-only.

Commit 947c15c

Browse files
André Königkbrandwijk
André König
authored andcommitted
fix(generators): replaces incompatible characters in schema with sane defaults (#51)
1 parent b6a2c68 commit 947c15c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import { Generator } from './types'
66

77
export { Generator } from './types'
88

9+
/**
10+
* The schema contains incompatible characters sometimes, e.g.
11+
* data types in comments are emphasized with "`", which represents
12+
* template strings in ES2015 and TypeScript. This function
13+
* replaces those characters with sane defaults.
14+
*
15+
* @param schema {String} The serialized schema
16+
* @returns {String}
17+
*
18+
*/
19+
const sanitizeSchema = (schema: string) =>
20+
schema.replace(/\`/g, '\'')
21+
922
export function generateCode(schema: string, generator: Generator | string): string {
1023
if (typeof generator === 'string'){
1124
generator = generators[generator] || require(generator).generator
@@ -15,6 +28,8 @@ ${Object.keys(generators).map(k => `'${k}`).join(', ')}`)
1528
}
1629
}
1730

31+
schema = sanitizeSchema(schema);
32+
1833
const document: DocumentNode = parse(schema, { noLocation: true })
1934
const ast: GraphQLSchema = buildASTSchema(document)
2035

test/features/graphcool-ts.feature

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Feature for Graphcool Typescript generator
55
Scenario: Scenario name
66
Given a schema looking like this:
77
"""
8+
# The `Query` type
89
type Query {
910
posts: [String]
1011
}
@@ -17,6 +18,7 @@ Feature for Graphcool Typescript generator
1718
import { GraphQLResolveInfo } from 'graphql'
1819
1920
const typeDefs = `
21+
# The 'Query' type
2022
type Query {
2123
posts: [String]
2224
}`

test/test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,10 @@ input LocationWhereUniqueInput {
25362536
id: ID
25372537
}
25382538
2539+
"""
2540+
The \`Long\` scalar type represents non-fractional signed whole numeric values.
2541+
Long can represent values between -(2^63) and 2^63 - 1.
2542+
"""
25392543
scalar Long
25402544
25412545
type MessageConnection {

0 commit comments

Comments
 (0)