graphql-client 0.8.1 → 0.8.2

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
  SHA1:
3
- metadata.gz: 3207be7a370ae7995dd3355381f4dfc6d839e100
4
- data.tar.gz: 80b877dd6c13310c10217a6a65a375728a6a9cb6
3
+ metadata.gz: f25cf31f15a80b4f310b6cbc8cba4f536ae6b8ef
4
+ data.tar.gz: 2481de14f0b278a24a17771de111d661589d004e
5
5
  SHA512:
6
- metadata.gz: 036b98757f630e799ca5f8b111aad802d77f2723bc0cc73dae113c24687189cbfd6ad440224a6ba952902dc401a57a6f7cfa33523c6b764aa83f37e526a3452f
7
- data.tar.gz: db865264342c1e9dc7b42d07fbe4ae5d01319514ca884c92bee4aff7e3980436e5fad4a851768f1c97bd371d1ae3a0b7c6460e3c0b895a48bf81dd2d0e3153d8
6
+ metadata.gz: '08cccc2e230f043b4460dcc2bc352ce5c0e6510709663971ac517da36f390668beed64c9bb702aef5d6e2bea8a5ba97a67cc5ae36715e2c49af3c124328226f7'
7
+ data.tar.gz: 8a311fdf37db44780cbc739e870b4ca706a2884d37f07647e152d4384d869d92051ea6d6513422376bcb77fdb7bda0cf51468f082cad93d5e342ce870215716a
@@ -30,7 +30,26 @@ module GraphQL
30
30
  ListWrapper.new(wrap(source_definition, node, type.of_type, name: name))
31
31
  when GraphQL::ScalarType
32
32
  ScalarWrapper.new(type)
33
- when GraphQL::ObjectType, GraphQL::InterfaceType, GraphQL::UnionType
33
+ when GraphQL::EnumType
34
+ EnumWrapper.new(type)
35
+ when GraphQL::UnionType
36
+ types = {}
37
+
38
+ node.selections.each do |selection|
39
+ case selection
40
+ when Language::Nodes::InlineFragment
41
+ selection_type = source_definition.document_types[selection]
42
+ selection_wrapper = wrap(source_definition, selection, selection_type, name: name)
43
+ if types[selection_type]
44
+ types[selection_type.name] |= selection_wrapper
45
+ else
46
+ types[selection_type.name] = selection_wrapper
47
+ end
48
+ end
49
+ end
50
+
51
+ UnionWrapper.new(types)
52
+ when GraphQL::ObjectType, GraphQL::InterfaceType
34
53
  fields = {}
35
54
 
36
55
  node.selections.each do |selection|
@@ -57,6 +76,26 @@ module GraphQL
57
76
  end
58
77
  end
59
78
 
79
+ class UnionWrapper
80
+ def initialize(possible_types)
81
+ @possible_types = possible_types
82
+ end
83
+
84
+ def cast(value, errors = nil)
85
+ typename = value && value["__typename"]
86
+ if wrapper = @possible_types[typename]
87
+ wrapper.cast(value, errors)
88
+ else
89
+ raise TypeError, "expected union value to be #{@possible_types.keys.join(", ")}, but was #{typename}"
90
+ end
91
+ end
92
+
93
+ def |(_other)
94
+ # XXX: How would union merge?
95
+ self
96
+ end
97
+ end
98
+
60
99
  class ListWrapper
61
100
  def initialize(type)
62
101
  @of_klass = type
@@ -109,6 +148,21 @@ module GraphQL
109
148
  end
110
149
  end
111
150
 
151
+ class EnumWrapper
152
+ def initialize(type)
153
+ @type = type
154
+ end
155
+
156
+ def cast(value, _errors = nil)
157
+ value
158
+ end
159
+
160
+ def |(_other)
161
+ # XXX: How would enums merge?
162
+ self
163
+ end
164
+ end
165
+
112
166
  # :nodoc:
113
167
  class ScalarWrapper
114
168
  def initialize(type)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub