Class: Tapioca::Dsl::Helpers::GraphqlTypeHelper
- Inherits:
-
Object
- Object
- Tapioca::Dsl::Helpers::GraphqlTypeHelper
- Extended by:
- T::Sig
- Includes:
- RBIHelper, Runtime::Reflection
- Defined in:
- lib/tapioca/dsl/helpers/graphql_type_helper.rb
Constant Summary
Constants included from Runtime::Reflection
Runtime::Reflection::ANCESTORS_METHOD, Runtime::Reflection::CLASS_METHOD, Runtime::Reflection::CONSTANTS_METHOD, Runtime::Reflection::EQUAL_METHOD, Runtime::Reflection::METHOD_METHOD, Runtime::Reflection::NAME_METHOD, Runtime::Reflection::OBJECT_ID_METHOD, Runtime::Reflection::PRIVATE_INSTANCE_METHODS_METHOD, Runtime::Reflection::PROTECTED_INSTANCE_METHODS_METHOD, Runtime::Reflection::PUBLIC_INSTANCE_METHODS_METHOD, Runtime::Reflection::REQUIRED_FROM_LABELS, Runtime::Reflection::SINGLETON_CLASS_METHOD, Runtime::Reflection::SUPERCLASS_METHOD
Constants included from SorbetHelper
SorbetHelper::FEATURE_REQUIREMENTS, SorbetHelper::SORBET_BIN, SorbetHelper::SORBET_EXE_PATH_ENV_VAR, SorbetHelper::SORBET_GEM_SPEC, SorbetHelper::SORBET_PAYLOAD_URL
Instance Method Summary collapse
Methods included from Runtime::Reflection
#ancestors_of, #are_equal?, #attached_class_of, #class_of, #constantize, #constants_of, #descendants_of, #inherited_ancestors_of, #method_of, #name_of, #name_of_type, #object_id_of, #private_instance_methods_of, #protected_instance_methods_of, #public_instance_methods_of, #qualified_name_of, #resolve_loc, #signature_of, #singleton_class_of, #superclass_of
Methods included from RBIHelper
#as_nilable_type, #create_block_param, #create_kw_opt_param, #create_kw_param, #create_kw_rest_param, #create_opt_param, #create_param, #create_rest_param, #create_typed_param, #sanitize_signature_types, serialize_type_variable, #valid_method_name?, #valid_parameter_name?
Methods included from SorbetHelper
#sorbet, #sorbet_path, #sorbet_supports?
Instance Method Details
#type_for(type) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tapioca/dsl/helpers/graphql_type_helper.rb', line 13 def type_for(type) unwrapped_type = type.unwrap parsed_type = case unwrapped_type when GraphQL::Types::Boolean.singleton_class "T::Boolean" when GraphQL::Types::Float.singleton_class qualified_name_of(Float) when GraphQL::Types::ID.singleton_class qualified_name_of(String) when GraphQL::Types::Int.singleton_class qualified_name_of(Integer) when GraphQL::Types::ISO8601Date.singleton_class qualified_name_of(Date) when GraphQL::Types::ISO8601DateTime.singleton_class qualified_name_of(DateTime) when GraphQL::Types::JSON.singleton_class "T::Hash[::String, T.untyped]" when GraphQL::Types::String.singleton_class qualified_name_of(String) when GraphQL::Schema::Enum.singleton_class enum_values = T.cast(unwrapped_type.enum_values, T::Array[GraphQL::Schema::EnumValue]) value_types = enum_values.map { |v| qualified_name_of(v.value.class) }.uniq if value_types.size == 1 value_types.first else "T.any(#{value_types.join(", ")})" end when GraphQL::Schema::InputObject.singleton_class qualified_name_of(unwrapped_type) else "T.untyped" end parsed_type = T.must(parsed_type) if type.list? parsed_type = "T::Array[#{parsed_type}]" end unless type.non_null? parsed_type = as_nilable_type(parsed_type) end parsed_type end |