graphql 0.19.3 → 0.19.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/analysis/max_query_complexity.rb +1 -1
- data/lib/graphql/analysis/max_query_depth.rb +1 -1
- data/lib/graphql/boolean_type.rb +2 -2
- data/lib/graphql/define/instance_definable.rb +2 -2
- data/lib/graphql/enum_type.rb +3 -3
- data/lib/graphql/field.rb +6 -6
- data/lib/graphql/float_type.rb +2 -2
- data/lib/graphql/id_type.rb +2 -2
- data/lib/graphql/input_object_type.rb +1 -1
- data/lib/graphql/int_type.rb +2 -2
- data/lib/graphql/internal_representation/rewrite.rb +12 -12
- data/lib/graphql/introspection/arguments_field.rb +1 -1
- data/lib/graphql/introspection/enum_value_type.rb +1 -1
- data/lib/graphql/introspection/enum_values_field.rb +1 -1
- data/lib/graphql/introspection/field_type.rb +1 -1
- data/lib/graphql/introspection/fields_field.rb +1 -1
- data/lib/graphql/introspection/input_fields_field.rb +1 -1
- data/lib/graphql/introspection/input_value_type.rb +2 -2
- data/lib/graphql/introspection/interfaces_field.rb +1 -1
- data/lib/graphql/introspection/of_type_field.rb +1 -1
- data/lib/graphql/introspection/possible_types_field.rb +1 -1
- data/lib/graphql/introspection/schema_field.rb +1 -1
- data/lib/graphql/introspection/schema_type.rb +5 -5
- data/lib/graphql/introspection/type_by_name_field.rb +1 -1
- data/lib/graphql/introspection/type_type.rb +6 -6
- data/lib/graphql/introspection/typename_field.rb +1 -1
- data/lib/graphql/language.rb +1 -0
- data/lib/graphql/language/comments.rb +44 -0
- data/lib/graphql/language/definition_slice.rb +1 -1
- data/lib/graphql/language/generation.rb +35 -12
- data/lib/graphql/language/lexer.rb +29 -10
- data/lib/graphql/language/lexer.rl +25 -6
- data/lib/graphql/language/nodes.rb +30 -23
- data/lib/graphql/language/parser.rb +33 -14
- data/lib/graphql/language/parser.y +33 -14
- data/lib/graphql/language/parser_tests.rb +86 -2
- data/lib/graphql/language/token.rb +3 -2
- data/lib/graphql/language/visitor.rb +3 -3
- data/lib/graphql/object_type.rb +1 -1
- data/lib/graphql/query/arguments.rb +23 -2
- data/lib/graphql/query/serial_execution/field_resolution.rb +31 -14
- data/lib/graphql/relay/base_connection.rb +1 -3
- data/lib/graphql/relay/connection_type.rb +1 -1
- data/lib/graphql/relay/mutation.rb +1 -1
- data/lib/graphql/relay/relation_connection.rb +7 -3
- data/lib/graphql/scalar_type.rb +1 -1
- data/lib/graphql/schema.rb +19 -8
- data/lib/graphql/schema/loader.rb +2 -2
- data/lib/graphql/schema/printer.rb +63 -8
- data/lib/graphql/schema/timeout_middleware.rb +11 -11
- data/lib/graphql/schema/validation.rb +12 -12
- data/lib/graphql/static_validation/arguments_validator.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_defined.rb +1 -1
- data/lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_are_defined_on_type.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +1 -1
- data/lib/graphql/static_validation/rules/fields_will_merge.rb +3 -2
- data/lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb +3 -3
- data/lib/graphql/static_validation/rules/fragment_types_exist.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_finite.rb +9 -4
- data/lib/graphql/static_validation/rules/fragments_are_named.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb +1 -1
- data/lib/graphql/static_validation/rules/fragments_are_used.rb +3 -3
- data/lib/graphql/static_validation/rules/mutation_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/required_arguments_are_present.rb +2 -2
- data/lib/graphql/static_validation/rules/subscription_root_exists.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb +1 -1
- data/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +2 -2
- data/lib/graphql/static_validation/rules/variables_are_input_types.rb +1 -1
- data/lib/graphql/static_validation/rules/variables_are_used_and_defined.rb +6 -6
- data/lib/graphql/static_validation/type_stack.rb +2 -2
- data/lib/graphql/string_type.rb +2 -2
- data/lib/graphql/version.rb +1 -1
- data/readme.md +1 -1
- data/spec/graphql/analysis/analyze_query_spec.rb +3 -3
- data/spec/graphql/analysis/query_complexity_spec.rb +7 -7
- data/spec/graphql/introspection/directive_type_spec.rb +2 -2
- data/spec/graphql/introspection/introspection_query_spec.rb +26 -26
- data/spec/graphql/language/generation_spec.rb +137 -53
- data/spec/graphql/language/lexer_spec.rb +22 -0
- data/spec/graphql/language/visitor_spec.rb +6 -6
- data/spec/graphql/query/arguments_spec.rb +45 -1
- data/spec/graphql/query/context_spec.rb +4 -4
- data/spec/graphql/query/executor_spec.rb +1 -1
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +1 -1
- data/spec/graphql/relay/mutation_spec.rb +2 -2
- data/spec/graphql/relay/node_spec.rb +2 -2
- data/spec/graphql/relay/relation_connection_spec.rb +16 -0
- data/spec/graphql/schema/loader_spec.rb +2 -2
- data/spec/graphql/schema/middleware_chain_spec.rb +6 -6
- data/spec/graphql/schema/printer_spec.rb +268 -18
- data/spec/graphql/schema/rescue_middleware_spec.rb +1 -1
- data/spec/graphql/schema/timeout_middleware_spec.rb +2 -2
- data/spec/graphql/schema_spec.rb +2 -2
- data/spec/graphql/static_validation/rules/fragments_are_finite_spec.rb +13 -0
- data/spec/graphql/static_validation/rules/fragments_are_used_spec.rb +1 -1
- data/spec/graphql/static_validation/type_stack_spec.rb +1 -1
- data/spec/support/dairy_app.rb +25 -25
- data/spec/support/dairy_data.rb +2 -0
- data/spec/support/star_wars_data.rb +2 -1
- data/spec/support/star_wars_schema.rb +18 -18
- metadata +19 -2
data/spec/graphql/schema_spec.rb
CHANGED
@@ -92,7 +92,7 @@ describe GraphQL::Schema do
|
|
92
92
|
assert_raises(NotImplementedError) {
|
93
93
|
GraphQL::Schema.define do
|
94
94
|
query(query_type)
|
95
|
-
resolve_type ->
|
95
|
+
resolve_type ->(obj, ctx) { :whatever }
|
96
96
|
end
|
97
97
|
}
|
98
98
|
end
|
@@ -118,7 +118,7 @@ describe GraphQL::Schema do
|
|
118
118
|
assert_raises(NotImplementedError) {
|
119
119
|
GraphQL::Schema.define do
|
120
120
|
query(query_type)
|
121
|
-
resolve_type ->
|
121
|
+
resolve_type ->(obj, ctx) { :whatever }
|
122
122
|
end
|
123
123
|
}
|
124
124
|
end
|
@@ -47,4 +47,17 @@ describe GraphQL::StaticValidation::FragmentsAreFinite do
|
|
47
47
|
]
|
48
48
|
assert_equal(expected, errors)
|
49
49
|
end
|
50
|
+
|
51
|
+
describe "undefined spreads inside fragments" do
|
52
|
+
let(:query_string) {%|
|
53
|
+
{
|
54
|
+
cheese(id: 1) { ... frag1 }
|
55
|
+
}
|
56
|
+
fragment frag1 on Cheese { id, ...frag2 }
|
57
|
+
|}
|
58
|
+
|
59
|
+
it "doesn't blow up" do
|
60
|
+
assert_equal("Fragment frag2 was used, but not defined", errors.first["message"])
|
61
|
+
end
|
62
|
+
end
|
50
63
|
end
|
@@ -7,7 +7,7 @@ class TypeCheckValidator
|
|
7
7
|
|
8
8
|
def validate(context)
|
9
9
|
self.class.checks.clear
|
10
|
-
context.visitor[GraphQL::Language::Nodes::Field] << ->
|
10
|
+
context.visitor[GraphQL::Language::Nodes::Field] << ->(node, parent) {
|
11
11
|
self.class.checks << context.object_types.map(&:name)
|
12
12
|
}
|
13
13
|
end
|
data/spec/support/dairy_app.rb
CHANGED
@@ -58,7 +58,7 @@ CheeseType = GraphQL::ObjectType.define do
|
|
58
58
|
# metadata test
|
59
59
|
joins [:cheeses, :milks]
|
60
60
|
argument :source, !types[!DairyAnimalEnum], default_value: [1]
|
61
|
-
resolve ->
|
61
|
+
resolve ->(t, a, c) {
|
62
62
|
# get the strings out:
|
63
63
|
sources = a["source"]
|
64
64
|
if sources.include?("YAK")
|
@@ -71,12 +71,12 @@ CheeseType = GraphQL::ObjectType.define do
|
|
71
71
|
|
72
72
|
field :nullableCheese, CheeseType, "Cheeses like this one" do
|
73
73
|
argument :source, types[!DairyAnimalEnum]
|
74
|
-
resolve ->
|
74
|
+
resolve ->(t, a, c) { raise("NotImplemented") }
|
75
75
|
end
|
76
76
|
|
77
77
|
field :deeplyNullableCheese, CheeseType, "Cheeses like this one" do
|
78
78
|
argument :source, types[types[DairyAnimalEnum]]
|
79
|
-
resolve ->
|
79
|
+
resolve ->(t, a, c) { raise("NotImplemented") }
|
80
80
|
end
|
81
81
|
|
82
82
|
# Keywords can be used for definition methods
|
@@ -96,17 +96,17 @@ MilkType = GraphQL::ObjectType.define do
|
|
96
96
|
field :origin, !types.String, "Place the milk comes from"
|
97
97
|
field :flavors, types[types.String], "Chocolate, Strawberry, etc" do
|
98
98
|
argument :limit, types.Int
|
99
|
-
resolve ->
|
99
|
+
resolve ->(milk, args, ctx) {
|
100
100
|
args[:limit] ? milk.flavors.first(args[:limit]) : milk.flavors
|
101
101
|
}
|
102
102
|
end
|
103
103
|
field :executionError do
|
104
104
|
type GraphQL::STRING_TYPE
|
105
|
-
resolve ->
|
105
|
+
resolve ->(t, a, c) { raise(GraphQL::ExecutionError, "There was an execution error") }
|
106
106
|
end
|
107
107
|
|
108
108
|
field :allDairy, -> { types[DairyProductUnion] } do
|
109
|
-
resolve ->
|
109
|
+
resolve ->(obj, args, ctx) { CHEESES.values + MILKS.values }
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -153,12 +153,12 @@ CowType = GraphQL::ObjectType.define do
|
|
153
153
|
|
154
154
|
field :cantBeNullButIs do
|
155
155
|
type !GraphQL::STRING_TYPE
|
156
|
-
resolve ->
|
156
|
+
resolve ->(t, a, c) { nil }
|
157
157
|
end
|
158
158
|
|
159
159
|
field :cantBeNullButRaisesExecutionError do
|
160
160
|
type !GraphQL::STRING_TYPE
|
161
|
-
resolve ->
|
161
|
+
resolve ->(t, a, c) { raise GraphQL::ExecutionError, "BOOM" }
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
@@ -188,11 +188,11 @@ DeepNonNullType = GraphQL::ObjectType.define do
|
|
188
188
|
name "DeepNonNull"
|
189
189
|
field :nonNullInt, !types.Int do
|
190
190
|
argument :returning, types.Int
|
191
|
-
resolve ->
|
191
|
+
resolve ->(obj, args, ctx) { args[:returning] }
|
192
192
|
end
|
193
193
|
|
194
194
|
field :deepNonNull, DeepNonNullType.to_non_null_type do
|
195
|
-
resolve ->
|
195
|
+
resolve ->(obj, args, ctx) { :deepNonNull }
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
@@ -205,7 +205,7 @@ class FetchField
|
|
205
205
|
description(desc)
|
206
206
|
argument :id, id_type
|
207
207
|
|
208
|
-
resolve ->
|
208
|
+
resolve ->(t, a, c) {
|
209
209
|
id_string = a["id"].to_s # Cheese has Int type, Milk has ID type :(
|
210
210
|
id, item = data.find { |id, item| id.to_s == id_string }
|
211
211
|
item
|
@@ -222,7 +222,7 @@ class SingletonField
|
|
222
222
|
type(return_type)
|
223
223
|
description(desc)
|
224
224
|
|
225
|
-
resolve ->
|
225
|
+
resolve ->(t, a, c) {data}
|
226
226
|
end
|
227
227
|
end
|
228
228
|
end
|
@@ -231,7 +231,7 @@ SourceFieldDefn = Proc.new {
|
|
231
231
|
type GraphQL::ListType.new(of_type: CheeseType)
|
232
232
|
description "Cheese from source"
|
233
233
|
argument :source, DairyAnimalEnum, default_value: 1
|
234
|
-
resolve ->
|
234
|
+
resolve ->(target, arguments, context) {
|
235
235
|
CHEESES.values.select{ |c| c.source == arguments["source"] }
|
236
236
|
}
|
237
237
|
}
|
@@ -240,7 +240,7 @@ FavoriteFieldDefn = GraphQL::Field.define do
|
|
240
240
|
name "favoriteEdible"
|
241
241
|
description "My favorite food"
|
242
242
|
type EdibleInterface
|
243
|
-
resolve ->
|
243
|
+
resolve ->(t, a, c) { MILKS[1] }
|
244
244
|
end
|
245
245
|
|
246
246
|
DairyAppQueryType = GraphQL::ObjectType.define do
|
@@ -260,7 +260,7 @@ DairyAppQueryType = GraphQL::ObjectType.define do
|
|
260
260
|
type !DairyProductUnion
|
261
261
|
# This is a list just for testing 😬
|
262
262
|
argument :product, types[DairyProductInputType], default_value: [{"source" => "SHEEP"}]
|
263
|
-
resolve ->
|
263
|
+
resolve ->(t, args, c) {
|
264
264
|
source = args["product"][0][:source] # String or Sym is ok
|
265
265
|
products = CHEESES.values + MILKS.values
|
266
266
|
if !source.nil?
|
@@ -272,7 +272,7 @@ DairyAppQueryType = GraphQL::ObjectType.define do
|
|
272
272
|
|
273
273
|
field :allDairy, types[DairyProductUnion] do
|
274
274
|
argument :executionErrorAtIndex, types.Int
|
275
|
-
resolve ->
|
275
|
+
resolve ->(obj, args, ctx) {
|
276
276
|
result = CHEESES.values + MILKS.values
|
277
277
|
result[args[:executionErrorAtIndex]] = GraphQL::ExecutionError.new("missing dairy") if args[:executionErrorAtIndex]
|
278
278
|
result
|
@@ -280,27 +280,27 @@ DairyAppQueryType = GraphQL::ObjectType.define do
|
|
280
280
|
end
|
281
281
|
|
282
282
|
field :allEdible, types[EdibleInterface] do
|
283
|
-
resolve ->
|
283
|
+
resolve ->(obj, args, ctx) { CHEESES.values + MILKS.values }
|
284
284
|
end
|
285
285
|
|
286
286
|
field :error do
|
287
287
|
description "Raise an error"
|
288
288
|
type GraphQL::STRING_TYPE
|
289
|
-
resolve ->
|
289
|
+
resolve ->(t, a, c) { raise("This error was raised on purpose") }
|
290
290
|
end
|
291
291
|
|
292
292
|
field :executionError do
|
293
293
|
type GraphQL::STRING_TYPE
|
294
|
-
resolve ->
|
294
|
+
resolve ->(t, a, c) { raise(GraphQL::ExecutionError, "There was an execution error") }
|
295
295
|
end
|
296
296
|
|
297
297
|
# To test possibly-null fields
|
298
298
|
field :maybeNull, MaybeNullType do
|
299
|
-
resolve ->
|
299
|
+
resolve ->(t, a, c) { OpenStruct.new(cheese: nil) }
|
300
300
|
end
|
301
301
|
|
302
302
|
field :deepNonNull, !DeepNonNullType do
|
303
|
-
resolve ->
|
303
|
+
resolve ->(o, a, c) { :deepNonNull }
|
304
304
|
end
|
305
305
|
end
|
306
306
|
|
@@ -317,7 +317,7 @@ DairyAppMutationType = GraphQL::ObjectType.define do
|
|
317
317
|
field :pushValue, !types[!types.Int] do
|
318
318
|
description("Push a value onto a global array :D")
|
319
319
|
argument :value, !types.Int
|
320
|
-
resolve ->
|
320
|
+
resolve ->(o, args, ctx) {
|
321
321
|
GLOBAL_VALUES << args[:value]
|
322
322
|
GLOBAL_VALUES
|
323
323
|
}
|
@@ -326,7 +326,7 @@ DairyAppMutationType = GraphQL::ObjectType.define do
|
|
326
326
|
field :replaceValues, !types[!types.Int] do
|
327
327
|
description("Replace the global array with new values")
|
328
328
|
argument :input, !ReplaceValuesInputType
|
329
|
-
resolve ->
|
329
|
+
resolve ->(o, args, ctx) {
|
330
330
|
GLOBAL_VALUES.clear
|
331
331
|
GLOBAL_VALUES.push(*args[:input][:values])
|
332
332
|
GLOBAL_VALUES
|
@@ -337,7 +337,7 @@ end
|
|
337
337
|
SubscriptionType = GraphQL::ObjectType.define do
|
338
338
|
name "Subscription"
|
339
339
|
field :test, types.String do
|
340
|
-
resolve ->
|
340
|
+
resolve ->(o, a, c) { "Test" }
|
341
341
|
end
|
342
342
|
end
|
343
343
|
|
@@ -350,7 +350,7 @@ DummySchema = GraphQL::Schema.define do
|
|
350
350
|
|
351
351
|
rescue_from(NoSuchDairyError) { |err| err.message }
|
352
352
|
|
353
|
-
resolve_type ->
|
353
|
+
resolve_type ->(obj, ctx) {
|
354
354
|
DummySchema.types[obj.class.name]
|
355
355
|
}
|
356
356
|
end
|
data/spec/support/dairy_data.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ostruct'
|
1
2
|
|
2
3
|
names = [
|
3
4
|
'X-Wing',
|
@@ -73,6 +74,6 @@ def STAR_WARS_DATA.create_ship(name, faction_id)
|
|
73
74
|
new_id = (self["Ship"].keys.map(&:to_i).max + 1).to_s
|
74
75
|
new_ship = OpenStruct.new(id: new_id, name: name)
|
75
76
|
self["Ship"][new_id] = new_ship
|
76
|
-
self["Faction"][faction_id]
|
77
|
+
self["Faction"][faction_id].ships << new_id
|
77
78
|
new_ship
|
78
79
|
end
|
@@ -21,7 +21,7 @@ BaseConnectionWithTotalCountType = BaseType.define_connection do
|
|
21
21
|
name "BasesConnectionWithTotalCount"
|
22
22
|
field :totalCount do
|
23
23
|
type types.Int
|
24
|
-
resolve ->
|
24
|
+
resolve ->(obj, args, ctx) { obj.nodes.count }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -40,7 +40,7 @@ CustomBaseEdgeType = BaseType.define_edge do
|
|
40
40
|
field :upcasedName, types.String, property: :upcased_name
|
41
41
|
field :upcasedParentName, types.String, property: :upcased_parent_name
|
42
42
|
field :edgeClassName, types.String do
|
43
|
-
resolve ->
|
43
|
+
resolve ->(obj, args, ctx) { obj.class.name }
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -49,10 +49,10 @@ CustomEdgeBaseConnectionType = BaseType.define_connection(edge_class: CustomBase
|
|
49
49
|
|
50
50
|
field :totalCountTimes100 do
|
51
51
|
type types.Int
|
52
|
-
resolve ->
|
52
|
+
resolve ->(obj, args, ctx) { obj.nodes.count * 100 }
|
53
53
|
end
|
54
54
|
|
55
|
-
field :fieldName, types.String, resolve: ->
|
55
|
+
field :fieldName, types.String, resolve: ->(obj, args, ctx) { obj.field.name }
|
56
56
|
end
|
57
57
|
|
58
58
|
Faction = GraphQL::ObjectType.define do
|
@@ -62,7 +62,7 @@ Faction = GraphQL::ObjectType.define do
|
|
62
62
|
field :id, !types.ID, resolve: GraphQL::Relay::GlobalIdResolve.new(type: Faction)
|
63
63
|
field :name, types.String
|
64
64
|
connection :ships, Ship.connection_type do
|
65
|
-
resolve ->
|
65
|
+
resolve ->(obj, args, ctx) {
|
66
66
|
all_ships = obj.ships.map {|ship_id| STAR_WARS_DATA["Ship"][ship_id] }
|
67
67
|
if args[:nameIncludes]
|
68
68
|
all_ships = all_ships.select { |ship| ship.name.include?(args[:nameIncludes])}
|
@@ -73,7 +73,7 @@ Faction = GraphQL::ObjectType.define do
|
|
73
73
|
argument :nameIncludes, types.String
|
74
74
|
end
|
75
75
|
connection :shipsWithMaxPageSize, Ship.connection_type, max_page_size: 2 do
|
76
|
-
resolve ->
|
76
|
+
resolve ->(obj, args, ctx) {
|
77
77
|
all_ships = obj.ships.map {|ship_id| STAR_WARS_DATA["Ship"][ship_id] }
|
78
78
|
if args[:nameIncludes]
|
79
79
|
all_ships = all_ships.select { |ship| ship.name.include?(args[:nameIncludes])}
|
@@ -87,7 +87,7 @@ Faction = GraphQL::ObjectType.define do
|
|
87
87
|
connection :bases, BaseConnectionWithTotalCountType do
|
88
88
|
# Resolve field should return an Array, the Connection
|
89
89
|
# will do the rest!
|
90
|
-
resolve ->
|
90
|
+
resolve ->(obj, args, ctx) {
|
91
91
|
all_bases = Base.where(id: obj.bases)
|
92
92
|
if args[:nameIncludes]
|
93
93
|
all_bases = all_bases.where("name LIKE ?", "%#{args[:nameIncludes]}%")
|
@@ -100,7 +100,7 @@ Faction = GraphQL::ObjectType.define do
|
|
100
100
|
connection :basesClone, BaseType.connection_type
|
101
101
|
connection :basesByName, BaseType.connection_type, property: :bases do
|
102
102
|
argument :order, types.String, default_value: "name"
|
103
|
-
resolve ->
|
103
|
+
resolve ->(obj, args, ctx) {
|
104
104
|
if args[:order].present?
|
105
105
|
obj.bases.order(args[:order])
|
106
106
|
else
|
@@ -110,16 +110,16 @@ Faction = GraphQL::ObjectType.define do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
connection :basesWithMaxLimitRelation, BaseType.connection_type, max_page_size: 2 do
|
113
|
-
resolve ->
|
113
|
+
resolve ->(object, args, context) { Base.all }
|
114
114
|
end
|
115
115
|
|
116
116
|
connection :basesWithMaxLimitArray, BaseType.connection_type, max_page_size: 2 do
|
117
|
-
resolve ->
|
117
|
+
resolve ->(object, args, context) { Base.all.to_a }
|
118
118
|
end
|
119
119
|
|
120
120
|
connection :basesAsSequelDataset, BaseConnectionWithTotalCountType do
|
121
121
|
argument :nameIncludes, types.String
|
122
|
-
resolve ->
|
122
|
+
resolve ->(obj, args, ctx) {
|
123
123
|
all_bases = SequelBase.where(faction_id: obj.id)
|
124
124
|
if args[:nameIncludes]
|
125
125
|
all_bases = all_bases.where("name LIKE ?", "%#{args[:nameIncludes]}%")
|
@@ -155,7 +155,7 @@ IntroduceShipMutation = GraphQL::Relay::Mutation.define do
|
|
155
155
|
return_field :faction, Faction
|
156
156
|
|
157
157
|
# Here's the mutation operation:
|
158
|
-
resolve ->
|
158
|
+
resolve ->(root_obj, inputs, ctx) {
|
159
159
|
faction_id = inputs["factionId"]
|
160
160
|
ship = STAR_WARS_DATA.create_ship(inputs["shipName"], faction_id)
|
161
161
|
faction = STAR_WARS_DATA["Faction"][faction_id]
|
@@ -169,15 +169,15 @@ end
|
|
169
169
|
QueryType = GraphQL::ObjectType.define do
|
170
170
|
name "Query"
|
171
171
|
field :rebels, Faction do
|
172
|
-
resolve ->
|
172
|
+
resolve ->(obj, args, ctx) { STAR_WARS_DATA["Faction"]["1"]}
|
173
173
|
end
|
174
174
|
|
175
175
|
field :empire, Faction do
|
176
|
-
resolve ->
|
176
|
+
resolve ->(obj, args, ctx) { STAR_WARS_DATA["Faction"]["2"]}
|
177
177
|
end
|
178
178
|
|
179
179
|
field :largestBase, BaseType do
|
180
|
-
resolve ->
|
180
|
+
resolve ->(obj, args, ctx) { Base.find(3) }
|
181
181
|
end
|
182
182
|
|
183
183
|
field :node, GraphQL::Relay::Node.field
|
@@ -193,7 +193,7 @@ StarWarsSchema = GraphQL::Schema.define do
|
|
193
193
|
query(QueryType)
|
194
194
|
mutation(MutationType)
|
195
195
|
|
196
|
-
resolve_type ->
|
196
|
+
resolve_type ->(object, ctx) {
|
197
197
|
if object == :test_error
|
198
198
|
:not_a_type
|
199
199
|
elsif object.is_a?(Base)
|
@@ -207,12 +207,12 @@ StarWarsSchema = GraphQL::Schema.define do
|
|
207
207
|
end
|
208
208
|
}
|
209
209
|
|
210
|
-
object_from_id ->
|
210
|
+
object_from_id ->(node_id, ctx) do
|
211
211
|
type_name, id = GraphQL::Schema::UniqueWithinType.decode(node_id)
|
212
212
|
STAR_WARS_DATA[type_name][id]
|
213
213
|
end
|
214
214
|
|
215
|
-
id_from_object ->
|
215
|
+
id_from_object ->(object, type, ctx) do
|
216
216
|
GraphQL::Schema::UniqueWithinType.encode(type.name, object.id)
|
217
217
|
end
|
218
218
|
end
|
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.19.
|
4
|
+
version: 0.19.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '11.0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0.44'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0.44'
|
195
209
|
- !ruby/object:Gem::Dependency
|
196
210
|
name: activerecord
|
197
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -349,6 +363,7 @@ files:
|
|
349
363
|
- lib/graphql/introspection/typename_field.rb
|
350
364
|
- lib/graphql/invalid_null_error.rb
|
351
365
|
- lib/graphql/language.rb
|
366
|
+
- lib/graphql/language/comments.rb
|
352
367
|
- lib/graphql/language/definition_slice.rb
|
353
368
|
- lib/graphql/language/generation.rb
|
354
369
|
- lib/graphql/language/lexer.rb
|
@@ -467,6 +482,7 @@ files:
|
|
467
482
|
- spec/graphql/language/definition_slice_spec.rb
|
468
483
|
- spec/graphql/language/equality_spec.rb
|
469
484
|
- spec/graphql/language/generation_spec.rb
|
485
|
+
- spec/graphql/language/lexer_spec.rb
|
470
486
|
- spec/graphql/language/nodes_spec.rb
|
471
487
|
- spec/graphql/language/parser_spec.rb
|
472
488
|
- spec/graphql/language/visitor_spec.rb
|
@@ -584,6 +600,7 @@ test_files:
|
|
584
600
|
- spec/graphql/language/definition_slice_spec.rb
|
585
601
|
- spec/graphql/language/equality_spec.rb
|
586
602
|
- spec/graphql/language/generation_spec.rb
|
603
|
+
- spec/graphql/language/lexer_spec.rb
|
587
604
|
- spec/graphql/language/nodes_spec.rb
|
588
605
|
- spec/graphql/language/parser_spec.rb
|
589
606
|
- spec/graphql/language/visitor_spec.rb
|