graphql 0.18.4 → 0.18.5

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/graphql.rb +1 -2
  3. data/lib/graphql/argument.rb +2 -2
  4. data/lib/graphql/base_type.rb +17 -0
  5. data/lib/graphql/define.rb +1 -1
  6. data/lib/graphql/directive.rb +6 -0
  7. data/lib/graphql/enum_type.rb +48 -4
  8. data/lib/graphql/field.rb +81 -19
  9. data/lib/graphql/field/resolve.rb +1 -1
  10. data/lib/graphql/input_object_type.rb +17 -3
  11. data/lib/graphql/interface_type.rb +12 -2
  12. data/lib/graphql/list_type.rb +23 -4
  13. data/lib/graphql/non_null_type.rb +27 -2
  14. data/lib/graphql/query.rb +0 -1
  15. data/lib/graphql/query/arguments.rb +1 -1
  16. data/lib/graphql/query/serial_execution/value_resolution.rb +3 -1
  17. data/lib/graphql/relay/global_node_identification.rb +29 -16
  18. data/lib/graphql/scalar_type.rb +24 -1
  19. data/lib/graphql/schema.rb +109 -19
  20. data/lib/graphql/schema/printer.rb +3 -3
  21. data/lib/graphql/static_validation/rules/argument_literals_are_compatible.rb +1 -1
  22. data/lib/graphql/union_type.rb +19 -6
  23. data/lib/graphql/version.rb +1 -1
  24. data/readme.md +5 -6
  25. data/spec/graphql/analysis/query_complexity_spec.rb +1 -1
  26. data/spec/graphql/argument_spec.rb +1 -1
  27. data/spec/graphql/field_spec.rb +1 -1
  28. data/spec/graphql/interface_type_spec.rb +0 -19
  29. data/spec/graphql/query/context_spec.rb +1 -1
  30. data/spec/graphql/query/executor_spec.rb +1 -1
  31. data/spec/graphql/query/serial_execution/value_resolution_spec.rb +8 -4
  32. data/spec/graphql/relay/array_connection_spec.rb +17 -17
  33. data/spec/graphql/relay/connection_type_spec.rb +1 -1
  34. data/spec/graphql/relay/global_node_identification_spec.rb +3 -21
  35. data/spec/graphql/relay/mutation_spec.rb +2 -2
  36. data/spec/graphql/relay/page_info_spec.rb +9 -9
  37. data/spec/graphql/relay/relation_connection_spec.rb +31 -31
  38. data/spec/graphql/schema/printer_spec.rb +1 -1
  39. data/spec/graphql/schema/reduce_types_spec.rb +1 -1
  40. data/spec/graphql/schema/timeout_middleware_spec.rb +1 -1
  41. data/spec/graphql/schema_spec.rb +18 -0
  42. data/spec/graphql/static_validation/rules/argument_literals_are_compatible_spec.rb +6 -6
  43. data/spec/graphql/union_type_spec.rb +0 -4
  44. data/spec/spec_helper.rb +1 -1
  45. data/spec/support/dairy_app.rb +13 -8
  46. data/spec/support/star_wars_schema.rb +18 -16
  47. metadata +2 -2
@@ -60,7 +60,7 @@ describe GraphQL::Schema::Printer do
60
60
  end
61
61
  end
62
62
 
63
- GraphQL::Schema.new(query: query_root)
63
+ GraphQL::Schema.define(query: query_root)
64
64
  }
65
65
 
66
66
  describe ".print_introspection_schema" do
@@ -96,7 +96,7 @@ describe GraphQL::Schema::ReduceTypes do
96
96
  end
97
97
 
98
98
  describe "when a field is only accessible through an interface" do
99
- it "is found through Schema.new(types:)" do
99
+ it "is found through Schema.define(types:)" do
100
100
  assert_equal HoneyType, DummySchema.types["Honey"]
101
101
  end
102
102
  end
@@ -35,7 +35,7 @@ describe GraphQL::Schema::TimeoutMiddleware do
35
35
  end
36
36
  end
37
37
 
38
- schema = GraphQL::Schema.new(query: query_type)
38
+ schema = GraphQL::Schema.define(query: query_type)
39
39
  schema.middleware << timeout_middleware
40
40
  schema
41
41
  }
@@ -20,4 +20,22 @@ describe GraphQL::Schema do
20
20
  assert_equal("Test", res["data"]["test"])
21
21
  end
22
22
  end
23
+
24
+ describe "#resolve_type" do
25
+ describe "when the return value is nil" do
26
+ it "returns nil" do
27
+ result = StarWarsSchema.resolve_type(123, nil)
28
+ assert_equal(nil, result)
29
+ end
30
+ end
31
+
32
+ describe "when the return value is not a BaseType" do
33
+ it "raises an error " do
34
+ err = assert_raises(RuntimeError) {
35
+ StarWarsSchema.resolve_type(:test_error, nil)
36
+ }
37
+ assert_includes err.message, "not_a_type (Symbol)"
38
+ end
39
+ end
40
+ end
23
41
  end
@@ -25,42 +25,42 @@ describe GraphQL::StaticValidation::ArgumentLiteralsAreCompatible do
25
25
  assert_equal(6, errors.length)
26
26
 
27
27
  query_root_error = {
28
- "message"=>"Argument 'id' on Field 'cheese' has an invalid value",
28
+ "message"=>"Argument 'id' on Field 'cheese' has an invalid value. Expected type 'Int!'.",
29
29
  "locations"=>[{"line"=>3, "column"=>7}],
30
30
  "path"=>["query getCheese", "cheese", "id"],
31
31
  }
32
32
  assert_includes(errors, query_root_error)
33
33
 
34
34
  directive_error = {
35
- "message"=>"Argument 'if' on Directive 'skip' has an invalid value",
35
+ "message"=>"Argument 'if' on Directive 'skip' has an invalid value. Expected type 'Boolean!'.",
36
36
  "locations"=>[{"line"=>4, "column"=>30}],
37
37
  "path"=>["query getCheese", "cheese", "source", "if"],
38
38
  }
39
39
  assert_includes(errors, directive_error)
40
40
 
41
41
  input_object_error = {
42
- "message"=>"Argument 'product' on Field 'badSource' has an invalid value",
42
+ "message"=>"Argument 'product' on Field 'badSource' has an invalid value. Expected type '[DairyProductInput]'.",
43
43
  "locations"=>[{"line"=>6, "column"=>7}],
44
44
  "path"=>["query getCheese", "badSource", "product"],
45
45
  }
46
46
  assert_includes(errors, input_object_error)
47
47
 
48
48
  input_object_field_error = {
49
- "message"=>"Argument 'source' on InputObject 'DairyProductInput' has an invalid value",
49
+ "message"=>"Argument 'source' on InputObject 'DairyProductInput' has an invalid value. Expected type 'DairyAnimal!'.",
50
50
  "locations"=>[{"line"=>6, "column"=>40}],
51
51
  "path"=>["query getCheese", "badSource", "product", "source"],
52
52
  }
53
53
  assert_includes(errors, input_object_field_error)
54
54
 
55
55
  missing_required_field_error = {
56
- "message"=>"Argument 'product' on Field 'missingSource' has an invalid value",
56
+ "message"=>"Argument 'product' on Field 'missingSource' has an invalid value. Expected type '[DairyProductInput]'.",
57
57
  "locations"=>[{"line"=>7, "column"=>7}],
58
58
  "path"=>["query getCheese", "missingSource", "product"],
59
59
  }
60
60
  assert_includes(errors, missing_required_field_error)
61
61
 
62
62
  fragment_error = {
63
- "message"=>"Argument 'source' on Field 'similarCheese' has an invalid value",
63
+ "message"=>"Argument 'source' on Field 'similarCheese' has an invalid value. Expected type '[DairyAnimal!]!'.",
64
64
  "locations"=>[{"line"=>13, "column"=>7}],
65
65
  "path"=>["fragment cheeseFields", "similarCheese", "source"],
66
66
  }
@@ -17,10 +17,6 @@ describe GraphQL::UnionType do
17
17
  assert_equal("MyUnion", union.name)
18
18
  end
19
19
 
20
- it "infers type from an object" do
21
- assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1], OpenStruct.new(schema: DummySchema)))
22
- end
23
-
24
20
  it '#include? returns true if type in in possible_types' do
25
21
  assert union.include?(type_1)
26
22
  end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,6 @@ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
20
20
  # # Load support files
21
21
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
22
22
 
23
- def query(string, variables={})
23
+ def star_wars_query(string, variables={})
24
24
  GraphQL::Query.new(StarWarsSchema, string, variables: variables).result
25
25
  end
@@ -333,11 +333,16 @@ SubscriptionType = GraphQL::ObjectType.define do
333
333
  end
334
334
  end
335
335
 
336
- DummySchema = GraphQL::Schema.new(
337
- query: DairyAppQueryType,
338
- mutation: DairyAppMutationType,
339
- subscription: SubscriptionType,
340
- max_depth: 5,
341
- types: [HoneyType, BeverageUnion],
342
- )
343
- DummySchema.rescue_from(NoSuchDairyError) { |err| err.message }
336
+ DummySchema = GraphQL::Schema.define do
337
+ query DairyAppQueryType
338
+ mutation DairyAppMutationType
339
+ subscription SubscriptionType
340
+ max_depth 5
341
+ orphan_types [HoneyType, BeverageUnion]
342
+
343
+ rescue_from(NoSuchDairyError) { |err| err.message }
344
+
345
+ resolve_type -> (obj, ctx) {
346
+ DummySchema.types[obj.class.name]
347
+ }
348
+ end
@@ -11,20 +11,6 @@ NodeIdentification = GraphQL::Relay::GlobalNodeIdentification.define do
11
11
  type_name, id = NodeIdentification.from_global_id(node_id)
12
12
  STAR_WARS_DATA[type_name][id]
13
13
  end
14
-
15
- type_from_object -> (object) do
16
- if object == :test_error
17
- :not_a_type
18
- elsif object.is_a?(Base)
19
- BaseType
20
- elsif STAR_WARS_DATA["Faction"].values.include?(object)
21
- Faction
22
- elsif STAR_WARS_DATA["Ship"].values.include?(object)
23
- Ship
24
- else
25
- nil
26
- end
27
- end
28
14
  end
29
15
 
30
16
  Ship = GraphQL::ObjectType.define do
@@ -215,5 +201,21 @@ MutationType = GraphQL::ObjectType.define do
215
201
  field :introduceShip, field: IntroduceShipMutation.field
216
202
  end
217
203
 
218
- StarWarsSchema = GraphQL::Schema.new(query: QueryType, mutation: MutationType)
219
- StarWarsSchema.node_identification = NodeIdentification
204
+ StarWarsSchema = GraphQL::Schema.define do
205
+ query(QueryType)
206
+ mutation(MutationType)
207
+ node_identification(NodeIdentification)
208
+ resolve_type -> (object, ctx) {
209
+ if object == :test_error
210
+ :not_a_type
211
+ elsif object.is_a?(Base)
212
+ BaseType
213
+ elsif STAR_WARS_DATA["Faction"].values.include?(object)
214
+ Faction
215
+ elsif STAR_WARS_DATA["Ship"].values.include?(object)
216
+ Ship
217
+ else
218
+ nil
219
+ end
220
+ }
221
+ 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.18.4
4
+ version: 0.18.5
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-08-25 00:00:00.000000000 Z
11
+ date: 2016-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter