Skip to content

Commit

Permalink
Fix query detection
Browse files Browse the repository at this point in the history
  • Loading branch information
s12v committed Nov 19, 2017
1 parent cd5830b commit f307fe1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/components/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Table extends React.Component {
}

handleRequest(har) {
if (!HarUtils.getGraphQLQuery(har)) {
if (!HarUtils.isGraphQLQuery(har)) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions client/services/HarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default class HarUtils {
return {};
}

static isGraphQLQuery(har) {
const query = this.getGraphQLQuery(har);
return query.hasOwnProperty('query');
}

static getGraphQLQuery(har) {
if (!this.isJson(har)) {
return {};
Expand Down
11 changes: 11 additions & 0 deletions client/test/HarUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ describe('HarUtils', () => {
expect(HarUtils.isJson(har)).to.equal(false);
});

it('should detect a GraphQL query', () => {
let har = harWithHeader({}, 'content-type', 'application/json');
har = harWithPostData(har, '{"query": "{}"}');
expect(HarUtils.isGraphQLQuery(har)).to.equal(true);
});

it('should detect not a GraphQL query', () => {
let har = harWithHeader({}, 'content-type', 'application/json');
expect(HarUtils.isGraphQLQuery(har)).to.equal(false);
});

it('should return GraphQL query', () => {
let har = harWithHeader({}, 'content-type', 'application/json');
har = harWithPostData(har, '{"query": "{}"}');
Expand Down

0 comments on commit f307fe1

Please sign in to comment.