-
Notifications
You must be signed in to change notification settings - Fork 529
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
Configure formatter width #1156
Conversation
@line_width 120 | ||
|
||
def inspect(term, %{pretty: true}) do | ||
def inspect(term, %{pretty: true, width: width}) do |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absinthe/lib/absinthe/language/render.ex
Line 12 in 102360e
|> format(@line_width) |
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
}
}
} |
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. |
Hi @andersonmcook I am open to merging this but there are now merge conflicts as you anticipated. Please reopen once those are fixed, thanks! |
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.