Skip to content

Commit

Permalink
fix: formatGraphQLErrors for persisted queries (#119)
Browse files Browse the repository at this point in the history
* Fix formatGraphQLErrors for persisted queries

* Change implementation

* Minimize diff

Co-authored-by: Jordan Gensler <jgensler@netflix.com>
  • Loading branch information
kesne and Jordan Gensler committed Oct 20, 2020
1 parent e04d347 commit 6a6ee9f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/createRequestError.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ export function formatGraphQLErrors(request: RelayRequest, errors: GraphQLRespon
const indent = ' '.repeat(prefix.length);

// custom errors thrown in graphql-server may not have locations
const locationMessage = locations
? '\n' +
locations
.map(({ column, line }) => {
const queryLine = queryLines[line - 1];
const offset = Math.min(column - 1, CONTEXT_BEFORE);
return [
queryLine.substr(column - 1 - offset, CONTEXT_LENGTH),
`${' '.repeat(Math.max(offset, 0))}^^^`,
]
.map((messageLine) => indent + messageLine)
.join('\n');
})
.join('\n')
: '';
const locationMessage =
locations && queryLines.length
? '\n' +
locations
.map(({ column, line }) => {
const queryLine = queryLines[line - 1];
const offset = Math.min(column - 1, CONTEXT_BEFORE);
return [
queryLine.substr(column - 1 - offset, CONTEXT_LENGTH),
`${' '.repeat(Math.max(offset, 0))}^^^`,
]
.map((messageLine) => indent + messageLine)
.join('\n');
})
.join('\n')
: '';
return prefix + message + locationMessage;
})
.join('\n');
Expand Down

0 comments on commit 6a6ee9f

Please sign in to comment.