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

Fix bug in AstPrinter preventing query short form from being used #2799

Merged
merged 1 commit into from May 17, 2022

Conversation

kilink
Copy link
Contributor

@kilink kilink commented Apr 16, 2022

AstPrinter's operationDefinition method had a String comparison that would
always fail when checking the node's operation; the String contained in
the op variable was already lowercased, while the constant "QUERY" was
used in the comparison. The result was that query short form was
never used when printing queries.

AstPrinter's operationDefinition method had a String comparison that would
always fail when checking the node's operation; the String contained in
the op variable was already lowercased, while the constant "QUERY" was
used in the comparison. The result was that query short form was
never used when printing queries.
@@ -199,7 +199,7 @@ scalar DateTime
String output = printAst(document)

expect:
output == """query {
output == """{
empireHero: hero(episode: EMPIRE) {
name
}
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure we want this behavior. I get that that printAstCompact might lead to { f } if there is no args etc.. (is more compact) but the normal printAst probably should use the slightly longer for.

@andimarek what are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

This was ported from graphql.js originally so in a sense could do what they do

And they do this

src/language/printer.js

  OperationDefinition(node) {
    const op = node.operation;
    const name = node.name;
    const varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
    const directives = join(node.directives, ' ');
    const selectionSet = node.selectionSet;
    // Anonymous queries with no directives or variable definitions can use
    // the query short form.
    return !name && !directives && !varDefs && op === 'query'
      ? selectionSet
      : join([op, join([name, varDefs]), directives, selectionSet], ' ');
  },

Copy link
Member

Choose a reason for hiding this comment

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

which is inline with what this PR does

Copy link

@luiznaac luiznaac Aug 1, 2022

Choose a reason for hiding this comment

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

@bbakerman I recently updated to the newest release (19.0) and found out that a test of mine was failing due to this modification. There's no parameter which we could pass nor a specific function we could call to get this behavior. IMHO, it's misleading to just assume the client wants the query in short form just because there're no names, vars nor directives.... shouldn't we introduce a more explicit way to achieve it?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot @luiznaac for calling this out. We discussed this and decided that this is a change we want to make, but we didn't document this explicitly in the release notes. I just updated them to make this clear.

We also discussed introducing an option, but we decided against it as it is semantically the same.

@andimarek andimarek added this to the 19.0 milestone Apr 26, 2022
@dondonz dondonz merged commit 271879b into graphql-java:master May 17, 2022
@Stuckya Stuckya mentioned this pull request Sep 13, 2022
9 tasks
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.

None yet

5 participants