From 0561a9afe9a97463fc71f1b2f6d7c91352b15959 Mon Sep 17 00:00:00 2001 From: Peteranny Date: Wed, 26 Jun 2024 21:39:08 +0800 Subject: [PATCH] minify query --- src/utils/graphqlClient.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/utils/graphqlClient.js b/src/utils/graphqlClient.js index 7fd28adda..d534b0e44 100644 --- a/src/utils/graphqlClient.js +++ b/src/utils/graphqlClient.js @@ -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;