Skip to content

Strips newlines when parsing GraphQL curl command #2888

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

Merged

Conversation

gerrytan
Copy link
Contributor

@gerrytan gerrytan commented Dec 2, 2020

This PR addresses a bug where GraphQL curl command copied from Chrome is not parsed correctly.

To reproduce the bug:

  1. Copy a graphql request as curl from Chrome network inspector
  2. Paste it into an Insomnia request address bar
  3. Switch the mime type to GraphQL

Expected: user is presented with a valid GraphQL query
Actual: user is presented with an invalid GraphQL (bunch of \n characters)

Video of the problem: here

Video of the new behaviour after this fix: here

Closes #1825

@CLAassistant
Copy link

CLAassistant commented Dec 4, 2020

CLA assistant check
All committers have signed the CLA.

@netlify
Copy link

netlify bot commented Dec 4, 2020

Deploy preview for insomnia-storybook ready!

Built with commit 636f86a

https://deploy-preview-2888--insomnia-storybook.netlify.app

export function newBodyGraphQL(rawBody: string): RequestBody {
try {
// Only strip the newlines if rawBody is a parsable JSON
JSON.parse(rawBody);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no other way to do this, and JSON.parse is the fastest way available, but it still is one of those things I want to mention - if anyone can think of a way to do this without JSON.parseing arbitrary inputs please say so. Sometimes in special cases there are ways around it, but from what I can tell this isn't one of those situations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is one of the special cases either so JSON.parse seems like a reasonable approach to it.

Copy link
Contributor

@dimitropoulos dimitropoulos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionally tested and reviewed code: thanks for the contribution!

@reynolek
Copy link
Contributor

reynolek commented Feb 8, 2021

Updated branch with develop

Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and works great! Thanks for the PR, and apologies for the delays 🙏🏽

@develohpanda develohpanda changed the title Strips newlines when parsing GraphQL curl command (#1825) Strips newlines when parsing GraphQL curl command Feb 9, 2021
@develohpanda develohpanda merged commit 021b9f5 into Kong:develop Feb 9, 2021
@gerrytan
Copy link
Contributor Author

gerrytan commented Feb 9, 2021

Thanks a lot for your help @dimitropoulos and @develohpanda

gravyboat pushed a commit to gravyboat/insomnia that referenced this pull request Feb 9, 2021
Co-authored-by: Eric Reynolds <reynolek@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Insomnia is not converting some CURL requests to GraphQL properly
5 participants