Skip to content
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

[umbrealla] use a true graphql prettifier (i.e., one designed for prettifying) #3242

Closed
dimitropoulos opened this issue Mar 25, 2021 · 6 comments · Fixed by #4022
Closed
Labels
A-graphql Area: GraphQL Protocol B-bug Bug: general classification E-good-first-issue Experience required: Beginner / New S-verified Status: Verified by maintainer stale Bot: Stale Issue

Comments

@dimitropoulos
Copy link
Contributor

dimitropoulos commented Mar 25, 2021

Describe the bug
There are a number of bugs that arise from our current approach to prettifying graphql:

To Reproduce

  1. Create a GraphQL request
  2. click Pretify GraphQL and observe the results

Expected behavior
The above issues have different solutions, but the over-arching concept is that the prettifying should work as one might naturally expect (and definitely without destroying information).

I think we should look at other tools and graphql clients to see how they approach this problem and go with the most widely adopted solution. I believe prettier may be an option, but the docs are down at the time of writing this issue.

@dimitropoulos dimitropoulos added B-bug Bug: general classification S-unverified Status: Unverified by maintainer S-verified Status: Verified by maintainer A-graphql Area: GraphQL Protocol and removed S-unverified Status: Unverified by maintainer labels Mar 25, 2021
@dimitropoulos
Copy link
Contributor Author

type Book {
  title: String, asdflnasdf: String, oqweroiyweroiyqwreoiqwer: String, nbiuiwrogiuwn: String, oineoinvoiunaouinaoiubhj: String,   nasgoinaionabionafb: String, author: Author
}

# comment that should not be removed
type Author {
  name: String
  books: [Book]
}

The above is an example of a formatter that would fix all of the above 3 bugs (and probably more). It can be found at https://mtp.tools/formatters/graphql-formatter but I don't see what editor it's uses (it makes a network request with your query 🤕)


Interestingly, the GraphiQL editor (the one I'm the most familiar with) doesn't seem as capable (for one thing, it destroys the comments).

@nijikokun nijikokun added the E-good-first-issue Experience required: Beginner / New label Mar 26, 2021
@stale
Copy link

stale bot commented May 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Bot: Stale Issue label May 26, 2021
@ariasmn
Copy link
Contributor

ariasmn commented Jul 16, 2021

Hi!

I have (kinda) looked into it, and the problem with the comments comes from the Javascript GraphQL library AST, since it can't parse comments. If they implement it, making a small library to correctly prettify the code should not be much of a problem, but modifying the parser is out of my league sadly.

My guess is that the one from mtp.tools is using a whole different GraphQL AST that parse comments correctly.

I hope that this information helps you!

@ariasmn
Copy link
Contributor

ariasmn commented Jul 16, 2021

Actually, Prettier should work to correctly solve the bugs mentioned. I might look into it later and try to make a PR if that's ok!

EDIT: @dimitropoulos May I have any pointer on how/where to load the Prettier package?

@dimitropoulos
Copy link
Contributor Author

@ariasmn I would love to see a PR for this!! You'd add it to the insomnia-app package and run it using the prettier API (https://prettier.io/docs/en/api.html).

Lemme know how I can help!

@ariasmn
Copy link
Contributor

ariasmn commented Sep 11, 2021

@dimitropoulos I just submitted a PR for this. Sorry it took that long, I have been a bit busy. 😅
Please let me know if any changes are needed!

gatzjames added a commit that referenced this issue Oct 1, 2021
* Implemented Prettier for GraphQL formatting (#3242)

* package bump and linting

Co-authored-by: Dimitri Mitropoulos <[email protected]>
Co-authored-by: James Gatz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-graphql Area: GraphQL Protocol B-bug Bug: general classification E-good-first-issue Experience required: Beginner / New S-verified Status: Verified by maintainer stale Bot: Stale Issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants