Skip to content

Conversation

sullvn
Copy link

@sullvn sullvn commented Oct 6, 2018

I encountered a runtime type error while printing some hand-constructed FieldDefinition AST nodes which conform to the type spec.

Problem

Type spec - declaring it's optional:

+arguments?: $ReadOnlyArray<InputValueDefinitionNode>,

Printing implementation - requiring it:

(args.every(arg => arg.indexOf('\n') === -1)

Solution

This PR fixes this discrepancy in the implementation with a default value.

https://github.com/awfulaxolotl/graphql-js/blob/df56ba3eadbfbc282ae6262927dfaeb162662158/src/language/printer.js#L139

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@IvanGoncharov IvanGoncharov requested a review from mjmahone October 9, 2018 15:05
@IvanGoncharov
Copy link
Member

@awfulaxolotl Sorry for the delay.
I reviewed our printer implementation and found another place with an exact same problem.
So I extracted code in question into hasMultilineItem function and reuse it in both places.
I pushed my changes on top of your PR and it would be great if you have time to review it.

@mjmahone Can you please review?

@IvanGoncharov IvanGoncharov added this to the v14.1.0 milestone Oct 9, 2018
@IvanGoncharov
Copy link
Member

@mjmahone General issue here is that printer.js is not covered by Flow but I will try to address this in the separate PR.

@sullvn
Copy link
Author

sullvn commented Oct 9, 2018

@IvanGoncharov Nice catch. Your extended fix looks good to me! Looking forward to printer.js being covered with Flow.

@IvanGoncharov
Copy link
Member

@mjmahone Can you please review?

Copy link
Contributor

@mjmahone mjmahone left a comment

Choose a reason for hiding this comment

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

Thanks you for finding and fixing this bug! Sorry for my review delay, but @IvanGoncharov seems to have helped move this fix along well. Thank you both!

@mjmahone mjmahone merged commit 6a69bbb into graphql:master Nov 4, 2018
adek05 pushed a commit to adek05/graphql-js that referenced this pull request Nov 5, 2018
…ts` field (graphql#1548)

* Fix error when printing a `FieldDefinition` AST node without arguments

* Generalize solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants