graphql 1.8.0.pre9 → 1.8.0.pre10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/graphql/argument.rb +1 -0
- data/lib/graphql/base_type.rb +2 -0
- data/lib/graphql/compatibility/query_parser_specification.rb +110 -0
- data/lib/graphql/deprecated_dsl.rb +15 -3
- data/lib/graphql/directive.rb +1 -0
- data/lib/graphql/enum_type.rb +2 -0
- data/lib/graphql/execution/multiplex.rb +1 -1
- data/lib/graphql/field.rb +2 -0
- data/lib/graphql/introspection/entry_points.rb +2 -2
- data/lib/graphql/introspection/schema_field.rb +1 -1
- data/lib/graphql/introspection/type_by_name_field.rb +1 -1
- data/lib/graphql/language/parser.rb +25 -25
- data/lib/graphql/language/parser.y +7 -7
- data/lib/graphql/query/arguments.rb +12 -0
- data/lib/graphql/relay/mutation/instrumentation.rb +1 -1
- data/lib/graphql/relay/mutation/resolve.rb +5 -1
- data/lib/graphql/schema.rb +5 -1
- data/lib/graphql/schema/argument.rb +1 -0
- data/lib/graphql/schema/build_from_definition.rb +60 -18
- data/lib/graphql/schema/enum.rb +1 -0
- data/lib/graphql/schema/enum_value.rb +1 -0
- data/lib/graphql/schema/field.rb +44 -31
- data/lib/graphql/schema/field/dynamic_resolve.rb +4 -8
- data/lib/graphql/schema/input_object.rb +30 -19
- data/lib/graphql/schema/interface.rb +12 -5
- data/lib/graphql/schema/member.rb +10 -0
- data/lib/graphql/schema/member/build_type.rb +3 -1
- data/lib/graphql/schema/member/has_arguments.rb +50 -0
- data/lib/graphql/schema/member/has_fields.rb +1 -1
- data/lib/graphql/schema/member/instrumentation.rb +4 -4
- data/lib/graphql/schema/mutation.rb +195 -0
- data/lib/graphql/schema/object.rb +4 -5
- data/lib/graphql/schema/relay_classic_mutation.rb +85 -0
- data/lib/graphql/schema/scalar.rb +1 -0
- data/lib/graphql/schema/traversal.rb +1 -1
- data/lib/graphql/schema/union.rb +1 -0
- data/lib/graphql/subscriptions/action_cable_subscriptions.rb +1 -1
- data/lib/graphql/unresolved_type_error.rb +3 -2
- data/lib/graphql/upgrader/member.rb +194 -19
- data/lib/graphql/version.rb +1 -1
- data/spec/fixtures/upgrader/delete_project.original.rb +28 -0
- data/spec/fixtures/upgrader/delete_project.transformed.rb +27 -0
- data/spec/fixtures/upgrader/increment_count.original.rb +59 -0
- data/spec/fixtures/upgrader/increment_count.transformed.rb +50 -0
- data/spec/graphql/execution/multiplex_spec.rb +1 -1
- data/spec/graphql/language/parser_spec.rb +0 -74
- data/spec/graphql/query/serial_execution/value_resolution_spec.rb +2 -8
- data/spec/graphql/query_spec.rb +26 -0
- data/spec/graphql/relay/mutation_spec.rb +2 -2
- data/spec/graphql/schema/build_from_definition_spec.rb +59 -0
- data/spec/graphql/schema/field_spec.rb +24 -0
- data/spec/graphql/schema/input_object_spec.rb +1 -0
- data/spec/graphql/schema/interface_spec.rb +4 -1
- data/spec/graphql/schema/mutation_spec.rb +99 -0
- data/spec/graphql/schema/relay_classic_mutation_spec.rb +28 -0
- data/spec/support/jazz.rb +25 -1
- data/spec/support/star_wars/schema.rb +17 -27
- metadata +17 -2
@@ -11,6 +11,10 @@ describe GraphQL::Schema::Interface do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class NewInterface1 < Jazz::GloballyIdentifiableType
|
14
|
+
# TODO not great
|
15
|
+
module Implementation
|
16
|
+
include Jazz::GloballyIdentifiableType::Implementation
|
17
|
+
end
|
14
18
|
end
|
15
19
|
|
16
20
|
class NewInterface2 < Jazz::GloballyIdentifiableType
|
@@ -21,7 +25,6 @@ describe GraphQL::Schema::Interface do
|
|
21
25
|
end
|
22
26
|
|
23
27
|
it "can override Implementation" do
|
24
|
-
|
25
28
|
new_object_1 = Class.new(GraphQL::Schema::Object) do
|
26
29
|
implements NewInterface1
|
27
30
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
# Make sure that `!` has no effect
|
5
|
+
using GraphQL::DeprecatedDSL
|
6
|
+
|
7
|
+
describe GraphQL::Schema::Mutation do
|
8
|
+
let(:mutation) { Jazz::AddInstrument }
|
9
|
+
after do
|
10
|
+
Jazz::Models.reset
|
11
|
+
end
|
12
|
+
|
13
|
+
it "Doesn't override !" do
|
14
|
+
assert_equal false, !mutation
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "definition" do
|
18
|
+
it "passes along description" do
|
19
|
+
assert_equal "Register a new musical instrument in the database", mutation.graphql_field.description
|
20
|
+
assert_equal "Autogenerated return type of AddInstrument", mutation.payload_type.description
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".field" do
|
25
|
+
it "returns a GraphQL::Field instance, for backwards compat" do
|
26
|
+
field = mutation.field
|
27
|
+
assert_instance_of GraphQL::Field, field
|
28
|
+
assert_equal "addInstrument", field.name
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a reference to the mutation" do
|
32
|
+
f = mutation.field
|
33
|
+
assert_equal mutation, f.mutation
|
34
|
+
|
35
|
+
# Make sure it's also present in the schema
|
36
|
+
f2 = Jazz::Schema.find("Mutation.addInstrument")
|
37
|
+
assert_equal mutation, f2.mutation
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".payload_type" do
|
42
|
+
it "has a reference to the mutation" do
|
43
|
+
assert_equal mutation, mutation.payload_type.mutation
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".object_class" do
|
48
|
+
it "can override & inherit the parent class" do
|
49
|
+
obj_class = Class.new(GraphQL::Schema::Object)
|
50
|
+
mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
51
|
+
object_class(obj_class)
|
52
|
+
end
|
53
|
+
mutation_subclass = Class.new(mutation_class)
|
54
|
+
|
55
|
+
assert_equal(GraphQL::Schema::Object, GraphQL::Schema::Mutation.object_class)
|
56
|
+
assert_equal(obj_class, mutation_class.object_class)
|
57
|
+
assert_equal(obj_class, mutation_subclass.object_class) end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe ".argument_class" do
|
61
|
+
it "can override & inherit the parent class" do
|
62
|
+
arg_class = Class.new(GraphQL::Schema::Argument)
|
63
|
+
mutation_class = Class.new(GraphQL::Schema::Mutation) do
|
64
|
+
argument_class(arg_class)
|
65
|
+
end
|
66
|
+
|
67
|
+
mutation_subclass = Class.new(mutation_class)
|
68
|
+
|
69
|
+
assert_equal(GraphQL::Schema::Argument, GraphQL::Schema::Mutation.argument_class)
|
70
|
+
assert_equal(arg_class, mutation_class.argument_class)
|
71
|
+
assert_equal(arg_class, mutation_subclass.argument_class)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "evaluation" do
|
76
|
+
it "runs mutations" do
|
77
|
+
query_str = <<-GRAPHQL
|
78
|
+
mutation {
|
79
|
+
addInstrument(name: "Trombone", family: BRASS) {
|
80
|
+
instrument {
|
81
|
+
name
|
82
|
+
family
|
83
|
+
}
|
84
|
+
entries {
|
85
|
+
name
|
86
|
+
}
|
87
|
+
ee
|
88
|
+
}
|
89
|
+
}
|
90
|
+
GRAPHQL
|
91
|
+
|
92
|
+
response = Jazz::Schema.execute(query_str)
|
93
|
+
assert_equal "Trombone", response["data"]["addInstrument"]["instrument"]["name"]
|
94
|
+
assert_equal "BRASS", response["data"]["addInstrument"]["instrument"]["family"]
|
95
|
+
assert_equal "GraphQL::Query::Context::ExecutionErrors", response["data"]["addInstrument"]["ee"]
|
96
|
+
assert_equal 7, response["data"]["addInstrument"]["entries"].size
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe GraphQL::Schema::RelayClassicMutation do
|
5
|
+
describe ".input_object_class" do
|
6
|
+
it "is inherited, with a default" do
|
7
|
+
custom_input = Class.new(GraphQL::Schema::InputObject)
|
8
|
+
mutation_base_class = Class.new(GraphQL::Schema::RelayClassicMutation) do
|
9
|
+
input_object_class(custom_input)
|
10
|
+
end
|
11
|
+
mutation_subclass = Class.new(mutation_base_class)
|
12
|
+
|
13
|
+
assert_equal GraphQL::Schema::InputObject, GraphQL::Schema::RelayClassicMutation.input_object_class
|
14
|
+
assert_equal custom_input, mutation_base_class.input_object_class
|
15
|
+
assert_equal custom_input, mutation_subclass.input_object_class
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe ".input_type" do
|
20
|
+
it "has a reference to the mutation" do
|
21
|
+
mutation = Class.new(GraphQL::Schema::RelayClassicMutation) do
|
22
|
+
graphql_name "Test"
|
23
|
+
end
|
24
|
+
assert_equal mutation, mutation.input_type.mutation
|
25
|
+
assert_equal mutation, mutation.input_type.graphql_definition.mutation
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/support/jazz.rb
CHANGED
@@ -328,7 +328,9 @@ module Jazz
|
|
328
328
|
# Access by method
|
329
329
|
input.string_value,
|
330
330
|
# Access by key:
|
331
|
-
input[
|
331
|
+
input[:string_value],
|
332
|
+
input.key?(:string_value).to_s,
|
333
|
+
# Access by legacy key
|
332
334
|
input[:stringValue],
|
333
335
|
]
|
334
336
|
end
|
@@ -362,11 +364,33 @@ module Jazz
|
|
362
364
|
argument :name, String, required: true
|
363
365
|
end
|
364
366
|
|
367
|
+
class AddInstrument < GraphQL::Schema::Mutation
|
368
|
+
description "Register a new musical instrument in the database"
|
369
|
+
|
370
|
+
argument :name, String, required: true
|
371
|
+
argument :family, Family, required: true
|
372
|
+
|
373
|
+
field :instrument, InstrumentType, null: false
|
374
|
+
# This is meaningless, but it's to test the conflict with `Hash#entries`
|
375
|
+
field :entries, [InstrumentType], null: false
|
376
|
+
# Test `extras` injection
|
377
|
+
|
378
|
+
field :ee, String, null: false
|
379
|
+
extras [:execution_errors]
|
380
|
+
def resolve(name:, family:, execution_errors:)
|
381
|
+
instrument = Jazz::Models::Instrument.new(name, family)
|
382
|
+
Jazz::Models.data["Instrument"] << instrument
|
383
|
+
{ instrument: instrument, entries: Jazz::Models.data["Instrument"], ee: execution_errors.class.name}
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
365
387
|
class Mutation < BaseObject
|
366
388
|
field :add_ensemble, Ensemble, null: false do
|
367
389
|
argument :input, EnsembleInput, required: true
|
368
390
|
end
|
369
391
|
|
392
|
+
field :add_instrument, mutation: AddInstrument
|
393
|
+
|
370
394
|
def add_ensemble(input:)
|
371
395
|
ens = Models::Ensemble.new(input.name)
|
372
396
|
Models.data["Ensemble"] << ens
|
@@ -164,34 +164,21 @@ module StarWars
|
|
164
164
|
field :basesWithCustomEdge, CustomEdgeBaseConnectionType, null: true, connection: true, resolve: ->(o, a, c) { LazyNodesWrapper.new(o.bases) }
|
165
165
|
end
|
166
166
|
|
167
|
-
|
168
|
-
# - define a derived InputObjectType
|
169
|
-
# - define a derived ObjectType (for return)
|
170
|
-
# - define a field, accessible from {Mutation#field}
|
171
|
-
#
|
172
|
-
# The resolve proc takes `inputs, ctx`, where:
|
173
|
-
# - `inputs` has the keys defined with `input_field`
|
174
|
-
# - `ctx` is the Query context (like normal fields)
|
175
|
-
#
|
176
|
-
# Notice that you leave out clientMutationId.
|
177
|
-
IntroduceShipMutation = GraphQL::Relay::Mutation.define do
|
178
|
-
# Used as the root for derived types:
|
179
|
-
name "IntroduceShip"
|
167
|
+
class IntroduceShipMutation < GraphQL::Schema::RelayClassicMutation
|
180
168
|
description "Add a ship to this faction"
|
181
169
|
|
182
170
|
# Nested under `input` in the query:
|
183
|
-
|
184
|
-
|
171
|
+
argument :ship_name, String, required: false
|
172
|
+
argument :faction_id, ID, required: true
|
185
173
|
|
186
174
|
# Result may have access to these fields:
|
187
|
-
|
188
|
-
|
189
|
-
|
175
|
+
field :ship_edge, Ship.edge_type, null: true
|
176
|
+
field :faction, Faction, null: true
|
177
|
+
field :aliased_faction, Faction, hash_key: :aliased_faction, null: true
|
190
178
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
}
|
179
|
+
def resolve(ship_name: nil, faction_id:)
|
180
|
+
IntroduceShipFunction.new.call(object, {ship_name: ship_name, faction_id: faction_id}, context)
|
181
|
+
end
|
195
182
|
end
|
196
183
|
|
197
184
|
class IntroduceShipFunction < GraphQL::Function
|
@@ -207,21 +194,24 @@ module StarWars
|
|
207
194
|
end)
|
208
195
|
|
209
196
|
def call(obj, args, ctx)
|
210
|
-
|
211
|
-
|
197
|
+
# support old and new args
|
198
|
+
ship_name = args["shipName"] || args[:ship_name]
|
199
|
+
faction_id = args["factionId"] || args[:faction_id]
|
200
|
+
if ship_name == 'Millennium Falcon'
|
212
201
|
GraphQL::ExecutionError.new("Sorry, Millennium Falcon ship is reserved")
|
213
|
-
elsif
|
202
|
+
elsif ship_name == 'Leviathan'
|
214
203
|
raise GraphQL::ExecutionError.new("🔥")
|
215
|
-
elsif
|
204
|
+
elsif ship_name == "Ebon Hawk"
|
216
205
|
LazyWrapper.new { raise GraphQL::ExecutionError.new("💥")}
|
217
206
|
else
|
218
|
-
ship = DATA.create_ship(
|
207
|
+
ship = DATA.create_ship(ship_name, faction_id)
|
219
208
|
faction = DATA["Faction"][faction_id]
|
220
209
|
connection_class = GraphQL::Relay::BaseConnection.connection_for_nodes(faction.ships)
|
221
210
|
ships_connection = connection_class.new(faction.ships, args)
|
222
211
|
ship_edge = GraphQL::Relay::Edge.new(ship, ships_connection)
|
223
212
|
result = {
|
224
213
|
shipEdge: ship_edge,
|
214
|
+
ship_edge: ship_edge, # support new-style, too
|
225
215
|
faction: faction,
|
226
216
|
aliased_faction: faction,
|
227
217
|
}
|
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: 1.8.0.
|
4
|
+
version: 1.8.0.pre10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|
@@ -525,15 +525,18 @@ files:
|
|
525
525
|
- lib/graphql/schema/member.rb
|
526
526
|
- lib/graphql/schema/member/accepts_definition.rb
|
527
527
|
- lib/graphql/schema/member/build_type.rb
|
528
|
+
- lib/graphql/schema/member/has_arguments.rb
|
528
529
|
- lib/graphql/schema/member/has_fields.rb
|
529
530
|
- lib/graphql/schema/member/instrumentation.rb
|
530
531
|
- lib/graphql/schema/member/list_type_proxy.rb
|
531
532
|
- lib/graphql/schema/member/non_null_type_proxy.rb
|
532
533
|
- lib/graphql/schema/middleware_chain.rb
|
534
|
+
- lib/graphql/schema/mutation.rb
|
533
535
|
- lib/graphql/schema/null_mask.rb
|
534
536
|
- lib/graphql/schema/object.rb
|
535
537
|
- lib/graphql/schema/possible_types.rb
|
536
538
|
- lib/graphql/schema/printer.rb
|
539
|
+
- lib/graphql/schema/relay_classic_mutation.rb
|
537
540
|
- lib/graphql/schema/rescue_middleware.rb
|
538
541
|
- lib/graphql/schema/scalar.rb
|
539
542
|
- lib/graphql/schema/timeout_middleware.rb
|
@@ -907,8 +910,12 @@ files:
|
|
907
910
|
- spec/fixtures/upgrader/blame_range.transformed.rb
|
908
911
|
- spec/fixtures/upgrader/date_time.original.rb
|
909
912
|
- spec/fixtures/upgrader/date_time.transformed.rb
|
913
|
+
- spec/fixtures/upgrader/delete_project.original.rb
|
914
|
+
- spec/fixtures/upgrader/delete_project.transformed.rb
|
910
915
|
- spec/fixtures/upgrader/gist_order_field.original.rb
|
911
916
|
- spec/fixtures/upgrader/gist_order_field.transformed.rb
|
917
|
+
- spec/fixtures/upgrader/increment_count.original.rb
|
918
|
+
- spec/fixtures/upgrader/increment_count.transformed.rb
|
912
919
|
- spec/fixtures/upgrader/release_order.original.rb
|
913
920
|
- spec/fixtures/upgrader/release_order.transformed.rb
|
914
921
|
- spec/fixtures/upgrader/starrable.original.rb
|
@@ -1013,8 +1020,10 @@ files:
|
|
1013
1020
|
- spec/graphql/schema/loader_spec.rb
|
1014
1021
|
- spec/graphql/schema/member/accepts_definition_spec.rb
|
1015
1022
|
- spec/graphql/schema/middleware_chain_spec.rb
|
1023
|
+
- spec/graphql/schema/mutation_spec.rb
|
1016
1024
|
- spec/graphql/schema/object_spec.rb
|
1017
1025
|
- spec/graphql/schema/printer_spec.rb
|
1026
|
+
- spec/graphql/schema/relay_classic_mutation_spec.rb
|
1018
1027
|
- spec/graphql/schema/rescue_middleware_spec.rb
|
1019
1028
|
- spec/graphql/schema/scalar_spec.rb
|
1020
1029
|
- spec/graphql/schema/timeout_middleware_spec.rb
|
@@ -1410,8 +1419,12 @@ test_files:
|
|
1410
1419
|
- spec/fixtures/upgrader/blame_range.transformed.rb
|
1411
1420
|
- spec/fixtures/upgrader/date_time.original.rb
|
1412
1421
|
- spec/fixtures/upgrader/date_time.transformed.rb
|
1422
|
+
- spec/fixtures/upgrader/delete_project.original.rb
|
1423
|
+
- spec/fixtures/upgrader/delete_project.transformed.rb
|
1413
1424
|
- spec/fixtures/upgrader/gist_order_field.original.rb
|
1414
1425
|
- spec/fixtures/upgrader/gist_order_field.transformed.rb
|
1426
|
+
- spec/fixtures/upgrader/increment_count.original.rb
|
1427
|
+
- spec/fixtures/upgrader/increment_count.transformed.rb
|
1415
1428
|
- spec/fixtures/upgrader/release_order.original.rb
|
1416
1429
|
- spec/fixtures/upgrader/release_order.transformed.rb
|
1417
1430
|
- spec/fixtures/upgrader/starrable.original.rb
|
@@ -1516,8 +1529,10 @@ test_files:
|
|
1516
1529
|
- spec/graphql/schema/loader_spec.rb
|
1517
1530
|
- spec/graphql/schema/member/accepts_definition_spec.rb
|
1518
1531
|
- spec/graphql/schema/middleware_chain_spec.rb
|
1532
|
+
- spec/graphql/schema/mutation_spec.rb
|
1519
1533
|
- spec/graphql/schema/object_spec.rb
|
1520
1534
|
- spec/graphql/schema/printer_spec.rb
|
1535
|
+
- spec/graphql/schema/relay_classic_mutation_spec.rb
|
1521
1536
|
- spec/graphql/schema/rescue_middleware_spec.rb
|
1522
1537
|
- spec/graphql/schema/scalar_spec.rb
|
1523
1538
|
- spec/graphql/schema/timeout_middleware_spec.rb
|