graphql 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graphql/query/serial_execution/selection_resolution.rb +15 -1
- data/lib/graphql/version.rb +1 -1
- data/spec/graphql/introspection/schema_type_spec.rb +1 -0
- data/spec/graphql/query_spec.rb +46 -0
- data/spec/support/dairy_app.rb +22 -0
- data/spec/support/dairy_data.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 361de5aace2ae0ad425b1c59da22dbc53128020e
|
4
|
+
data.tar.gz: d2927200177cdc6c5d26f82feb195180d9e631da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9b4d287ff8fe030fdb5b7693b1e418cbdbd8f4c2f50c99f6e2daef14501a39b60afbdaba2ec1a6958cf4f7ef6cf9cd13028779565f34cc81ffc08df01ceffd8
|
7
|
+
data.tar.gz: d775e65e4736ab0ed9fb9502c4f42d0a59ea5703efc3c9174e68a9f25300377b3c6236e7f818967e6a6cccd83ad5316c1b9259c70313972a313bc93aed2c90f8
|
@@ -21,12 +21,26 @@ module GraphQL
|
|
21
21
|
def result
|
22
22
|
selections.reduce({}) do |memo, ast_field|
|
23
23
|
field_value = resolve_field(ast_field)
|
24
|
-
memo
|
24
|
+
deep_merge memo, field_value
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
+
def deep_merge(h1, h2)
|
31
|
+
h1.merge(h2) do |key, oldval, newval|
|
32
|
+
if oldval.is_a?(Array) && newval.is_a?(Array)
|
33
|
+
oldval.each_index.map do |i|
|
34
|
+
deep_merge oldval[i], newval[i]
|
35
|
+
end
|
36
|
+
elsif oldval.is_a?(Hash) && newval.is_a?(Hash)
|
37
|
+
deep_merge(oldval, newval)
|
38
|
+
else
|
39
|
+
newval
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
def resolve_field(ast_field)
|
31
45
|
chain = GraphQL::Query::DirectiveChain.new(ast_field, query) {
|
32
46
|
strategy_name = RESOLUTION_STRATEGIES[ast_field.class]
|
data/lib/graphql/version.rb
CHANGED
data/spec/graphql/query_spec.rb
CHANGED
@@ -82,6 +82,52 @@ describe GraphQL::Query do
|
|
82
82
|
assert_equal(GraphQL::Language::Nodes::FragmentDefinition, query.fragments['cheeseFields'].class)
|
83
83
|
end
|
84
84
|
|
85
|
+
describe "merging fragments with different keys" do
|
86
|
+
let(:query_string) { %|
|
87
|
+
query getCheeseFieldsThroughDairy {
|
88
|
+
dairy {
|
89
|
+
...flavorFragment
|
90
|
+
...fatContentFragment
|
91
|
+
}
|
92
|
+
}
|
93
|
+
fragment flavorFragment on Dairy {
|
94
|
+
cheese {
|
95
|
+
flavor
|
96
|
+
}
|
97
|
+
milks {
|
98
|
+
id
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
fragment fatContentFragment on Dairy {
|
103
|
+
cheese {
|
104
|
+
fatContent
|
105
|
+
}
|
106
|
+
milks {
|
107
|
+
fatContent
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
|}
|
112
|
+
|
113
|
+
it "should include keys from each fragment" do
|
114
|
+
expected = {"data" => {
|
115
|
+
"dairy" => {
|
116
|
+
"cheese" => {
|
117
|
+
"flavor" => "Brie",
|
118
|
+
"fatContent" => 0.19
|
119
|
+
},
|
120
|
+
"milks" => [
|
121
|
+
{
|
122
|
+
"id" => "1",
|
123
|
+
"fatContent" => 0.04,
|
124
|
+
}
|
125
|
+
],
|
126
|
+
}
|
127
|
+
}}
|
128
|
+
assert_equal(expected, result)
|
129
|
+
end
|
130
|
+
end
|
85
131
|
|
86
132
|
describe "malformed queries" do
|
87
133
|
describe "whitespace-only" do
|
data/spec/support/dairy_app.rb
CHANGED
@@ -62,6 +62,14 @@ MilkType = GraphQL::ObjectType.define do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
DairyType = GraphQL::ObjectType.define do
|
66
|
+
name 'Dairy'
|
67
|
+
description 'A farm where milk is harvested and cheese is produced'
|
68
|
+
field :id, !types.ID
|
69
|
+
field :cheese, CheeseType
|
70
|
+
field :milks, types[MilkType]
|
71
|
+
end
|
72
|
+
|
65
73
|
MaybeNullType = GraphQL::ObjectType.define do
|
66
74
|
name "MaybeNull"
|
67
75
|
description "An object whose fields return nil"
|
@@ -96,6 +104,19 @@ class FetchField
|
|
96
104
|
end
|
97
105
|
end
|
98
106
|
|
107
|
+
class SingletonField
|
108
|
+
def self.create(type:, data:)
|
109
|
+
desc = "Find the only #{type.name}"
|
110
|
+
return_type = type
|
111
|
+
GraphQL::Field.define do
|
112
|
+
type(return_type)
|
113
|
+
description(desc)
|
114
|
+
|
115
|
+
resolve -> (t, a, c) {data}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
99
120
|
SourceFieldDefn = Proc.new {
|
100
121
|
type GraphQL::ListType.new(of_type: CheeseType)
|
101
122
|
description "Cheese from source"
|
@@ -116,6 +137,7 @@ QueryType = GraphQL::ObjectType.define do
|
|
116
137
|
description "Query root of the system"
|
117
138
|
field :cheese, field: FetchField.create(type: CheeseType, data: CHEESES)
|
118
139
|
field :milk, field: FetchField.create(type: MilkType, data: MILKS, id_type: !types.ID)
|
140
|
+
field :dairy, field: SingletonField.create(type: DairyType, data: DAIRY)
|
119
141
|
field :fromSource, &SourceFieldDefn
|
120
142
|
field :favoriteEdible, &FavoriteFieldDefn
|
121
143
|
field :searchDairy do
|
data/spec/support/dairy_data.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|