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

Strange formatting of input types with descriptions #287

Closed
nightroman opened this issue Jan 21, 2023 · 16 comments · Fixed by #304
Closed

Strange formatting of input types with descriptions #287

nightroman opened this issue Jan 21, 2023 · 16 comments · Fixed by #304
Labels
bug Something isn't working

Comments

@nightroman
Copy link

If an input type has field descriptions then formatting produces unexpected extra new lines and extra indentation of fields.

Please find attached the project for reproducing the issue.
TryGraphQLParser.zip

Test1

No issues for type types:

dotnet run -- x1-type.graphql
  • input x1-type.graphql contains a type with fields with descriptions.
  • output x1-type.graphql.output.graphql is formatted as expected.

Test2

Formatting issues with input with descriptions:

dotnet run -- x2-input.graphql
  • input x2-input.graphql contains an input with fields with descriptions.
  • output x2-input.graphql.output.graphql shows unexpected new lines and extra indentations.

Test3

No issues with input without descriptions:

dotnet run -- x3-input.graphql
  • input x3-input.graphql contains an input with no descriptions.
  • output x3-input.graphql.output.graphql is formatted as expected.
@nightroman nightroman added the bug Something isn't working label Jan 21, 2023
@nightroman
Copy link
Author

Example input:

"A component contains the parametric details of a PCB part."
input DesComponentFilterInput {
    and: [DesComponentFilterInput!]
    or: [DesComponentFilterInput!]
    "The library label for this component."
    name: StringOperationFilterInput
    "The additional information for this component."
    comment: StringOperationFilterInput
    "The summary of function or other performance details for this component."
    description: StringOperationFilterInput
    "The component revision."
    revision: DesRevisionFilterInput
}

Example result with unexpected new lines and indentations:

"A component contains the parametric details of a PCB part."
input DesComponentFilterInput {
  and: [DesComponentFilterInput!]
  or: [DesComponentFilterInput!]

  "The library label for this component."
    name: StringOperationFilterInput

  "The additional information for this component."
    comment: StringOperationFilterInput

  "The summary of function or other performance details for this component."
    description: StringOperationFilterInput

  "The component revision."
    revision: DesRevisionFilterInput
}

@sungam3r
Copy link
Member

Indeed, I struggled with indentation (both horizontal and vertical) a lot when I rewrote the parser a long time ago. I will try to look at this problem today, but for now I am away from my home PC.

@sungam3r
Copy link
Member

OK. I reproduced this and I have an idea how to fix this. It requires some internal redesign of AST printing.

@nightroman
Copy link
Author

@sungam3r Any progress? No pressure, just wondering when to expect the improvement, approximately.

@sungam3r
Copy link
Member

sungam3r commented Mar 1, 2023

Nope. I can’t say when it will be ready. I remember this task. Recently I have been littered with household chores.

@sungam3r
Copy link
Member

I want to return to this task in the near future after I finish the adjacent changes in v8.2/v8.3.

@sungam3r
Copy link
Member

In process. There is some progress. I need to delicately tune practically each method of parser.

@nightroman
Copy link
Author

@sungam3r Thank you for the good news, cannot wait to try it out!

@sungam3r
Copy link
Member

Fixed in #304 but I'm sure there are more issues to fix internally.

@nightroman
Copy link
Author

@sungam3r Thank you! Will the nuget package be updated soon?

@sungam3r
Copy link
Member

Today or tomorrow.

@sungam3r
Copy link
Member

@nightroman
Copy link
Author

@sungam3r Thank you.
Input type formatting is fixed, great!

There is a regression though (I think).
We lost indentation of field/query parameters in object types.

Example before (normal indentation)

type Query {
  "Fetches an object given its ID."
  node(
    "ID of the object."
    id: ID!): Node
  "Lookup nodes by a list of IDs."
  nodes(
    "The list of node IDs."
    ids: [ID!]!): [Node]!
  "Search for workspaces associated with this account."
  desWorkspaces(where: DesWorkspaceFilterInput): [DesWorkspace!]!
  "Search a specific workspace by its unique identifier."
  desWorkspaceById(
    "The node identifier for a workspace."
    id: ID!): DesWorkspace

Example now (no indentation)

type Query {
  "Fetches an object given its ID."
  node(
  "ID of the object."
  id: ID!): Node
  "Lookup nodes by a list of IDs."
  nodes(
  "The list of node IDs."
  ids: [ID!]!): [Node]!
  "Search for workspaces associated with this account."
  desWorkspaces(where: DesWorkspaceFilterInput): [DesWorkspace!]!
  "Search a specific workspace by its unique identifier."
  desWorkspaceById(
  "The node identifier for a workspace."
  id: ID!): DesWorkspace

Should I submit another issue or this comment is enough for an action?

@sungam3r
Copy link
Member

Submit, please, in parser repo.

@sungam3r
Copy link
Member

With new design of indentation it should not take much time to fix.

@nightroman
Copy link
Author

Here is the new issue -- #311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants