-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix error display for websocket fetchers (#2535)
* don't join multiple errors in ws-fetcher * make `formatError` typings more generic * fix async interable execution * add e2e test suite for errors * add changeset * fix error assertion for older graphql versions
- Loading branch information
1 parent
0fc3273
commit ea732ea
Showing
13 changed files
with
172 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphiql/toolkit': patch | ||
--- | ||
|
||
Fix error formatting for websocket requests and make error formatting more generic in general |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { version } from 'graphql'; | ||
|
||
describe('Errors', () => { | ||
it('Should show an error when the HTTP request fails', () => { | ||
cy.visit('/?http-error=true'); | ||
cy.assertQueryResult({ | ||
errors: [ | ||
{ | ||
/** | ||
* The exact error message can differ depending on the browser and | ||
* its JSON parser. This is the error you get in Electron (which | ||
* we use to run the tests headless), the error in the latest Chrome | ||
* version is different! | ||
*/ | ||
message: 'Unexpected token B in JSON at position 0', | ||
stack: 'SyntaxError: Unexpected token B in JSON at position 0', | ||
}, | ||
], | ||
}); | ||
}); | ||
it('Should show an error when introspection fails', () => { | ||
cy.visit('/?graphql-error=true'); | ||
cy.assertQueryResult({ | ||
errors: [{ message: 'Something unexpected happened...' }], | ||
}); | ||
}); | ||
it('Should show an error when the schema is invalid', () => { | ||
cy.visit('/?bad=true'); | ||
/** | ||
* We can't use `cy.assertQueryResult` here because the stack contains line | ||
* and column numbers of the `graphiql.min.js` bundle which are not stable. | ||
*/ | ||
cy.get('section.result-window').should(element => { | ||
expect(element.get(0).innerText).to.contain( | ||
version.startsWith('16.') | ||
? 'Names must only contain [_a-zA-Z0-9] but \\"<img src=x onerror=alert(document.domain)>\\" does not.' | ||
: 'Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \\"<img src=x onerror=alert(document.domain)>\\" does not.', | ||
); | ||
}); | ||
}); | ||
it('Should show an error when sending an invalid query', () => { | ||
cy.visitWithOp({ query: '{thisDoesNotExist}' }); | ||
cy.clickExecuteQuery(); | ||
cy.assertQueryResult({ | ||
errors: [ | ||
{ | ||
message: 'Cannot query field "thisDoesNotExist" on type "Test".', | ||
locations: [{ line: 1, column: 2 }], | ||
}, | ||
], | ||
}); | ||
}); | ||
it('Should show an error when sending an invalid subscription', () => { | ||
cy.visitWithOp({ query: 'subscription {thisDoesNotExist}' }); | ||
cy.clickExecuteQuery(); | ||
cy.assertQueryResult({ | ||
errors: [ | ||
{ | ||
message: | ||
'Cannot query field "thisDoesNotExist" on type "SubscriptionType".', | ||
locations: [{ line: 1, column: 15 }], | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.