tapioca 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c7d5aa34969c7dc1bcd885ac0438e4a76d945ca23e7a5942d88d1aa679d4b75
4
- data.tar.gz: 0d6fd32d3388e33804bbdbb6cddcd904f724cc3071864219b6fcb88377cb5816
3
+ metadata.gz: 555978fd8996f91539408f4e1c251bf30933d800deab606a63974088f59d8525
4
+ data.tar.gz: 249a48a0c8a9cc73d56334b2a83b26b356a920747b7ba4b83e1c92575ba1d158
5
5
  SHA512:
6
- metadata.gz: fdda19a3d7e5033fb96a3703c6b2f35030fc72ec5299072c8d41db071df61bbe4fcd28c5e68637199c793b52713f0177ffc55086fce58fb7b443194a8de5d2a4
7
- data.tar.gz: 7ad308fc2d306370e5a246c9ef548b0199d597027e6c4561f93b7aff4a31ac98f26d2cdc4e5cb836704c1351d634505a71f9a87cfef899899fea0f07ab8d0795
6
+ metadata.gz: 819cb6fc4c0fb0adbbf79ad4250147c6753b87f257a9c9d869419ca4db68ad869aea78fbbb995a71e1cee31b06a237df34f680bc1c97e3f3b7ea62c4c67b6b16
7
+ data.tar.gz: e28b2f755e4ff5aab74cacc4f7141e5c93ee2b0ca8e1818c068b0c4ef5ba6e76e06cfbc5775f8e03babc50309df8d85c20c30708e9656bb714f506cb7ed8434d
@@ -31,7 +31,7 @@ module Tapioca
31
31
  # # test_case.rbi
32
32
  # # typed: true
33
33
  # class ActiveSupport::TestCase
34
- # sig { params(fixture_names: Symbol).returns(T.untyped) }
34
+ # sig { params(fixture_names: T.any(String, Symbol)).returns(T.untyped) }
35
35
  # def posts(*fixture_names); end
36
36
  # end
37
37
  # ~~~
@@ -99,7 +99,7 @@ module Tapioca
99
99
  def create_fixture_method(mod, name)
100
100
  mod.create_method(
101
101
  name,
102
- parameters: [create_rest_param("fixture_names", type: "Symbol")],
102
+ parameters: [create_rest_param("fixture_names", type: "T.any(String, Symbol)")],
103
103
  return_type: "T.untyped"
104
104
  )
105
105
  end
@@ -47,12 +47,10 @@ module Tapioca
47
47
  arguments = constant.all_argument_definitions
48
48
  return if arguments.empty?
49
49
 
50
- graphql_type_helper = Helpers::GraphqlTypeHelper.new
51
-
52
50
  root.create_path(constant) do |input_object|
53
51
  arguments.each do |argument|
54
52
  name = argument.keyword.to_s
55
- input_object.create_method(name, return_type: graphql_type_helper.type_for(argument.type))
53
+ input_object.create_method(name, return_type: Helpers::GraphqlTypeHelper.type_for(argument.type))
56
54
  end
57
55
  end
58
56
  end
@@ -54,12 +54,11 @@ module Tapioca
54
54
  return if arguments.empty?
55
55
 
56
56
  arguments_by_name = arguments.to_h { |a| [a.keyword.to_s, a] }
57
- graphql_type_helper = Helpers::GraphqlTypeHelper.new
58
57
 
59
58
  params = compile_method_parameters_to_rbi(method_def).map do |param|
60
59
  name = param.param.name
61
60
  argument = arguments_by_name.fetch(name, nil)
62
- create_typed_param(param.param, argument ? graphql_type_helper.type_for(argument.type) : "T.untyped")
61
+ create_typed_param(param.param, argument ? Helpers::GraphqlTypeHelper.type_for(argument.type) : "T.untyped")
63
62
  end
64
63
 
65
64
  root.create_path(constant) do |mutation|
@@ -4,10 +4,10 @@
4
4
  module Tapioca
5
5
  module Dsl
6
6
  module Helpers
7
- class GraphqlTypeHelper
7
+ module GraphqlTypeHelper
8
+ extend self
9
+
8
10
  extend T::Sig
9
- include RBIHelper
10
- include Runtime::Reflection
11
11
 
12
12
  sig { params(type: GraphQL::Schema::Wrapper).returns(String) }
13
13
  def type_for(type)
@@ -17,45 +17,49 @@ module Tapioca
17
17
  when GraphQL::Types::Boolean.singleton_class
18
18
  "T::Boolean"
19
19
  when GraphQL::Types::Float.singleton_class
20
- qualified_name_of(Float)
21
- when GraphQL::Types::ID.singleton_class
22
- qualified_name_of(String)
20
+ type_for_constant(Float)
21
+ when GraphQL::Types::ID.singleton_class, GraphQL::Types::String.singleton_class
22
+ type_for_constant(String)
23
23
  when GraphQL::Types::Int.singleton_class
24
- qualified_name_of(Integer)
24
+ type_for_constant(Integer)
25
25
  when GraphQL::Types::ISO8601Date.singleton_class
26
- qualified_name_of(Date)
26
+ type_for_constant(Date)
27
27
  when GraphQL::Types::ISO8601DateTime.singleton_class
28
- qualified_name_of(DateTime)
28
+ type_for_constant(DateTime)
29
29
  when GraphQL::Types::JSON.singleton_class
30
30
  "T::Hash[::String, T.untyped]"
31
- when GraphQL::Types::String.singleton_class
32
- qualified_name_of(String)
33
31
  when GraphQL::Schema::Enum.singleton_class
34
32
  enum_values = T.cast(unwrapped_type.enum_values, T::Array[GraphQL::Schema::EnumValue])
35
- value_types = enum_values.map { |v| qualified_name_of(v.value.class) }.uniq
33
+ value_types = enum_values.map { |v| type_for_constant(v.value.class) }.uniq
34
+
36
35
  if value_types.size == 1
37
- value_types.first
36
+ T.must(value_types.first)
38
37
  else
39
38
  "T.any(#{value_types.join(", ")})"
40
39
  end
41
40
  when GraphQL::Schema::InputObject.singleton_class
42
- qualified_name_of(unwrapped_type)
41
+ type_for_constant(unwrapped_type)
43
42
  else
44
43
  "T.untyped"
45
44
  end
46
45
 
47
- parsed_type = T.must(parsed_type)
48
-
49
46
  if type.list?
50
47
  parsed_type = "T::Array[#{parsed_type}]"
51
48
  end
52
49
 
53
50
  unless type.non_null?
54
- parsed_type = as_nilable_type(parsed_type)
51
+ parsed_type = RBIHelper.as_nilable_type(parsed_type)
55
52
  end
56
53
 
57
54
  parsed_type
58
55
  end
56
+
57
+ private
58
+
59
+ sig { params(constant: Module).returns(String) }
60
+ def type_for_constant(constant)
61
+ Runtime::Reflection.qualified_name_of(constant) || "T.untyped"
62
+ end
59
63
  end
60
64
  end
61
65
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.10.0"
5
+ VERSION = "0.10.1"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2022-08-31 00:00:00.000000000 Z
14
+ date: 2022-09-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler