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

Configure formatter width #1156

Conversation

andersonmcook
Copy link
Contributor

I wanted to adopt the new formatter for formatting string queries for tests but my team was unsatisfied with how the formatter favored long lines. This adds some configurability to the width of the formatter.

I have some of the same failing tests locally as #1155 due to being on Elixir 1.13/OTP 24.

@line_width 120

def inspect(term, %{pretty: true}) do
def inspect(term, %{pretty: true, width: width}) do
Copy link
Contributor

Choose a reason for hiding this comment

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

This will only match if a width is passed as an opt right? Do you also need another clause that does not match on width?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we benefit here from the default Inspect.Opts.

term
|> render()
|> concat(line())
|> format(@line_width)
|> format(width)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this not be applied in the Absinthe.Language.Render module? You add the width to the Absinthe.Formatter but this is never passed on to the SDL.Render module.

There are two intermedate representations in Absinthe of schema/executable documents. The Language structs, which is the result of the lexer/parser. And the Blueprint structs, which is used to build schema's and execute them.

Both representations can be rendered to the graphql string representation. The Language representation can be converted to executable documents.
Blueprints can be converted back to the schema definition language.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I overlooked that. I'm happy to make the change wherever it makes the most sense to you 😄 .

Copy link
Contributor

Choose a reason for hiding this comment

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

|> format(@line_width)
this is probably what you're looking for.

@andersonmcook
Copy link
Contributor Author

I'd be interested in making multiple arguments more vertical as well, if the reviewers/maintainers were amenable.

e.g.

query SomeQuery(
  $abc: Boolean
  $def: String!
  $ghi: Int
) {
  someQuery(abc: $abc) {
    aField
    aFieldWithArgs(
      def: $def
      ghi: $ghi
    ) {
      anotherField
    }
  }
}

@maartenvanvliet
Copy link
Contributor

You'll need to fiddle with the Inspect Algebra representation, specifically the render_list function.

@andersonmcook
Copy link
Contributor Author

You'll need to fiddle with the Inspect Algebra representation, specifically the render_list function.

Maarten, I noticed your PR and it gave me inspiration 😄 . There will be an inevitable conflict, but have a look and let me know if this is an OK formatting style.

@benwilson512
Copy link
Contributor

Hi @andersonmcook I am open to merging this but there are now merge conflicts as you anticipated. Please reopen once those are fixed, thanks!

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.

4 participants