feat(code-export): add support to grapqhl (#1288)

Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
ajubin 2024-09-25 07:08:41 +02:00 committed by GitHub
parent 3a58c6d3bd
commit 5889e114d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View File

@ -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';

View File

@ -349,7 +349,7 @@ const CollectionItem = ({ item, collection, searchText }) => {
Run
</div>
)}
{!isFolder && item.type === 'http-request' && (
{!isFolder && (
<div
className="dropdown-item"
onClick={(e) => {

View File

@ -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
};