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

schema printer adds unnecessary comma for arguments with description #667

Open
dariuszkuc opened this issue Sep 27, 2023 · 4 comments
Open
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation

Comments

@dariuszkuc
Copy link
Member

Description

Schema printer adds unnecessary comma for arguments with description. See repro below.

Steps to reproduce

#[test]
    fn arguments() {
        let mut foo = ObjectType {
            name: Name::new("Foo"),
            description: None,
            directives: vec![],
            fields: IndexMap::new(),
            implements_interfaces: IndexMap::new(),
        };
        foo.fields.insert(
            Name::new("bar"),
            Component::new(FieldDefinition {
                name: Name::new("bar"),
                description: None,
                directives: vec![],
                arguments: vec![Node::new(InputValueDefinition {
                    name: Name::new("arg"),
                    description: Some(NodeStr::new("foobar")),
                    // description: None,
                    directives: vec![],
                    ty: Type::Named(NodeStr::new("String")),
                    default_value: None,
                })],
                ty: Type::Named(NodeStr::new("String")),
            }),
        );

        let mut schema = Schema::new();
        schema
            .types
            .insert(Name::new("Foo"), ExtendedType::Object(Node::new(foo)));
        println!("{}", schema);
    }

Expected result

No comma after single argument with description

type Foo {
  bar(
    "foobar"
    arg: String
  ): String
}

Actual result

Extra comma after single argument

type Foo {
  bar(
    "foobar"
    arg: String,
  ): String
}

Environment

  • Operating system and version: MacOS Ventura
  • Shell (bash/zsh/powershell): zsh
  • apollo-rs crate: mut branch
  • Crate version: 1.72.0
@dariuszkuc dariuszkuc added bug Something isn't working triage labels Sep 27, 2023
@goto-bus-stop
Copy link
Member

All multi-line lists get a trailing comma, and description forces an argument decl list to be multi-line. So this is definitely intentional, though perhaps it could be configurable in the future.

@goto-bus-stop goto-bus-stop added apollo-compiler issues/PRs pertaining to semantic analysis & validation and removed bug Something isn't working triage labels Nov 1, 2023
@SimonSapin
Copy link
Contributor

I confirm this was intentional, but it’s a stylistic choice that we can change. I’m not sure it’s worth configuration. It could be a heuristic based on the presence of descriptions (on the argument before and/or after the potential comma)

@lrlna
Copy link
Member

lrlna commented Nov 3, 2023

Do we do what graphql-js does? I think with printing we should just stick to their format

@SimonSapin
Copy link
Contributor

Looking for ', ' in https://github.com/graphql/graphql-js/blob/main/src/language/printer.ts seems like the best we have, to find out where graphql-js uses commas.

In at least one place it chooses either commas OR newlines:

      let argsLine = prefix + wrap('(', join(args, ', '), ')');

      if (argsLine.length > MAX_LINE_LENGTH) {
        argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
      }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-compiler issues/PRs pertaining to semantic analysis & validation
Projects
None yet
Development

No branches or pull requests

4 participants