mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-16 17:51:48 +01:00
feat(code-export): add support to grapqhl (#1288)
Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
parent
3a58c6d3bd
commit
5889e114d4
@ -32,7 +32,10 @@ const CodeView = ({ language, item }) => {
|
|||||||
|
|
||||||
let snippet = '';
|
let snippet = '';
|
||||||
try {
|
try {
|
||||||
snippet = new HTTPSnippet(buildHarRequest({ request: item.request, headers })).convert(target, client);
|
snippet = new HTTPSnippet(buildHarRequest({ request: item.request, headers, type: item.type })).convert(
|
||||||
|
target,
|
||||||
|
client
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
snippet = 'Error generating code snippet';
|
snippet = 'Error generating code snippet';
|
||||||
|
@ -349,7 +349,7 @@ const CollectionItem = ({ item, collection, searchText }) => {
|
|||||||
Run
|
Run
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isFolder && item.type === 'http-request' && (
|
{!isFolder && (
|
||||||
<div
|
<div
|
||||||
className="dropdown-item"
|
className="dropdown-item"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
@ -31,6 +31,7 @@ const createHeaders = (request, headers) => {
|
|||||||
if (contentType !== '') {
|
if (contentType !== '') {
|
||||||
enabledHeaders.push({ name: 'content-type', value: contentType });
|
enabledHeaders.push({ name: 'content-type', value: contentType });
|
||||||
}
|
}
|
||||||
|
|
||||||
return enabledHeaders;
|
return enabledHeaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -43,7 +44,14 @@ const createQuery = (queryParams = []) => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const createPostData = (body) => {
|
const createPostData = (body, type) => {
|
||||||
|
if (type === 'graphql-request') {
|
||||||
|
return {
|
||||||
|
mimeType: 'application/json',
|
||||||
|
text: JSON.stringify(body[body.mode])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const contentType = createContentType(body.mode);
|
const contentType = createContentType(body.mode);
|
||||||
if (body.mode === 'formUrlEncoded' || body.mode === 'multipartForm') {
|
if (body.mode === 'formUrlEncoded' || body.mode === 'multipartForm') {
|
||||||
return {
|
return {
|
||||||
@ -64,7 +72,7 @@ const createPostData = (body) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildHarRequest = ({ request, headers }) => {
|
export const buildHarRequest = ({ request, headers, type }) => {
|
||||||
return {
|
return {
|
||||||
method: request.method,
|
method: request.method,
|
||||||
url: encodeURI(request.url),
|
url: encodeURI(request.url),
|
||||||
@ -72,7 +80,7 @@ export const buildHarRequest = ({ request, headers }) => {
|
|||||||
cookies: [],
|
cookies: [],
|
||||||
headers: createHeaders(request, headers),
|
headers: createHeaders(request, headers),
|
||||||
queryString: createQuery(request.params),
|
queryString: createQuery(request.params),
|
||||||
postData: createPostData(request.body),
|
postData: createPostData(request.body, type),
|
||||||
headersSize: 0,
|
headersSize: 0,
|
||||||
bodySize: 0
|
bodySize: 0
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user