mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 08:34:15 +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 = '';
|
||||
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) {
|
||||
console.error(e);
|
||||
snippet = 'Error generating code snippet';
|
||||
|
@ -349,7 +349,7 @@ const CollectionItem = ({ item, collection, searchText }) => {
|
||||
Run
|
||||
</div>
|
||||
)}
|
||||
{!isFolder && item.type === 'http-request' && (
|
||||
{!isFolder && (
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={(e) => {
|
||||
|
@ -31,6 +31,7 @@ const createHeaders = (request, headers) => {
|
||||
if (contentType !== '') {
|
||||
enabledHeaders.push({ name: 'content-type', value: contentType });
|
||||
}
|
||||
|
||||
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);
|
||||
if (body.mode === 'formUrlEncoded' || body.mode === 'multipartForm') {
|
||||
return {
|
||||
@ -64,7 +72,7 @@ const createPostData = (body) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const buildHarRequest = ({ request, headers }) => {
|
||||
export const buildHarRequest = ({ request, headers, type }) => {
|
||||
return {
|
||||
method: request.method,
|
||||
url: encodeURI(request.url),
|
||||
@ -72,7 +80,7 @@ export const buildHarRequest = ({ request, headers }) => {
|
||||
cookies: [],
|
||||
headers: createHeaders(request, headers),
|
||||
queryString: createQuery(request.params),
|
||||
postData: createPostData(request.body),
|
||||
postData: createPostData(request.body, type),
|
||||
headersSize: 0,
|
||||
bodySize: 0
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user