Closed ivanbrennan closed 2 years ago
Hi, great question. Yes, in GraphQL-Ruby 2.0, all types will be classes -- GraphQL::ObjectType
will be completely removed.
Likewise, GraphQL::Relay::GlobalIdResolve
will also be removed; instead, global_id_field
will call .id_from_object
directly. Here's the implementation that's currently only the 2.0-dev branch:
I hope that helps -- let me know if there's anything else I can help with while you consider that migration!
I hope that helps -- let me know if there's anything else I can help with while you consider that migration!
@rmosolgo That's very helpful, thanks for clarifying :+1:
I had one followup question: will it still be possible to call .graphql_name
on a type class (e.g. Types::SongType.graphql_name
) to determine its name in the client-facing schema? But since you mentioned the 2.0-dev branch (which I wasn't previously aware of), I took a look at that and it looks like .graphql_name
is still available, so I guess that answers my question :)
Thanks again for all your work!
.graphql_name
on a type class
Yep! (In fact, .graphql_name
was added specifically for classes: since .name
returns the Ruby class name, I needed some other method for the GraphQL type name.)
I have a few pieces of code that manually call
.id_from_object
to calculate a Relay-style node ID, so they need to determine the appropriatetype
to pass into the call,to ensure they're consistent with the behavior of
GraphQL::Relay::GlobalIdResolve
.Due to the way Relay node IDs are currently calculated,
my code does the following:
My assumption is that when
.graphql_definition
objects are removed (in GraphQL-Ruby 2.0), the code inGraphQL::Relay::GlobalIdResolve
will start passing the class that describes the type, rather than passing an instance ofGraphQL::ObjectType
. Is that the case?For example, say
obj
is an instance of an ActiveRecord modelSong
,@type
is the classTypes::SongType
, and@type.graphql_definition
is an instance ofGraphQL::ObjectType
displayed asSong
. Once.graphql_definition
objects are removed, can I expect.id_from_object
to receiveTypes::SongType
(the class itself, not an instance of it) as it's second argument (type
)?