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

Add support for description parsing #132

Merged
merged 4 commits into from
Jul 7, 2021
Merged

Add support for description parsing #132

merged 4 commits into from
Jul 7, 2021

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Jun 28, 2021

Adds support for description parsing according to spec. Requires #131 to be merged in order for tests to pass.

Note in the case where there is a comment both before and after the description, such as in the example below, the second comment is attached to the type definition, and the first comment is added to the list of unattached comments. If a comment only in one of the two locations, then it is attached to the type definition. This mechanic is covered by the tests.

# comment 1
"""
This is my custom scalar
"""
# comment 2
scalar MyScalar

Description fields have been added only to the nodes that allow a description. Since typical GraphQL queries and mutations cannot contain any nodes that would have a description field, and therefor no additional memory could be allocated, there is no need for an additional option to skip parsing of descriptions.

@Shane32 Shane32 self-assigned this Jun 28, 2021
@github-actions github-actions bot added the test Pull request that adds new or changes existing tests label Jun 28, 2021
@Shane32 Shane32 requested a review from sungam3r June 28, 2021 18:42
@Shane32 Shane32 added enhancement New feature or request and removed test Pull request that adds new or changes existing tests labels Jun 28, 2021
@github-actions github-actions bot added the test Pull request that adds new or changes existing tests label Jul 6, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #132 (68344cb) into master (69342d5) will increase coverage by 0.52%.
The diff coverage is 94.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #132      +/-   ##
==========================================
+ Coverage   92.06%   92.58%   +0.52%     
==========================================
  Files          48       49       +1     
  Lines        2193     2320     +127     
  Branches      251      273      +22     
==========================================
+ Hits         2019     2148     +129     
+ Misses        147      145       -2     
  Partials       27       27              
Impacted Files Coverage Δ
...rc/GraphQLParser/AST/GraphQLDirectiveDefinition.cs 75.00% <ø> (+12.50%) ⬆️
src/GraphQLParser/AST/GraphQLEnumTypeDefinition.cs 85.71% <ø> (ø)
...rc/GraphQLParser/AST/GraphQLEnumValueDefinition.cs 66.66% <ø> (ø)
src/GraphQLParser/AST/GraphQLFieldDefinition.cs 75.00% <ø> (ø)
...phQLParser/AST/GraphQLInputObjectTypeDefinition.cs 85.71% <ø> (ø)
...c/GraphQLParser/AST/GraphQLInputValueDefinition.cs 75.00% <ø> (ø)
...raphQLParser/AST/GraphQLInterfaceTypeDefinition.cs 85.71% <ø> (+14.28%) ⬆️
...c/GraphQLParser/AST/GraphQLObjectTypeDefinition.cs 87.50% <ø> (+12.50%) ⬆️
...c/GraphQLParser/AST/GraphQLScalarTypeDefinition.cs 66.66% <ø> (+16.66%) ⬆️
...rc/GraphQLParser/AST/GraphQLUnionTypeDefinition.cs 71.42% <ø> (+14.28%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69342d5...68344cb. Read the comment docs.

@Shane32
Copy link
Member Author

Shane32 commented Jul 6, 2021

I have incorporated ideas from #70 into this PR. If there are no comments I will merge this PR.

@sungam3r
Copy link
Member

sungam3r commented Nov 5, 2021

@Shane32 I begin to review this PR but I already suspect what it will affect:
изображение
I believe that this code was to be changed to take new Description syntax node into account, right?

@Shane32
Copy link
Member Author

Shane32 commented Nov 5, 2021

I can't remember exactly, but I think I made changes that would be both non-breaking (i.e. support comments as descriptions) and also support the spec (i.e. support strings/blockstrings as descriptions). Precedence is to spec - a string/blockstring is a description. If no string/blockstring, then resort to old non-spec behavior.

Per spec, I believe comments should be completely ignored. Perhaps we change that in v5.

@@ -0,0 +1,9 @@
namespace GraphQLParser.AST
{
public class GraphQLDescription : ASTNode
Copy link
Member

Choose a reason for hiding this comment

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

@Shane32 Where is Location for GraphQLDescription syntax node ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I didn't put one in because the syntax for the parent node technically includes the description, and so the start of the description is the same as the start of the type definition node. At least that's maybe why I did it??? It's been 4 months so I can't remember my reasoning exactly.

Maybe it should be in there anyway though, so that there's a way to determine the end of the description node? I guess that would be a new class called GraphQLDescriptionFull ... ??

Copy link
Member

Choose a reason for hiding this comment

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

the syntax for the parent node technically includes the description, and so the start of the description is the same as the start of the type definition node.

Nope. Those are different syntax nodes with different locations. GraphQLComment node has Location for example.

I guess that would be a new class called GraphQLDescriptionFull

Yep. Maybe new, maybe existing. I should remember why I did only one GraphQLComment class without GraphQLCommentFull counterpart. I have already started review, so I can do all the necessary edits myself.

Copy link
Member Author

Choose a reason for hiding this comment

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

image

Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty sure the library is already written this way -- to match the spec. So a type definition node will have its Location start and end points exactly as described by the spec and shown above.

I don't see any reason why a description node can't have a Location also

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no added complexity. It is not complex. It is not difficult to write. In fact you simply don’t need to remove optimized functionality that already exists in the library. I do not see any reason to take something optimized and unoptimize it. It does not make sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

The current implementation adds a couple lines of code to the entire library. As in like simply 2-3 lines of code. That is not complex. It is not harder to read. There is no reason to deoptimize the library for the sake of 2 lines of code.

Copy link
Member

Choose a reason for hiding this comment

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

I will think. There is a small chance that schema extensions can also have descriptions (although it is unlikely) - graphql/graphql-spec#900

Copy link
Member

Choose a reason for hiding this comment

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

Well, everything turned out to be simple and difficult at the same time. See http://spec.graphql.org/October2021/#sec-Type-Extensions or even more old http://spec.graphql.org/June2018/#sec-Type-Extensions :
изображение

Now parser supports (partially) only ObjectTypeExtension. Wow! :) No support for other extensions at all, no tests. The good news is that Description property will not exist on GraphQLTypeExtensionDefinition when it stops inherit from GraphQLTypeDefinition. All extensions should have a separate new base class. Also we should add a bunch of new classes to cover each kind of extension. Looks like a good feature for v8. So I suggest to merge this as is (after your review of course) and continue to work on separate issue - #143.

Copy link
Member

Choose a reason for hiding this comment

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

@sungam3r
Copy link
Member

sungam3r commented Nov 5, 2021

Yep, I see
изображение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request test Pull request that adds new or changes existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants