Skip to content

Commit 3793d4e

Browse files
author
Omri Peleg
committed
WIP
1 parent 473c80e commit 3793d4e

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

src/targets/rapidql/rapidql.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,50 @@ module.exports = function (source, options) {
1111

1212
var code = new CodeBuilder(opts.indent)
1313

14-
code.push('var axios = require("axios").default;')
14+
code.push('// For more information about RapidQL, checkout docs.rapidql.com!')
15+
.push('')
1516
.blank()
17+
code.push('// For more information about RapidQL, checkout docs.rapidql.com!');
18+
code.push("const RapidQL = require('RapidQL');");
19+
code.push('let rql = new RapidQL({');
20+
code.push('});');
21+
code.push('');
22+
code.push('rql.query(`{');
23+
code.push(` Http.${(source.method || '').toLowerCase()}(`);
24+
code.push(` url:"${helpers.quote(source.fullUrl)}"`);
1625

17-
var reqOpts = {
18-
method: source.method,
19-
url: source.url
26+
if (source.headers.length) {
27+
lines.push(` headers : {\n${Object.entries(source.allHeaders).map(([key, val]) => `"${key}":"${val}"`).join(",\n")}\n }`);
2028
}
2129

22-
if (Object.keys(source.queryObj).length) {
23-
reqOpts.params = source.queryObj
24-
}
25-
26-
if (Object.keys(source.allHeaders).length) {
27-
reqOpts.headers = source.allHeaders
28-
}
29-
30-
switch (source.postData.mimeType) {
31-
case 'application/x-www-form-urlencoded':
32-
reqOpts.data = source.postData.paramsObj
33-
break
34-
35-
case 'application/json':
36-
if (source.postData.jsonObj) {
37-
reqOpts.data = source.postData.jsonObj
38-
}
39-
break
30+
// if (parameters.length) {
31+
// appendComma(lines.length - 1);
32+
// lines.push(` form : {\n${parameters.join(",\n")}\n }`);
33+
// }
4034

41-
default:
42-
if (source.postData.text) {
43-
reqOpts.data = source.postData.text
44-
}
35+
if (source?.postData?.text) {
36+
code.push(` json: true,`)
37+
code.push(` body: ${source?.postData?.text}`)
4538
}
4639

47-
code.push('var options = %s;', stringifyObject(reqOpts, { indent: ' ', inlineCharacterLimit: 80 }))
48-
.blank()
40+
// builder.forPayload((payload) => {
41+
// appendComma(lines.length - 1);
42+
// if (payload.format === "JSON") {
43+
// lines.push(` json : true,`);
44+
// lines.push(` body : ${helpers.escapePayload(payload, true)}`);
45+
// } else {
46+
// lines.push(` body : "${helpers.escapePayload(payload)}"`);
47+
// }
48+
// });
4949

50-
code.push(util.format('axios.request(options).then(%s', 'function (response) {'))
51-
.push(1, 'console.log(response.data);')
52-
.push('}).catch(%s', 'function (error) {')
53-
.push(1, 'console.error(error);')
54-
.push('});')
50+
code.push(" ) {");
51+
code.push("");
52+
code.push(" }");
53+
code.push("}`)");
54+
code.push(".then((res) => console.log(res))");
55+
code.push(".catch((err) => console.log(err));");
5556

56-
return code.join()
57+
return code.join();
5758
}
5859

5960
module.exports.info = {

0 commit comments

Comments
 (0)