graphql 0.18.5 → 0.18.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,12 @@ describe GraphQL::ObjectType do
18
18
  assert_equal([EdibleInterface, AnimalProductInterface, LocalProductInterface], type.interfaces)
19
19
  end
20
20
 
21
+ it "accepts fields definition" do
22
+ last_produced_dairy = GraphQL::Field.define(name: :last_produced_dairy, type: DairyProductUnion)
23
+ cow_type = GraphQL::ObjectType.define(name: "Cow", fields: [last_produced_dairy])
24
+ assert_equal([last_produced_dairy], cow_type.fields)
25
+ end
26
+
21
27
  describe '#get_field ' do
22
28
  it "exposes fields" do
23
29
  field = type.get_field("id")
@@ -0,0 +1,147 @@
1
+ require "spec_helper"
2
+
3
+ describe GraphQL::Schema::Loader do
4
+ let(:schema) {
5
+ node_type = GraphQL::InterfaceType.define do
6
+ name "Node"
7
+
8
+ field :id, !types.ID
9
+ end
10
+
11
+ choice_type = GraphQL::EnumType.define do
12
+ name "Choice"
13
+
14
+ value "FOO"
15
+ value "BAR"
16
+ end
17
+
18
+ sub_input_type = GraphQL::InputObjectType.define do
19
+ name "Sub"
20
+ input_field :string, types.String
21
+ end
22
+
23
+ big_int_type = GraphQL::ScalarType.define do
24
+ name "BigInt"
25
+ coerce_input -> (value) { value =~ /\d+/ ? Integer(value) : nil }
26
+ coerce_result -> (value) { value.to_s }
27
+ end
28
+
29
+ variant_input_type = GraphQL::InputObjectType.define do
30
+ name "Varied"
31
+ input_field :id, types.ID
32
+ input_field :int, types.Int
33
+ input_field :bigint, big_int_type
34
+ input_field :float, types.Float
35
+ input_field :bool, types.Boolean
36
+ input_field :enum, choice_type
37
+ input_field :sub, types[sub_input_type]
38
+ end
39
+
40
+ comment_type = GraphQL::ObjectType.define do
41
+ name "Comment"
42
+ description "A blog comment"
43
+ interfaces [node_type]
44
+
45
+ field :body, !types.String
46
+ end
47
+
48
+ post_type = GraphQL::ObjectType.define do
49
+ name "Post"
50
+ description "A blog post"
51
+
52
+ field :id, !types.ID
53
+ field :title, !types.String
54
+ field :body, !types.String
55
+ field :comments, types[!comment_type]
56
+ end
57
+
58
+ content_type = GraphQL::UnionType.define do
59
+ name "Content"
60
+ description "A post or comment"
61
+ possible_types [post_type, comment_type]
62
+ end
63
+
64
+ query_root = GraphQL::ObjectType.define do
65
+ name "Query"
66
+ description "The query root of this schema"
67
+
68
+ field :post do
69
+ type post_type
70
+ argument :id, !types.ID
71
+ argument :varied, variant_input_type, default_value: { id: "123", int: 234, float: 2.3, enum: "FOO", sub: [{ string: "str" }] }
72
+ end
73
+
74
+ field :content do
75
+ type content_type
76
+ end
77
+ end
78
+
79
+ GraphQL::Schema.new(query: query_root)
80
+ }
81
+
82
+ let(:schema_json) {
83
+ schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
84
+ }
85
+
86
+ describe "load" do
87
+ def assert_deep_equal(expected_type, actual_type)
88
+ assert_equal expected_type.class, actual_type.class
89
+
90
+ case actual_type
91
+ when Array
92
+ actual_type.each_with_index do |obj, index|
93
+ assert_deep_equal expected_type[index], obj
94
+ end
95
+
96
+ when GraphQL::Schema
97
+ assert_equal expected_type.query.name, actual_type.query.name
98
+ assert_equal expected_type.directives.keys.sort, actual_type.directives.keys.sort
99
+ assert_equal expected_type.types.keys.sort, actual_type.types.keys.sort
100
+ assert_deep_equal expected_type.types.values.sort_by(&:name), actual_type.types.values.sort_by(&:name)
101
+
102
+ when GraphQL::ObjectType, GraphQL::InterfaceType
103
+ assert_equal expected_type.name, actual_type.name
104
+ assert_equal expected_type.description, actual_type.description
105
+ assert_deep_equal expected_type.all_fields.sort_by(&:name), actual_type.all_fields.sort_by(&:name)
106
+
107
+ when GraphQL::Field
108
+ assert_equal expected_type.name, actual_type.name
109
+ assert_equal expected_type.description, actual_type.description
110
+ assert_equal expected_type.arguments.keys, actual_type.arguments.keys
111
+ assert_deep_equal expected_type.arguments.values, actual_type.arguments.values
112
+
113
+ when GraphQL::ScalarType
114
+ assert_equal expected_type.name, actual_type.name
115
+
116
+ when GraphQL::EnumType
117
+ assert_equal expected_type.name, actual_type.name
118
+ assert_equal expected_type.description, actual_type.description
119
+ assert_equal expected_type.values.keys, actual_type.values.keys
120
+ assert_deep_equal expected_type.values.values, actual_type.values.values
121
+
122
+ when GraphQL::EnumType::EnumValue
123
+ assert_equal expected_type.name, actual_type.name
124
+ assert_equal expected_type.description, actual_type.description
125
+
126
+ when GraphQL::Argument
127
+ assert_equal expected_type.name, actual_type.name
128
+ assert_equal expected_type.description, actual_type.description
129
+ assert_deep_equal expected_type.type, actual_type.type
130
+
131
+ when GraphQL::InputObjectType
132
+ assert_equal expected_type.arguments.keys, actual_type.arguments.keys
133
+ assert_deep_equal expected_type.arguments.values, actual_type.arguments.values
134
+
135
+ when GraphQL::NonNullType, GraphQL::ListType
136
+ assert_deep_equal expected_type.of_type, actual_type.of_type
137
+
138
+ else
139
+ assert_equal expected_type, actual_type
140
+ end
141
+ end
142
+
143
+ it "returns the schema" do
144
+ assert_deep_equal(schema, GraphQL::Schema::Loader.load(schema_json))
145
+ end
146
+ end
147
+ 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.5
4
+ version: 0.18.6
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-27 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
@@ -310,6 +310,7 @@ files:
310
310
  - lib/graphql/language/nodes.rb
311
311
  - lib/graphql/language/parser.rb
312
312
  - lib/graphql/language/parser.y
313
+ - lib/graphql/language/parser_tests.rb
313
314
  - lib/graphql/language/token.rb
314
315
  - lib/graphql/language/visitor.rb
315
316
  - lib/graphql/list_type.rb
@@ -346,6 +347,7 @@ files:
346
347
  - lib/graphql/schema.rb
347
348
  - lib/graphql/schema/catchall_middleware.rb
348
349
  - lib/graphql/schema/invalid_type_error.rb
350
+ - lib/graphql/schema/loader.rb
349
351
  - lib/graphql/schema/middleware_chain.rb
350
352
  - lib/graphql/schema/possible_types.rb
351
353
  - lib/graphql/schema/printer.rb
@@ -431,6 +433,7 @@ files:
431
433
  - spec/graphql/relay/relation_connection_spec.rb
432
434
  - spec/graphql/scalar_type_spec.rb
433
435
  - spec/graphql/schema/catchall_middleware_spec.rb
436
+ - spec/graphql/schema/loader_spec.rb
434
437
  - spec/graphql/schema/middleware_chain_spec.rb
435
438
  - spec/graphql/schema/printer_spec.rb
436
439
  - spec/graphql/schema/reduce_types_spec.rb
@@ -537,6 +540,7 @@ test_files:
537
540
  - spec/graphql/relay/relation_connection_spec.rb
538
541
  - spec/graphql/scalar_type_spec.rb
539
542
  - spec/graphql/schema/catchall_middleware_spec.rb
543
+ - spec/graphql/schema/loader_spec.rb
540
544
  - spec/graphql/schema/middleware_chain_spec.rb
541
545
  - spec/graphql/schema/printer_spec.rb
542
546
  - spec/graphql/schema/reduce_types_spec.rb