-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Document !type
better or consider dropping it?
#1048
Comments
@burlesona, I assume the answer is because, as this is a library for working with graphql, much of the syntax and design is inspired by the graphql spec rather than ruby. Graphql-ruby's As someone who found graphql-ruby after finding graphql, graphql-ruby's use of This being said, I know the current dsl is something |
👍 thanks for opening an issue, it's also a source of heartburn for me, because in other code, I write I think we'll use |
This was also very confusing for me, learning this library for the first time. Everywhere else in almost all programming languages I've seen, a bang before a statement negates it. At the very least, it should be documented very clearly towards the beginning of documentation and guides. |
The new class-based API will use https://github.com/rmosolgo/graphql-ruby/blob/1.8-dev/guides/schema/class_based_api.md |
Fortran, man. Anyway, I know doesn't matter anymore, but I figured I'd point out that you can move the unary operators to the back by calling them as methods. Woulda looked more like the query language and less like Ruby boolean logic. class Type
def initialize(**config)
@config = { required: false, **config }
end
def !
self.class.new **@config, required: true
end
Int = new name: 'Int'
end
Type::Int # => #<Type:0x00007fcfe30368e8 @config={:required=>false, :name=>"Int"}>
Type::Int.! # => #<Type:0x00007fcfe30345c0 @config={:required=>true, :name=>"Int"}> |
Just some food for thought:
graphql-ruby/lib/graphql/define/non_null_with_bang.rb
Line 11 in 741f269
which leads to:
I'm new to GraphQL Ruby, but have been developing in Ruby for almost ten years now. I've never seen the unary
!
operator overloaded like this, and it jumped out at me on the project home page enough that I had to dive into the source code to figure out what the heck it did, finally discovering it just calls#to_non_null_type
.That's extremely surprising behavior. To me it seems like unnecessary syntax sugar that actually obfuscates the code rather than make it more readable.
It's not my library so I offer the following with no expectation that you'll want to make the change, but if I were maintaining this I'd drop the unary and adopt one of the following changes:
First preference, just shorten
#to_non_null_type
as#non_null
and invoke it like:That's nice and short and it works exactly the way the code works now, while being extremely clear and readable.
Alternatively, if there are lots of these methods and invoking them as such feels clunky to you, or you don't want the hassle of making them chainable, you could add factory methods such that you can call the constant (subscript or parens depending on how you prefer to implement it).
or
Any of the above and I wouldn't have so much as raised an eyebrow going through the docs for GraphQL Ruby.
Again, I know it's not my code and I don't mean to come in and raise a fuss, just wanted to offer you some feedback which I hope you find constructive food for thought. If not, feel free to ignore :)
Meanwhile, thanks for writing a great OSS lib, I'll be off learning how the rest of it works 👍
The text was updated successfully, but these errors were encountered: