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

feat: format with comments #263

Merged
merged 21 commits into from
Jun 24, 2023

Conversation

Warashi
Copy link
Contributor

@Warashi Warashi commented Jun 24, 2023

This PR makes formatter not to remove comments.
FIXES #262

I have:

  • Added tests covering the bug / feature
  • Updated any relevant documentation

@coveralls
Copy link

coveralls commented Jun 24, 2023

Coverage Status

coverage: 88.544% (+0.1%) from 88.426% when pulling 8e4c68c on Warashi:feature/format-with-comments into 5e5180f on vektah:master.

@Warashi
Copy link
Contributor Author

Warashi commented Jun 24, 2023

I found unused codes and removed.

@sonatard
Copy link
Contributor

sonatard commented Jun 24, 2023

@Warashi Thanks!!

I found that comments disappear in the following cases:

--- a/formatter/testdata/source/schema/definition.graphql
+++ b/formatter/testdata/source/schema/definition.graphql
@@ -1,5 +1,6 @@
 # Cat0 comment
 # Cat0 comment 2
+"""Cat0 description"""
 scalar Cat0
 # Cat1 comment
 type Cat1 {

Could you add description to schema under comments in test files?

@Warashi
Copy link
Contributor Author

Warashi commented Jun 24, 2023

@sonatard Thanks for comment.
I added testcases and fixed codes.

@sonatard
Copy link
Contributor

Thanks!! LGTM!!

@StevenACoffman StevenACoffman merged commit 98e9b07 into vektah:master Jun 24, 2023
@StevenACoffman
Copy link
Collaborator

Thank you both very much! Looking forward to future PRs from you both!

@Warashi Warashi deleted the feature/format-with-comments branch June 24, 2023 14:08
github-merge-queue bot referenced this pull request in infratographer/x Jul 14, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/vektah/gqlparser/v2](https://togithub.com/vektah/gqlparser)
| require | patch | `v2.5.1` -> `v2.5.6` |

---

### Release Notes

<details>
<summary>vektah/gqlparser (github.com/vektah/gqlparser/v2)</summary>

###
[`v2.5.6`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.6)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.5...v2.5.6)

#### What's Changed

- feat: support end of definition comment and end of file comment by
[@&#8203;Warashi](https://togithub.com/Warashi) in
[https://github.com/vektah/gqlparser/pull/264](https://togithub.com/vektah/gqlparser/pull/264)
- feat(formatter): preserve spaces at the head of comments by
[@&#8203;Warashi](https://togithub.com/Warashi) in
[https://github.com/vektah/gqlparser/pull/265](https://togithub.com/vektah/gqlparser/pull/265)

**Full Changelog**:
vektah/gqlparser@v2.5.5...v2.5.6

###
[`v2.5.5`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.5)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.4...v2.5.5)

#### What's Changed

- feat: format with comments by
[@&#8203;Warashi](https://togithub.com/Warashi) in
[https://github.com/vektah/gqlparser/pull/263](https://togithub.com/vektah/gqlparser/pull/263)

**Full Changelog**:
vektah/gqlparser@v2.5.4...v2.5.5

###
[`v2.5.4`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.4)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.3...v2.5.4)

#### What's Changed

- feat(lexer): comment token support by
[@&#8203;Warashi](https://togithub.com/Warashi) in
[https://github.com/vektah/gqlparser/pull/261](https://togithub.com/vektah/gqlparser/pull/261)

#### New Contributors

- [@&#8203;Warashi](https://togithub.com/Warashi) made their first
contribution in
[https://github.com/vektah/gqlparser/pull/261](https://togithub.com/vektah/gqlparser/pull/261)

**Full Changelog**:
vektah/gqlparser@v2.5.3...v2.5.4

###
[`v2.5.3`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.3)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.2...v2.5.3)

#### What's Changed

- Update modules by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[https://github.com/vektah/gqlparser/pull/259](https://togithub.com/vektah/gqlparser/pull/259)

**Full Changelog**:
vektah/gqlparser@v2.5.2...v2.5.3

###
[`v2.5.2`](https://togithub.com/vektah/gqlparser/releases/tag/v2.5.2)

[Compare
Source](https://togithub.com/vektah/gqlparser/compare/v2.5.1...v2.5.2)

#### What's Changed

- Add github actions to lint by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[https://github.com/vektah/gqlparser/pull/241](https://togithub.com/vektah/gqlparser/pull/241)
- GH Actions CI Additions + Linter fixups by
[@&#8203;philipaconrad](https://togithub.com/philipaconrad) in
[https://github.com/vektah/gqlparser/pull/242](https://togithub.com/vektah/gqlparser/pull/242)
- Prefer to wrap third party errors by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[https://github.com/vektah/gqlparser/pull/243](https://togithub.com/vektah/gqlparser/pull/243)
- Remove a duplicate line in lexer_test.yml by
[@&#8203;ryicoh](https://togithub.com/ryicoh) in
[https://github.com/vektah/gqlparser/pull/244](https://togithub.com/vektah/gqlparser/pull/244)
- Point to the right GraphQL spec by
[@&#8203;Khyme](https://togithub.com/Khyme) in
[https://github.com/vektah/gqlparser/pull/250](https://togithub.com/vektah/gqlparser/pull/250)
- Bump json5 from 2.2.0 to 2.2.3 in /validator/imported by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/vektah/gqlparser/pull/251](https://togithub.com/vektah/gqlparser/pull/251)
- support [@&#8203;defer](https://togithub.com/defer) directive by
[@&#8203;fiatjaf](https://togithub.com/fiatjaf) in
[https://github.com/vektah/gqlparser/pull/255](https://togithub.com/vektah/gqlparser/pull/255)
- Don't drop repeatable keyword when formatting directive by
[@&#8203;tadeokondrak](https://togithub.com/tadeokondrak) in
[https://github.com/vektah/gqlparser/pull/256](https://togithub.com/vektah/gqlparser/pull/256)
- Validate directive arguments during schema parsing by
[@&#8203;fredzqm](https://togithub.com/fredzqm) in
[https://github.com/vektah/gqlparser/pull/258](https://togithub.com/vektah/gqlparser/pull/258)
- Validate enum values directive are legit by
[@&#8203;fredzqm](https://togithub.com/fredzqm) in
[https://github.com/vektah/gqlparser/pull/257](https://togithub.com/vektah/gqlparser/pull/257)

#### New Contributors

- [@&#8203;ryicoh](https://togithub.com/ryicoh) made their first
contribution in
[https://github.com/vektah/gqlparser/pull/244](https://togithub.com/vektah/gqlparser/pull/244)
- [@&#8203;Khyme](https://togithub.com/Khyme) made their first
contribution in
[https://github.com/vektah/gqlparser/pull/250](https://togithub.com/vektah/gqlparser/pull/250)
- [@&#8203;fiatjaf](https://togithub.com/fiatjaf) made their first
contribution in
[https://github.com/vektah/gqlparser/pull/255](https://togithub.com/vektah/gqlparser/pull/255)
- [@&#8203;tadeokondrak](https://togithub.com/tadeokondrak) made their
first contribution in
[https://github.com/vektah/gqlparser/pull/256](https://togithub.com/vektah/gqlparser/pull/256)
- [@&#8203;fredzqm](https://togithub.com/fredzqm) made their first
contribution in
[https://github.com/vektah/gqlparser/pull/258](https://togithub.com/vektah/gqlparser/pull/258)

**Full Changelog**:
vektah/gqlparser@v2.5.1...v2.5.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/infratographer/x).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTAuMCIsInVwZGF0ZWRJblZlciI6IjM1LjE0MS4zIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
benjaminjkraft added a commit to benjaminjkraft/gqlparser that referenced this pull request Jul 16, 2023
In vektah#263, we introduced parsing of comments, as well as support for them
in the formatter. In some cases this is surely useful, but in others
it's just bloat. (And as I describe in Khan/genqlient#282, it may even
be a problem in some cases which depended on the fact that formatting
the query didn't include comments.)

In this commit I introduce an option to control whether comments are
formatted. I set the default to false (i.e. restoring the previous
behavior if no options are set), because adding this felt to me
like a breaking change, and because it seems to me like the more common
usage. `WithComments()` restores the behavior added in vektah#263. If others
disagree I'm happy to keep the changed default, and instead provide
`WithoutComments()`. I also added tests both ways (and for the existing
`WithIndent()` option), and checked that the `comments` tests match the
existing ones, and the `default` tests match those from `v2.6.3` (except
for the addition of a few descriptions whose omission seem to have been
a bug).

Comments are still parsed in any case, as adding new struct fields is no
problem; and they are still included in `Dump` since that seems
obviously parallel to struct fields and is more of a debugging thing.
StevenACoffman pushed a commit that referenced this pull request Jul 17, 2023
* Put comments behind an option in formatter

In #263, we introduced parsing of comments, as well as support for them
in the formatter. In some cases this is surely useful, but in others
it's just bloat. (And as I describe in Khan/genqlient#282, it may even
be a problem in some cases which depended on the fact that formatting
the query didn't include comments.)

In this commit I introduce an option to control whether comments are
formatted. I set the default to false (i.e. restoring the previous
behavior if no options are set), because adding this felt to me
like a breaking change, and because it seems to me like the more common
usage. `WithComments()` restores the behavior added in #263. If others
disagree I'm happy to keep the changed default, and instead provide
`WithoutComments()`. I also added tests both ways (and for the existing
`WithIndent()` option), and checked that the `comments` tests match the
existing ones, and the `default` tests match those from `v2.6.3` (except
for the addition of a few descriptions whose omission seem to have been
a bug).

Comments are still parsed in any case, as adding new struct fields is no
problem; and they are still included in `Dump` since that seems
obviously parallel to struct fields and is more of a debugging thing.

* docs
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.

FormatSchemaDocument and FormatQueryDocument support to print comments
4 participants