Skip to content

AstPrinter: Empty types should not include braces {} #3619

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

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

tinnou
Copy link
Contributor

@tinnou tinnou commented Jun 5, 2024

Description

In the latest version of the spec, empty types (input objects, object types) must be represented without curly braces, i.e the following is valid:

type Query 
# below only here to make the sdl valid 
extend type Query {
  foo: String
}

while the following technically isn't (note the {}):

type Query {}
# below only here to make the sdl valid 
extend type Query {
  foo: String
}

Because of historical reasons, graphql-java supports parsing of both syntaxes. However its AstPrinter prints the spec invalid form. While this is ok in systems where graphql-java's GraphQL parser is the only one in use, it fails in poly-parser systems where stricter (albeit spec-compliant) parsers might fail to parse graphql-java printed SDL output.

Approach

This PR updates the AstPrinter to be spec-compliant, i.e serialize empty types, empty selection sets (although should never happen) without the {}.

Follow ups

If there is interest, I can follow up with another PR that (while breaking backwards-compatibilty) will make the parser spec compliant as well, i.e only allow the form without braces {}.

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Great to see you contributing again :)

@tinnou
Copy link
Contributor Author

tinnou commented Jun 6, 2024

Great to see you contributing again :)

🙏 but really it's all you and the other core contributors that keep this library in tip-top shape!
@dondonz @andimarek 🤟

Copy link
Member

@dondonz dondonz left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@dondonz dondonz added this pull request to the merge queue Jun 11, 2024
Merged via the queue into graphql-java:master with commit 5ff0027 Jun 11, 2024
1 check passed
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.

3 participants