From e8407cef0e267c32b91b91b3a1849b0e73a87aa1 Mon Sep 17 00:00:00 2001 From: Christian Joudrey Date: Sat, 25 Nov 2017 14:06:53 -0500 Subject: [PATCH 1/2] Support .graphql files that have no line breaks - #53 --- src/source_map.js | 3 ++- test/source_map.js | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/source_map.js b/src/source_map.js index 2de27f3..4c49e90 100644 --- a/src/source_map.js +++ b/src/source_map.js @@ -11,7 +11,8 @@ export class SourceMap { return paths.reduce((offsets, path) => { const currentSegment = this.sourceFiles[path]; - const amountLines = currentSegment.match(/\r?\n/g).length; + const currentSegmentLines = currentSegment.match(/\r?\n/g); + const amountLines = currentSegmentLines ? currentSegmentLines.length : 0; const startLine = currentOffset; const endLine = currentOffset + amountLines; diff --git a/test/source_map.js b/test/source_map.js index a6eee69..6174e84 100644 --- a/test/source_map.js +++ b/test/source_map.js @@ -10,6 +10,9 @@ const sourceFiles = { username: String! email: String! }`, + + 'schema.graphql': 'schema { query: Query }', + 'comment.graphql': 'type Comment { user: User! body: String! }', }; describe('SourceMap', () => { @@ -25,7 +28,9 @@ describe('SourceMap', () => { type User { username: String! email: String! -}` +} +schema { query: Query } +type Comment { user: User! body: String! }` ); }); }); @@ -41,6 +46,8 @@ type User { assert.equal('user.graphql', sourceMap.getOriginalPathForLine(5)); assert.equal('user.graphql', sourceMap.getOriginalPathForLine(6)); assert.equal('user.graphql', sourceMap.getOriginalPathForLine(7)); + assert.equal('schema.graphql', sourceMap.getOriginalPathForLine(8)); + assert.equal('comment.graphql', sourceMap.getOriginalPathForLine(9)); }); }); }); From 0320152ed7426b4a58df76efd07d26d19549b9fe Mon Sep 17 00:00:00 2001 From: Christian Joudrey Date: Sat, 25 Nov 2017 14:09:07 -0500 Subject: [PATCH 2/2] Add extra test case --- test/configuration.js | 1 + test/fixtures/schema/empty.graphql | 0 2 files changed, 1 insertion(+) create mode 100644 test/fixtures/schema/empty.graphql diff --git a/test/configuration.js b/test/configuration.js index fa6810e..21b8141 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -16,6 +16,7 @@ describe('Configuration', () => { author: User! } + type Query { something: String! } diff --git a/test/fixtures/schema/empty.graphql b/test/fixtures/schema/empty.graphql new file mode 100644 index 0000000..e69de29