Skip to content

Commit 6a6ee9f

Browse files
kesneJordan Gensler
and
Jordan Gensler
authored
fix: formatGraphQLErrors for persisted queries (#119)
* Fix formatGraphQLErrors for persisted queries * Change implementation * Minimize diff Co-authored-by: Jordan Gensler <[email protected]>
1 parent e04d347 commit 6a6ee9f

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/createRequestError.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,22 @@ export function formatGraphQLErrors(request: RelayRequest, errors: GraphQLRespon
3939
const indent = ' '.repeat(prefix.length);
4040

4141
// custom errors thrown in graphql-server may not have locations
42-
const locationMessage = locations
43-
? '\n' +
44-
locations
45-
.map(({ column, line }) => {
46-
const queryLine = queryLines[line - 1];
47-
const offset = Math.min(column - 1, CONTEXT_BEFORE);
48-
return [
49-
queryLine.substr(column - 1 - offset, CONTEXT_LENGTH),
50-
`${' '.repeat(Math.max(offset, 0))}^^^`,
51-
]
52-
.map((messageLine) => indent + messageLine)
53-
.join('\n');
54-
})
55-
.join('\n')
56-
: '';
42+
const locationMessage =
43+
locations && queryLines.length
44+
? '\n' +
45+
locations
46+
.map(({ column, line }) => {
47+
const queryLine = queryLines[line - 1];
48+
const offset = Math.min(column - 1, CONTEXT_BEFORE);
49+
return [
50+
queryLine.substr(column - 1 - offset, CONTEXT_LENGTH),
51+
`${' '.repeat(Math.max(offset, 0))}^^^`,
52+
]
53+
.map((messageLine) => indent + messageLine)
54+
.join('\n');
55+
})
56+
.join('\n')
57+
: '';
5758
return prefix + message + locationMessage;
5859
})
5960
.join('\n');

0 commit comments

Comments
 (0)