Repository: apollographql/apollo-codegen
Pull request #380 (2018-02-16 21:14:59)

handle more than one line break in comments
I believe the title says it all.

meteor-bot: @quentin-: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/
rgoldfinger: @lewisf mind taking a look?
lewisf: thank you!

Patch:
diff --git a/src/javascript/flow/language.ts b/src/javascript/flow/language.ts
index d306dc65..8ffe92b0 100644
--- a/src/javascript/flow/language.ts
+++ b/src/javascript/flow/language.ts
@@ -104,7 +104,7 @@ export default class FlowGenerator {
         if (description) {
           objectTypeProperty.trailingComments = [{
             type: 'CommentLine',
-            value: ` ${description.replace('\n', ' ')}`
+            value: ` ${description.replace(new RegExp('\n', 'g'), ' ')}`
           } as t.CommentLine]
         }
 
diff --git a/src/javascript/typescript/language.ts b/src/javascript/typescript/language.ts
index 7197ea9c..fce3d652 100644
--- a/src/javascript/typescript/language.ts
+++ b/src/javascript/typescript/language.ts
@@ -56,7 +56,7 @@ export default class TypescriptGenerator {
     if (description) {
       typeAlias.leadingComments = [{
         type: 'CommentLine',
-        value: ` ${description.replace('\n', ' ')}`
+        value: ` ${description.replace(new RegExp('\n', 'g'), ' ')}`
       } as t.CommentLine];
     }
 
@@ -106,7 +106,7 @@ export default class TypescriptGenerator {
       if (description) {
         propertySignatureType.trailingComments = [{
           type: 'CommentLine',
-          value: ` ${description.replace('\n', ' ')}`
+          value: ` ${description.replace(new RegExp('\n', 'g'), ' ')}`
         } as t.CommentLine]
       }
 


Test patch:
diff --git a/test/fixtures/misc/schema.json b/test/fixtures/misc/schema.json
index 90e8d21d..109612af 100644
--- a/test/fixtures/misc/schema.json
+++ b/test/fixtures/misc/schema.json
@@ -191,7 +191,7 @@
             },
             {
               "name": "multiLine",
-              "description": "This is a multi-line\ncomment.",
+              "description": "This is a\nmulti-line\ncomment.",
               "args": [],
               "type": {
                 "kind": "SCALAR",
@@ -235,7 +235,7 @@
             },
             {
               "name": "second",
-              "description": "This is a multi-line\ncomment.",
+              "description": "This is a\nmulti-line\ncomment.",
               "isDeprecated": false,
               "deprecationReason": null
             }
@@ -1382,4 +1382,4 @@
       ]
     }
   }
-}
\ No newline at end of file
+}
diff --git a/test/flow/__snapshots__/codeGeneration.js.snap b/test/flow/__snapshots__/codeGeneration.js.snap
index 056cb715..657326c2 100644
--- a/test/flow/__snapshots__/codeGeneration.js.snap
+++ b/test/flow/__snapshots__/codeGeneration.js.snap
@@ -432,7 +432,8 @@ exports[`Flow code generation #generateSource() should handle comments in enums
 
 export type EnumCommentTestCase =
   \\"first\\" | // This is a single-line comment
-  // This is a multi-line
+  // This is a
+  // multi-line
   // comment.
   \\"second\\";
 
@@ -472,7 +473,8 @@ exports[`Flow code generation #generateSource() should handle multi-line comment
 export type CustomScalarQuery = {|
   commentTest: ? {|
     __typename: \\"CommentTest\\",
-    // This is a multi-line
+    // This is a
+    // multi-line
     // comment.
     multiLine: ?string,
   |},
diff --git a/test/typescript/__snapshots__/codeGeneration.js.snap b/test/typescript/__snapshots__/codeGeneration.js.snap
index 935f3814..cfde0282 100644
--- a/test/typescript/__snapshots__/codeGeneration.js.snap
+++ b/test/typescript/__snapshots__/codeGeneration.js.snap
@@ -334,7 +334,8 @@ exports[`TypeScript code generation #generateSource() should handle comments in
 
 export enum EnumCommentTestCase {
   first = \\"first\\", // This is a single-line comment
-  // This is a multi-line
+  // This is a
+  // multi-line
   // comment.
   second = \\"second\\",
 }
@@ -375,7 +376,8 @@ exports[`TypeScript code generation #generateSource() should handle multi-line c
 export interface CustomScalarQuery {
   commentTest:  {
     __typename: \\"CommentTest\\",
-    // This is a multi-line
+    // This is a
+    // multi-line
     // comment.
     multiLine: string | null,
   } | null,