-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Export Request As Code Snippet #1031
Comments
Thanks for pointing that out! That's perfect! |
I might be blind, but I can't see that option on v1.2.0, can only see the options: "Rename", "Clone", "Delete". Maybe it's because it's a graphql query? |
@KarmaCop213 Generate Code option not available for GraphQL request type. |
Hello, It would be great indeed to support export of grapqhl requests :) I've started digging into the code, but I don't have more time now to continue. So I write down below what I've found so it could help future me or someone else to go one step further The code in charge of enabling export into gql is [here] ( bruno/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js Line 330 in 5ca7f6b
But graphql code export is not working due to an error on this line: Line 20 in 5ca7f6b
Here's a basic sample from const harRequest = {
method: 'POST',
url: 'http://localhost:3001/graphql',
httpVersion: 'HTTP/1.1',
cookies: [],
headers: [],
queryString: [],
postData: {
mimeType: '',
text: {
query: 'query liveness {\n\tliveness\t\n}'
}
},
headersSize: 0,
bodySize: 0
}; But when calling [Error [HARError]: validation failed] {
errors: [
{
keyword: 'type',
dataPath: '.postData.text',
schemaPath: 'postData.json#/properties/text/type',
params: { type: 'string' },
message: 'should be string'
}
]
} To understand the difference, I looked at const sameRequestButWithoutGQL = {
method: 'POST',
url: 'http://localhost:3001/graphql',
httpVersion: 'HTTP/1.1',
cookies: [],
headers: [],
queryString: [],
postData: {
mimeType: 'application/json',
text: '{\n "query": \'query liveness {\\n\\tliveness\\t\\n}\'\n}'
},
headersSize: 0,
bodySize: 0
}; So the main difference is in To continue the fix, one should handle gql request differently based on
Here's a file to continue working on to support gql code export const harRequest = {
method: 'POST',
url: 'http://localhost:3001/graphql',
httpVersion: 'HTTP/1.1',
cookies: [],
headers: [],
queryString: [],
postData: {
mimeType: '',
text: {
query: 'query liveness {\n\tliveness\t\n}'
}
},
headersSize: 0,
bodySize: 0
};
const sameRequestButWithoutGQL = {
method: 'POST',
url: 'http://localhost:3001/graphql',
httpVersion: 'HTTP/1.1',
cookies: [],
headers: [],
queryString: [],
postData: {
mimeType: 'application/json',
text: '{\n "query": \'query liveness {\\n\\tliveness\\t\\n}\'\n}'
},
headersSize: 0,
bodySize: 0
};
const { HTTPSnippet } = require('httpsnippet');
const htttSnippet = new HTTPSnippet(sameRequestButWithoutGQL);
console.log(htttSnippet.convert('shell', 'curl')); |
Although Bruno already has the Export Request As Code Snippet feature, +1 to support C# |
Hi. Is this a feature planed? Although it would be nice to be able to generate code Graphql request, instead of removing "Generate code" menu in dots menu, it could be disabled. That would tell user generate code is not yet available for this request. |
Also, the generated code doesn't take into account the pre-request script. In Postman you can copy the actual request being sent after the request has been modified by the script. |
as my organisation is migrating to graphql completely, being able to export graphql requests to curl would be an immensely appreciated feature, even without the capability to take into account pre-request scripts i see there's a pull request already, would it be possible to consider merging it in? |
I completely agree, and I'd like to add that the generated code does not include an authentication header or replace variables. I believe that there should be at least an option for that. |
- GraphQL is now supported: usebruno#1031 - PowerShell generator works: usebruno#1566 - Collection and Folder level headers are now included: usebruno#943 - Variables are fully interpolated: usebruno#417 - Pre-Request-Script is executed for generation: usebruno#1261
Postman has a really handy feature where you can export a request as a code snippet. The code snippet supports curl, C, C#, Go, Java and a lot of other languages. It makes it really easy to prototype something in postman and then have a starting point for implementation. It would be great if we can do this in Bruno as well.
The text was updated successfully, but these errors were encountered: