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

Make print() break long List and Object Values over multiple line #3860

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

dylanowen
Copy link

@dylanowen dylanowen commented Mar 9, 2023

This builds upon #2797 to add multiline support for ObjectValues and ListValues.
Example:

{
  trip(
    obj: {wheelchair: false, smallObj: {a: 1}, largeObj: {wheelchair: false, smallObj: {a: 1}, arriveBy: false, includePlannedCancellations: true, transitDistanceReluctance: 2000, anotherLongFieldName: "Lots and lots and lots and lots of text"}, arriveBy: false, includePlannedCancellations: true, transitDistanceReluctance: 2000, anotherLongFieldName: "Lots and lots and lots and lots of text"}
  ) {
    dateTime
  }
  another(
    list: [["small array", "small", "small"], ["Lots and lots and lots and lots of text", "Lots and lots and lots and lots of text", "Lots and lots and lots and lots of text"]]
  ) {
    dateTime
  }
}

is now

{
  trip(
    obj: {
      wheelchair: false,
      smallObj: { a: 1 },
      largeObj: {
        wheelchair: false,
        smallObj: { a: 1 },
        arriveBy: false,
        includePlannedCancellations: true,
        transitDistanceReluctance: 2000,
        anotherLongFieldName: "Lots and lots and lots and lots of text"
      },
      arriveBy: false,
      includePlannedCancellations: true,
      transitDistanceReluctance: 2000,
      anotherLongFieldName: "Lots and lots and lots and lots of text"
    }
  ) {
    dateTime
  }
  another(
    list: [
      ["small array", "small", "small"],
      [
        "Lots and lots and lots and lots of text",
        "Lots and lots and lots and lots of text",
        "Lots and lots and lots and lots of text"
      ]
    ]
  ) {
    dateTime
  }
}

I agree that #2797 (comment) would be a better long term approach but rewriting the printer to support something like the prettier document builder with softlines and length aware line breaks is a much larger effort. This change will allow lines greater than 80 but it at least gives us a reasonable default for when to break out these larger lines.

@netlify
Copy link

netlify bot commented Mar 9, 2023

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit cfde0cc
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/642d881b1369230008db7619
😎 Deploy Preview https://deploy-preview-3860--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@lwilli
Copy link

lwilli commented Mar 15, 2023

I like this formatting much better as well! 👍

@MamiStyle MamiStyle linked an issue Mar 26, 2023 that may be closed by this pull request
@github-advanced-security
Copy link

You have successfully added a new CodeQL configuration .github/workflows/pull_request.yml:codeql. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab.

@IvanGoncharov
Copy link
Member

@dylanowen Thanks for PR!
I changed it to match both spec examples and prettier output (removed commas)
Also I changed a code to match existing solution for args from #2797

@IvanGoncharov IvanGoncharov added the PR: feature 🚀 requires increase of "minor" version number label Apr 5, 2023
@IvanGoncharov IvanGoncharov merged commit ddd6a01 into graphql:main Apr 5, 2023
@dylanowen
Copy link
Author

@IvanGoncharov Thanks for fixing this up and getting it in!

@dylanowen dylanowen deleted the printer-value-length branch October 19, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature 🚀 requires increase of "minor" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No entiendo nada
3 participants