Skip to content

Commit

Permalink
minify query
Browse files Browse the repository at this point in the history
  • Loading branch information
peteranny committed Jun 26, 2024
1 parent 5201cac commit 0561a9a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/utils/graphqlClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import fetchUtil from './fetchUtil';

const fetch = fetchUtil('/graphql');

const minifyQuery = query =>
query
.replace(/\s?([{}()])\s?/g, '$1')
.replace(/\s+/g, ' ')
.trim();

const graphqlClient = ({ variables, query, options, token }) =>
fetch.post({ body: { query, variables }, token, options }).then(response => {
if (response.errors) {
throw new GraphqlError(response.errors);
}
return response.data;
});
fetch
.post({ body: { query: minifyQuery(query), variables }, token, options })
.then(response => {
if (response.errors) {
throw new GraphqlError(response.errors);
}
return response.data;
});

export default graphqlClient;

0 comments on commit 0561a9a

Please sign in to comment.