From 822adf7c7c586a4ee79ff1fc6a499770b6ca3a85 Mon Sep 17 00:00:00 2001 From: varavut lormongkol Date: Sun, 23 Oct 2016 17:55:04 +0700 Subject: [PATCH 1/3] in non-GET request use json: true option instead JSON.stringify() and change body type to any instead string --- src/main.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7d30a69..e24b7f3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -86,12 +86,12 @@ let verb = config.method || 'GET'; let endpointUrl = config.endpoint; performIntrospectionQuery(body => { - let result = JSON.parse(body); + let result = body; let schema = buildClientSchema(result.data); processFiles(schema); }); -function performIntrospectionQuery(callback: (body: string) => void) { +function performIntrospectionQuery(callback: (body: any) => void) { // introspection query let introspectionUrl = config.schema || config.endpoint; if (!introspectionUrl) { @@ -110,7 +110,8 @@ function performIntrospectionQuery(callback: (body: string) => void) { : { url: introspectionUrl, method, headers: [{ 'Content-Type': 'application/json' }], - body: JSON.stringify({ query: introspectionQuery }) + json: true, + body: { query: introspectionQuery } }; request(reqOpts, function (err, res, body) { From 8e4c719134fd4dc378ef563d086bb404a6bac236 Mon Sep 17 00:00:00 2001 From: varavut lormongkol Date: Sun, 23 Oct 2016 17:56:27 +0700 Subject: [PATCH 2/3] move schema and method option to elmPackageJson.graphql because config object is depends on this field --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index e24b7f3..97c9181 100644 --- a/src/main.ts +++ b/src/main.ts @@ -58,11 +58,11 @@ if (options.init) { config = elmPackageJson.graphql; if (options.schema) { - elmPackageJson.schema = options.schema; + elmPackageJson.graphql.schema = options.schema; } if (options.method) { - elmPackageJson.method = options.method; + elmPackageJson.graphql.method = options.method; } // check that the endpoint works From 60e0a8d0174a66a867cf3b8903b6a933e09b3347 Mon Sep 17 00:00:00 2001 From: varavut lormongkol Date: Sun, 23 Oct 2016 18:13:29 +0700 Subject: [PATCH 3/3] when unexpected type catched log on the console instead throw an exception to break a program --- src/elm-ast.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elm-ast.ts b/src/elm-ast.ts index b644d12..a5ce620 100644 --- a/src/elm-ast.ts +++ b/src/elm-ast.ts @@ -129,7 +129,7 @@ export function typeToString(ty: ElmType, level: number, isField?: boolean): str ty.fields.map(f => fieldToString(f, level + 1)).join(`${indent}, `) + `${indent}}`; } else { - throw new Error('unexpected type: ' + ty.constructor.name + ' ' + JSON.stringify(ty)); + console.error('unexpected type: ' + JSON.stringify(ty)); } }