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
Add stripIgnoredTokens feature to remove insignificant whitespace #1628
Conversation
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! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@IvanGoncharov can you review this one? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
@rybon Thanks for PR 👍 and Happy New Year 🎄 Thanks a lot for writting bunch of test cases. Proposed functionality doesn't work with AST so I don't see any benefits in having it as part of const schema = buildClientSchema(introspection);
let sdl = printSchema(schema);
const ast = parse(sdl);
sdl = print(ast, { condense: true }); I think we should make 'condense' a standalone function inside RegExp are good for PoC but it's a big maintainance problem in the future. {
compile(jsCode: "function () { console.log('Valid JS code inside GraphQL string'); }")
} You just can't handle such use cases with RegExp and should use lexer to correctly implement this functionality: graphql-js/src/language/__tests__/lexer-test.js Lines 726 to 740 in fc3e2e3
Last issue for me is the name, I understand why you can't call it @rybon What do you think? |
@IvanGoncharov Happy New Year to you too :-). Thanks for the review. I've put this feature in the I agree that RegExp is kinda hacky and not an ideal solution. There are indeed a number of edge cases that are very hard to catch with this approach. And if the GraphQL spec expands, one would need to expand the RegExp as well. I don't have any experience with ASTs and lexers, so I don't know how to implement this feature with that approach instead. But I'm willing to try it out. Would you (or anyone else) be willing to help me get started on this? I'm not really attached to the name |
@rybon Sorry, I accidentally screw this PR trying to add commit on top of it.
I implemented it here: be79c4e |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@rybon I tested it based on your example: const {
stripIgnoredTokens
} = require('./dist/utilities/stripignoredtokens');
const result = stripIgnoredTokens(`
query SomeQuery($foo: String!, $bar: String) {
someField(foo: $foo, bar: $bar) {
a
b {
c
d
}
}
}
`);
console.log(result);
// query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}} |
Looks good. I'll revert the changes in |
@rybon Great 👍 |
@IvanGoncharov done. I've added tests for the Query document and SDL document. |
I like this idea, really. But code coverage should be increased — especially new features should be deeply tested. BTW can this be implemented for AST too? — like I always have AST (processed, validated, etc) when I wish write it down for next tooling. |
@langpavel OK fair enough. But keep in mind that I'm not very familiar with this codebase, so I would need some help to get that done. Could you help me out? |
@rybon I think that all you need is altered copy of src/language/printer.js |
That is where the implementation was originally done (see earlier commits). What needs to be done in that copy? |
@rybon Ok, I see first commit. BTW I like latest tiny implementation. But having only AST version make more sense to me. @IvanGoncharov What do you think? |
The RegExp implementation was done because I wasn't aware of an alternative approach at the time. I didn't decrease coverage on purpose, but I see it decreased by 0.007%. Are we striving for 100% coverage in this project? If so, how do we achieve that (have every single line covered)? OK, I can rewrite these functions, but they would have to be parameterized to deal with this use case. What should the implementation be in that case? I have no experience with ASTs. |
@rybon let's wait for @IvanGoncharov.
Better way is create new You can learn about AST here: astexplorer.net |
@rybon Situation is like this I agree with the current implementation. The real problem here is that The idea here is that it simply not enough to use tests for I'm fully supporting this functionality but currently I need to finish a couple of other long standing issues with this lib. I can promise that we will include it in upcoming |
OK understood. I was testing it from the perspective of an end user, in this case an app developer who just wants to cut down on the size of GraphQL strings in an app bundle or over the wire. In that case the implementation details (the call stack that gets invoked) don't matter that much, only the end result does. |
First is public API, second expected behavior. None of both is implementation detail test. |
Codecov Report
@@ Coverage Diff @@
## master #1628 +/- ##
========================================
Coverage ? 98.6%
========================================
Files ? 216
Lines ? 13368
Branches ? 1971
========================================
Hits ? 13181
Misses ? 187
Partials ? 0
Continue to review full report at Codecov.
|
@langpavel done. Only line I can't seem to get covered is the |
@IvanGoncharov anything else that needs to be done for this PR to land? |
@rybon Sorry for the delay. I totally understand that adding this feature taking too much time so I stoped development of all other features until I merge this one. I'm working on it in my free time but I expect it will take a couple days at most. P.S. I need to rebase some commit and also add new ones so to prevent stupid situation with github (like what I did with Lexer commit) I will open separate PR. |
Heavily based on work done by @rybon in graphql#1628. Solves graphql#1523.
Just saw your PR (#1802). Great work! Thank you for your efforts, I really appreciate it. |
Heavily based on work done by @rybon in graphql#1628. Solves graphql#1523.
Heavily based on work done by @rybon in graphql#1628. Solves graphql#1523.
Heavily based on work done by @rybon in graphql#1628. Solves graphql#1523.
Heavily based on work done by @rybon in graphql#1628. Solves graphql#1523.
Solves #1523.