diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..51dedef --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/hera.iml b/.idea/hera.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/hera.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df7825d --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..907aa31 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..102c473 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 1596790765613 + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 4386032..1f2b362 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@103cuong/hera-js", - "version": "0.2.0", + "version": "0.2.1", "description": "👩🏼‍💻 Simple and lightweight GraphQL client.", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/index.ts b/src/index.ts index a401928..efc22ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,17 +1,17 @@ import axios, { AxiosResponse, AxiosRequestConfig } from 'axios'; function formatVariables(variables: any): any { - let formatedVariables = JSON.stringify(variables); - formatedVariables = formatedVariables.replace(/"([^"]+)"\s*:\s*/g, '$1:'); - return formatedVariables; + let formattedVariables = JSON.stringify(variables); + formattedVariables = formattedVariables.replace(/"([^"]+)"\s*:\s*/g, '$1:'); + return formattedVariables; } function formatQuery(query: string, variables: any): string { - let formatedQuery = query; - for (const key in variables) { + let formattedQuery = query; + Object.keys(variables).forEach((key) => { const regex = new RegExp(`\\$${key}`, 'g'); - formatedQuery = formatedQuery.replace(regex, formatVariables(variables[key])); - } - return formatedQuery; + formattedQuery = formattedQuery.replace(regex, formatVariables(variables[key])); + }); + return formattedQuery; } interface Option {