Skip to content

Add support for leading vertical bar in union types #907

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 3 commits into from
Jun 13, 2017

Conversation

alexandrebodin
Copy link
Contributor

Implementation of the leading vertical bar in the language parser.

Issue #897

Copy link
Contributor

@robzhu robzhu left a comment

Choose a reason for hiding this comment

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

Looks great! See inline for a question and some suggested additional test cases.

@@ -83,6 +83,8 @@ union Feed = Story | Article | Advert

union AnnotatedUnion @onUnion = A | B

union AnnotatedUnionTwo @onUnion = A | B
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intend to have | A | B?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope the printer will only print without it or with it I think it's better to leave it out and add it with prettier for ex

};
expect(printJson(doc)).to.equal(printJson(expected));
});

Copy link
Contributor

@robzhu robzhu Jun 13, 2017

Choose a reason for hiding this comment

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

Can you please also add test cases for | Wo | Rld |, union Hello = Wo | Rld |, Wo || Rld and union Hello = |?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

@alexandrebodin
Copy link
Contributor Author

@robzhu I added severals news tests

@robzhu
Copy link
Contributor

robzhu commented Jun 13, 2017

@alexandrebodin, thank you for the high quality PR and fast turnaround!

@robzhu robzhu merged commit 3aa2a73 into graphql:master Jun 13, 2017
@@ -943,6 +943,9 @@ function parseUnionTypeDefinition(lexer: Lexer<*>): UnionTypeDefinitionNode {
*/
function parseUnionMembers(lexer: Lexer<*>): Array<NamedTypeNode> {
const members = [];
if (peek(lexer, TokenKind.PIPE)) {
skip(lexer, TokenKind.PIPE);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The wrapping peek is unnecessary. skip is effectively a call to peek.

@@ -943,6 +943,9 @@ function parseUnionTypeDefinition(lexer: Lexer<*>): UnionTypeDefinitionNode {
*/
function parseUnionMembers(lexer: Lexer<*>): Array<NamedTypeNode> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Every method in the parser has parse language atop it. It would be nice to include this here as well

@leebyron
Copy link
Contributor

This is not the only place in the IDL where bar-separated tokens exists. Should we remain consistent and update the others as well? Or would that not be fitting?

@alexandrebodin
Copy link
Contributor Author

@leebyron I could update the other places if you can point them to me.

@leebyron
Copy link
Contributor

Let me take a quick look

leebyron added a commit that referenced this pull request Jun 14, 2017
This adds a bit of cleanup after #907 for post-commit review:

* Removes unnecessary `peek()`
* Adds leading pipe support to directive locations
* Removes some redundant tests
* Orders tests so similar tests remain together
@leebyron leebyron mentioned this pull request Jun 14, 2017
leebyron added a commit that referenced this pull request Jun 14, 2017
This adds a bit of cleanup after #907 for post-commit review:

* Removes unnecessary `peek()`
* Adds leading pipe support to directive locations
* Removes some redundant tests
* Orders tests so similar tests remain together
leebyron added a commit that referenced this pull request Jun 14, 2017
This adds a bit of cleanup after #907 for post-commit review:

* Removes unnecessary `peek()`
* Adds leading pipe support to directive locations
* Removes some redundant tests
* Orders tests so similar tests remain together
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