Add "is kind" helper #69

Closed
josh opened this Issue Feb 2, 2017 · 4 comments

Projects

None yet

3 participants

@josh
Member
josh commented Feb 2, 2017 edited

Add a helper that can check object type, as well as interfaces.

Checking the exact type is already possible with typename

user.instance_of?(::User)
user.typename == "User"

But there is nothing like is_a or kind_of that can check the type hierarchy.

user.is_a?(::User)
user.is_a?(::Author)
@josh
Member
josh commented Feb 2, 2017

Looking for naming suggestions. I can't call it is_a or kind_of since those are Ruby builtins. Maybe type_of?

@josh
Member
josh commented Feb 2, 2017

CC @mclark

@mclark
mclark commented Feb 2, 2017

👍 for type_of?. It's consistent with the rest of the GraphQL vocabulary anyway.

@rmosolgo
rmosolgo commented Feb 2, 2017

Another option would be of_type?, personally that makes a bit more sense to me, eg

user.of_type?(User)
user.of_type?(Author)

At least for me, that's how I say it in plain talk, "object O is of type T"

@josh josh referenced this issue Feb 3, 2017
Merged

Add type_of? #70

@josh josh closed this in #70 Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment