Skip to content

Commit

Permalink
Merge pull request #58 from cjoudrey/fix-crash-no-line-breaks
Browse files Browse the repository at this point in the history
Support .graphql files that have no line breaks
  • Loading branch information
Christian Joudrey authored Nov 25, 2017
2 parents 382dc3b + 0320152 commit e872557
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/source_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Configuration', () => {
author: User!
}
type Query {
something: String!
}
Expand Down
Empty file.
9 changes: 8 additions & 1 deletion test/source_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -25,7 +28,9 @@ describe('SourceMap', () => {
type User {
username: String!
email: String!
}`
}
schema { query: Query }
type Comment { user: User! body: String! }`
);
});
});
Expand All @@ -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));
});
});
});

0 comments on commit e872557

Please sign in to comment.