-
Notifications
You must be signed in to change notification settings - Fork 43
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
Descriptions/Comments/Locations rework #142
Conversation
Codecov Report
@@ Coverage Diff @@
## master #142 +/- ##
==========================================
- Coverage 92.66% 91.90% -0.76%
==========================================
Files 49 50 +1
Lines 2317 2496 +179
Branches 273 278 +5
==========================================
+ Hits 2147 2294 +147
- Misses 143 180 +37
+ Partials 27 22 -5
Continue to review full report at Codecov.
|
Note that GraphQLLocation is a struct, and takes almost no processing power to compute (since the location is already known). So if there are no optimized classes for skipping only locations, then running the parser with only I also think (if I remember right) that if an error occurs during parsing, an exception is generated within the parser that utilizes the location of the error, even if location is specified to be ignored when parsing. So while flags are a better design, it may be a bit misleading to users in that ignoring locations (but not comments) will actually do anything beneficial. Just because of that reason, I'd probably keep the options values like they were, especially as we have no intention of adding additional flags or adding additional classes to options for ignoring only locations. Assume that we proceed with switching it to flags, I might add a comment to this effect - either in the xml comment for the enum option, or in the readme file. |
bac16f6
to
03dd0b4
Compare
I did so that every option gave effect. I have to write tests and put some code for reading comments in 3-4 places. When I worked on this PR, I realized that the processing of comments is a very unpleasant process. They may be everywhere! We are far from properly handling comment. I found that if you put a comment after the name of the arg but before its value, the parser generates an exception. Boom! See |
internal static class NodeHelper | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static GraphQLComment CreateGraphQLComment(IgnoreOptions options) |
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.
First three methods differ from others. GraphQLComment
, GraphQLDocument
and GraphQLDescription
have no comments. All other methods are completely the same. Perhaps when I will write tests, I will see that comments are not applicable to some other AST nodes.
Why not just discard all comments (according to spec) for v8? Eliminate the options for parsing it, eliminate the complexity of the classes to hold comments, etc.
Just an idea... |
I really think you are wasting a lot of time here, and making the project unnecessarily complex with "a lot of new internal classes" that are not necessary when the only project that uses this parser -- GraphQL.NET -- only does two things: (a) skip comments for execution, and (b) load comments for backwards compatibility when creating a schema-first schema. And as for the second point, descriptions have long been in the spec now to be done by strings, not comments. So even that is not necessary for GraphQL.NET v5. |
(Edit: oops GraphQL always uses locations) We should really eliminate optimization of parsing without locations, since GraphQL requires the use of locations in error messages. |
Of course, we can do it. But from the point of view of the syntactic parsing it will be a step back. People may need comments on completely different reasons. The most obvious of them is the documentation provision through the introspection. We will force everyone to use descriptions. At best, consumers will have to change their SDLs. In the worst case, they will not be able to do this at all, because they do not own these schemas. Then they have to change these schemas (SDL) dynamically, which will require ... the syntactic analysis that we have deleted 😄 . |
I'm not sure that this requirement somehow limits us. The specification describes what should occur between the client and the server. Parser is a general mechanism that can work without the presence of any client. For example, it may be the transformation from one SDL to another SDL or to some different file format. Getting SDL statistics, whatever. |
None of those scenarios require memory optimization. Only execution does, which requires location information. |
Why so 😄 ? It is better to say "the only public project that uses this parser" although I doubt even that it is indeed the only public. I use the parser in my private projects for example. In any case, we need to eliminate exceptions caused by the placing comments in "unexpected" positions. |
You can write all that extra code if you want; I wouldn't 🤷♂️. |
For sure. |
Where (a) you skip parsing location information, and (b) in situations that require hyper-optimized memory allocations? |
Hey, go ahead 👍 ... maybe it's useful to someone; maybe you. |
OK. By the way, if we talk about the complexity of the code, then after the changes made code became easier. I deleted all the ternary operators around AST creation and initializing. All properties are set once now. The number of codes in the "main" parser file decreased. I look positively on changes. |
Is it ready for another review? |
Not yet. I'll let you know. |
@Shane32 I'm ready for review. It turned out to be a big one PR. What you should pay attention to:
I also walked through all the |
Now it will be easier to work on the new features from the October spec. |
See #132 as a starting point. Fixes #141. Also now parser respects ignore-locations option for comments. Also fixes exceptions caused by placing comments in "unexpected" positions in query/SDL.