graphql 0.9.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/base_type.rb +24 -0
- data/lib/graphql/definition_helpers/defined_by_config.rb +5 -4
- data/lib/graphql/definition_helpers/non_null_with_bang.rb +1 -1
- data/lib/graphql/definition_helpers/type_definer.rb +1 -1
- data/lib/graphql/enum_type.rb +16 -3
- data/lib/graphql/input_object_type.rb +10 -0
- data/lib/graphql/language.rb +0 -5
- data/lib/graphql/language/nodes.rb +79 -75
- data/lib/graphql/language/parser.rb +109 -106
- data/lib/graphql/language/transform.rb +100 -91
- data/lib/graphql/language/visitor.rb +78 -74
- data/lib/graphql/list_type.rb +5 -0
- data/lib/graphql/non_null_type.rb +6 -2
- data/lib/graphql/query.rb +58 -9
- data/lib/graphql/query/arguments.rb +29 -26
- data/lib/graphql/query/base_execution/value_resolution.rb +3 -3
- data/lib/graphql/query/directive_chain.rb +1 -1
- data/lib/graphql/query/executor.rb +6 -27
- data/lib/graphql/query/literal_input.rb +89 -0
- data/lib/graphql/query/ruby_input.rb +20 -0
- data/lib/graphql/query/serial_execution/field_resolution.rb +1 -1
- data/lib/graphql/query/variables.rb +39 -0
- data/lib/graphql/scalar_type.rb +27 -5
- data/lib/graphql/schema.rb +5 -0
- data/lib/graphql/schema/type_expression.rb +28 -0
- data/lib/graphql/static_validation/literal_validator.rb +5 -2
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +0 -2
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/version.rb +1 -1
- data/readme.md +3 -2
- data/spec/graphql/enum_type_spec.rb +7 -2
- data/spec/graphql/input_object_type_spec.rb +45 -0
- data/spec/graphql/language/parser_spec.rb +2 -1
- data/spec/graphql/language/transform_spec.rb +5 -0
- data/spec/graphql/query/base_execution/value_resolution_spec.rb +46 -0
- data/spec/graphql/query/context_spec.rb +37 -0
- data/spec/graphql/query/executor_spec.rb +33 -0
- data/spec/graphql/query_spec.rb +110 -26
- data/spec/graphql/schema/type_expression_spec.rb +38 -0
- data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +2 -2
- data/spec/support/dairy_app.rb +17 -17
- data/spec/support/dairy_data.rb +2 -2
- metadata +12 -2
@@ -5,8 +5,8 @@ describe GraphQL::StaticValidation::ArgumentLiteralsAreCompatible do
|
|
5
5
|
query getCheese {
|
6
6
|
cheese(id: "aasdlkfj") { source }
|
7
7
|
cheese(id: 1) { source @skip(if: {id: 1})}
|
8
|
-
yakSource: searchDairy(product: {source: YAK, fatContent: 1.1}) { source }
|
9
|
-
badSource: searchDairy(product: {source: 1.1}) { source }
|
8
|
+
yakSource: searchDairy(product: [{source: YAK, fatContent: 1.1}]) { source }
|
9
|
+
badSource: searchDairy(product: [{source: 1.1}]) { source }
|
10
10
|
}
|
11
11
|
|
12
12
|
fragment cheeseFields on Cheese {
|
data/spec/support/dairy_app.rb
CHANGED
@@ -32,17 +32,15 @@ CheeseType = GraphQL::ObjectType.define do
|
|
32
32
|
field :id, !types.Int, "Unique identifier"
|
33
33
|
field :flavor, !types.String, "Kind of Cheese"
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
type(!DairyAnimalEnum)
|
38
|
-
description("Animal which produced the milk for this cheese")
|
39
|
-
end
|
35
|
+
field :source, !DairyAnimalEnum,
|
36
|
+
"Animal which produced the milk for this cheese"
|
40
37
|
|
38
|
+
# Or can define by block:
|
41
39
|
field :similarCheese, -> { CheeseType }, "Cheeses like this one" do
|
42
40
|
argument :source, !types[!DairyAnimalEnum]
|
43
41
|
resolve -> (t, a, c) {
|
44
42
|
# get the strings out:
|
45
|
-
sources = a["source"]
|
43
|
+
sources = a["source"]
|
46
44
|
if sources.include?("YAK")
|
47
45
|
raise NoSuchDairyError.new("No cheeses are made from Yak milk!")
|
48
46
|
else
|
@@ -67,6 +65,9 @@ MilkType = GraphQL::ObjectType.define do
|
|
67
65
|
field :fatContent, !types.Float, "Percentage which is milkfat"
|
68
66
|
field :flavors, types[types.String], "Chocolate, Strawberry, etc" do
|
69
67
|
argument :limit, types.Int
|
68
|
+
resolve -> (milk, args, ctx) {
|
69
|
+
args[:limit] ? milk.flavors.first(args[:limit]) : milk.flavors
|
70
|
+
}
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -98,12 +99,6 @@ CowType = GraphQL::ObjectType.define do
|
|
98
99
|
field :last_produced_dairy, DairyProductUnion
|
99
100
|
end
|
100
101
|
|
101
|
-
MaybeNullType = GraphQL::ObjectType.define do
|
102
|
-
name "MaybeNull"
|
103
|
-
description "An object whose fields return nil"
|
104
|
-
field :cheese, CheeseType
|
105
|
-
end
|
106
|
-
|
107
102
|
DairyProductInputType = GraphQL::InputObjectType.define {
|
108
103
|
name "DairyProductInput"
|
109
104
|
description "Properties for finding a dairy product"
|
@@ -121,7 +116,11 @@ class FetchField
|
|
121
116
|
description(desc)
|
122
117
|
argument :id, id_type
|
123
118
|
|
124
|
-
resolve -> (t, a, c) {
|
119
|
+
resolve -> (t, a, c) {
|
120
|
+
id_string = a["id"].to_s # Cheese has Int type, Milk has ID type :(
|
121
|
+
id, item = data.find { |id, item| id.to_s == id_string }
|
122
|
+
item
|
123
|
+
}
|
125
124
|
end
|
126
125
|
end
|
127
126
|
end
|
@@ -166,12 +165,13 @@ QueryType = GraphQL::ObjectType.define do
|
|
166
165
|
field :searchDairy do
|
167
166
|
description "Find dairy products matching a description"
|
168
167
|
type !DairyProductUnion
|
169
|
-
|
170
|
-
|
168
|
+
# This is a list just for testing 😬
|
169
|
+
argument :product, types[DairyProductInputType], default_value: [{"source" => "SHEEP"}]
|
170
|
+
resolve -> (t, args, c) {
|
171
|
+
source = args["product"][0][:source] # String or Sym is ok
|
171
172
|
products = CHEESES.values + MILKS.values
|
172
|
-
source = a["product"][:source] # String or sym is ok
|
173
173
|
if !source.nil?
|
174
|
-
products = products.select { |
|
174
|
+
products = products.select { |pr| pr.source == source }
|
175
175
|
end
|
176
176
|
products.first
|
177
177
|
}
|
data/spec/support/dairy_data.rb
CHANGED
@@ -5,9 +5,9 @@ CHEESES = {
|
|
5
5
|
3 => Cheese.new(3, "Manchego", 0.065, "SHEEP")
|
6
6
|
}
|
7
7
|
|
8
|
-
Milk = Struct.new(:id, :fatContent, :source)
|
8
|
+
Milk = Struct.new(:id, :fatContent, :source, :flavors)
|
9
9
|
MILKS = {
|
10
|
-
1 => Milk.new(1, 0.04, 1),
|
10
|
+
1 => Milk.new(1, 0.04, 1, ["Natural", "Chocolate", "Strawberry"]),
|
11
11
|
}
|
12
12
|
|
13
13
|
DAIRY = OpenStruct.new(
|
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.
|
4
|
+
version: 0.10.0
|
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-10-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -213,11 +213,14 @@ files:
|
|
213
213
|
- lib/graphql/query/context.rb
|
214
214
|
- lib/graphql/query/directive_chain.rb
|
215
215
|
- lib/graphql/query/executor.rb
|
216
|
+
- lib/graphql/query/literal_input.rb
|
217
|
+
- lib/graphql/query/ruby_input.rb
|
216
218
|
- lib/graphql/query/serial_execution.rb
|
217
219
|
- lib/graphql/query/serial_execution/field_resolution.rb
|
218
220
|
- lib/graphql/query/serial_execution/operation_resolution.rb
|
219
221
|
- lib/graphql/query/serial_execution/selection_resolution.rb
|
220
222
|
- lib/graphql/query/type_resolver.rb
|
223
|
+
- lib/graphql/query/variables.rb
|
221
224
|
- lib/graphql/repl.rb
|
222
225
|
- lib/graphql/scalar_type.rb
|
223
226
|
- lib/graphql/schema.rb
|
@@ -227,6 +230,7 @@ files:
|
|
227
230
|
- lib/graphql/schema/middleware_chain.rb
|
228
231
|
- lib/graphql/schema/printer.rb
|
229
232
|
- lib/graphql/schema/rescue_middleware.rb
|
233
|
+
- lib/graphql/schema/type_expression.rb
|
230
234
|
- lib/graphql/schema/type_map.rb
|
231
235
|
- lib/graphql/schema/type_reducer.rb
|
232
236
|
- lib/graphql/schema/type_validator.rb
|
@@ -274,6 +278,8 @@ files:
|
|
274
278
|
- spec/graphql/language/transform_spec.rb
|
275
279
|
- spec/graphql/language/visitor_spec.rb
|
276
280
|
- spec/graphql/object_type_spec.rb
|
281
|
+
- spec/graphql/query/base_execution/value_resolution_spec.rb
|
282
|
+
- spec/graphql/query/context_spec.rb
|
277
283
|
- spec/graphql/query/executor_spec.rb
|
278
284
|
- spec/graphql/query/type_resolver_spec.rb
|
279
285
|
- spec/graphql/query_spec.rb
|
@@ -281,6 +287,7 @@ files:
|
|
281
287
|
- spec/graphql/schema/middleware_chain_spec.rb
|
282
288
|
- spec/graphql/schema/printer_spec.rb
|
283
289
|
- spec/graphql/schema/rescue_middleware_spec.rb
|
290
|
+
- spec/graphql/schema/type_expression_spec.rb
|
284
291
|
- spec/graphql/schema/type_reducer_spec.rb
|
285
292
|
- spec/graphql/schema/type_validator_spec.rb
|
286
293
|
- spec/graphql/schema_spec.rb
|
@@ -349,6 +356,8 @@ test_files:
|
|
349
356
|
- spec/graphql/language/transform_spec.rb
|
350
357
|
- spec/graphql/language/visitor_spec.rb
|
351
358
|
- spec/graphql/object_type_spec.rb
|
359
|
+
- spec/graphql/query/base_execution/value_resolution_spec.rb
|
360
|
+
- spec/graphql/query/context_spec.rb
|
352
361
|
- spec/graphql/query/executor_spec.rb
|
353
362
|
- spec/graphql/query/type_resolver_spec.rb
|
354
363
|
- spec/graphql/query_spec.rb
|
@@ -356,6 +365,7 @@ test_files:
|
|
356
365
|
- spec/graphql/schema/middleware_chain_spec.rb
|
357
366
|
- spec/graphql/schema/printer_spec.rb
|
358
367
|
- spec/graphql/schema/rescue_middleware_spec.rb
|
368
|
+
- spec/graphql/schema/type_expression_spec.rb
|
359
369
|
- spec/graphql/schema/type_reducer_spec.rb
|
360
370
|
- spec/graphql/schema/type_validator_spec.rb
|
361
371
|
- spec/graphql/schema_spec.rb
|