-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Descriptions as Strings in BuildFromDefinition #1167
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
Comments
👍 For adding it, but we shouldn't remove the old way yet. If anyone is depending on it, we want to give them a chance to update first. |
Yeah, I agree. We should be able to support both ways if my memory of that code is right. |
I'd take a stab at this, but seems Any ideas @rmosolgo? 🙇 |
So far, we only have the first part of block string support: we added it to But we need to use Parser-wise, what we need to do is:
Additionally, we need to update Does that clarify it a bit?
|
@rmosolgo Thanks for your reply! I was wondering if we could re-use the I'm not super familiar with ragel, but seems pretty straight forward. |
Personally, I would rather not reuse that that code because it's a bit of a hack. Comments are technically ignored tokens, so they're ignored by the parser entirely. However, since the first draft of the SDL said that comments could be used for description, we supported that (#305) with I think if we can implement descriptions at the parser level, we could simplify the code a bit. For example, if we picked up leading strings like: diff --git a/lib/graphql/language/parser.y b/lib/graphql/language/parser.y
index 071e57c5..65c6c9b9 100644
--- a/lib/graphql/language/parser.y
+++ b/lib/graphql/language/parser.y
@@ -295,9 +295,13 @@ rule
+ description_opt:
+ /* none */ { return nil }
+ | STRING
+
object_type_definition:
- TYPE name implements_opt directives_list_opt LCURLY field_definition_list RCURLY {
- return make_node(:ObjectTypeDefinition, name: val[1], interfaces: val[2], directives: val[3], fields: val[5], description: get_description(val[0]), position_source: val[0])
+ description_opt TYPE name implements_opt directives_list_opt LCURLY field_definition_list RCURLY {
+ return make_node(:ObjectTypeDefinition, name: val[2], interfaces: val[3], directives: val[4], fields: val[6], description: (val[0] || get_description(val[1])), position_source: val[0] || val[1])
} Then (after a period of backward compat), we could:
So, although it's a bigger change now, I think it sets us up for a bit simpler system down the road. That said, beggars can't be choosers: if you want to send a PR with the implementation you mentioned and a few tests, I'd happily accept it as a solid improvement, and then later, when we remove the comments-as-descriptions code, we can revisit those changes to the parser! |
@rmosolgo Thank you for your explanation! I tried to follow your instruction for We'll have to come back to this, so I don't want to hold things up if someone else gets to it first. My impression after this though, is that your original suggestion should work -- and we can keep compatibility with comment style descriptions. |
Huh, thanks for taking a stab at it! I took a little try with my pseudocode from above: In the test case added there, we never enter |
@rmosolgo Oh interesting, that is not far off from the patch I was working on. And the tests pass! How about for a single-line string? Such as: it "parses strings as type descriptions" do
defn_string = <<-GRAPHQL
"""Here's a description"""
type Thing { field: Stuff }
GRAPHQL
document = subject.parse(defn_string)
type_defn = document.definitions.first
assert_equal "Thing", type_defn.name
assert_equal "Here's a description", type_defn.description
end |
According to the spec, any string should be fair game. A type's description is a
and a
So, an example like the one you posted should be supported! |
Oh, maybe I misread, your example was a block string, but it didn't begin with a newline. This is also fair game, for example, here's a block string |
@rmosolgo That's exactly what I meant, using a block string for the description. Both seem at least included in the spec and other implementations I've come across. |
Hi, I'm helping to close out issues. From reading the discussion, it seems this is fully resolved when #1725 landed. I'm closing the issue, let me know if anyone likes to reopen it. |
Glad to see this land, nice work! 🎉 |
Uh oh!
There was an error while loading. Please reload this page.
I just stumbled upon this PR in
graphql-js
: graphql/graphql-js#927Before
Now
Implementing this depends on #1150.
Ref. Impl.:
Spec: graphql/graphql-spec#90
The text was updated successfully, but these errors were encountered: