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
@@ -8,11 +8,6 @@ describe GraphQL::InterfaceType do
8
8
  assert_equal([CheeseType, HoneyType, MilkType], DummySchema.possible_types(interface))
9
9
  end
10
10
 
11
- it "resolves types for objects" do
12
- assert_equal(CheeseType, interface.resolve_type(CHEESES.values.first, dummy_query_context))
13
- assert_equal(MilkType, interface.resolve_type(MILKS.values.first, dummy_query_context))
14
- end
15
-
16
11
  describe "query evaluation" do
17
12
  let(:result) { DummySchema.execute(query_string, variables: {"cheeseId" => 2})}
18
13
  let(:query_string) {%|
@@ -40,20 +35,6 @@ describe GraphQL::InterfaceType do
40
35
  end
41
36
  end
42
37
 
43
- describe '#resolve_type' do
44
- let(:interface) {
45
- GraphQL::InterfaceType.define do
46
- resolve_type -> (object, ctx) {
47
- :custom_resolve
48
- }
49
- end
50
- }
51
-
52
- it "can be overriden in the definition" do
53
- assert_equal(interface.resolve_type(123, nil), :custom_resolve)
54
- end
55
- end
56
-
57
38
  describe "fragments" do
58
39
  let(:query_string) {%|
59
40
  {
@@ -16,7 +16,7 @@ describe GraphQL::Query::Context do
16
16
  resolve -> (target, args, ctx) { ctx.query.class.name }
17
17
  end
18
18
  }}
19
- let(:schema) { GraphQL::Schema.new(query: query_type, mutation: nil)}
19
+ let(:schema) { GraphQL::Schema.define(query: query_type, mutation: nil)}
20
20
  let(:result) { schema.execute(query_string, context: {"some_key" => "some value"})}
21
21
 
22
22
  describe "access to passed-in values" do
@@ -85,7 +85,7 @@ describe GraphQL::Query::Executor do
85
85
  end
86
86
  end
87
87
 
88
- GraphQL::Schema.new(query: DummyQueryType, mutation: MutationType)
88
+ GraphQL::Schema.define(query: DummyQueryType, mutation: MutationType)
89
89
  }
90
90
  let(:variables) { nil }
91
91
  let(:query_string) { %|
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe GraphQL::Query::SerialExecution::ValueResolution do
4
- let(:query_root) {
4
+ let(:schema) {
5
5
  day_of_week_enum = GraphQL::EnumType.define do
6
6
  name "DayOfWeek"
7
7
  value("MONDAY", value: 0)
@@ -16,10 +16,9 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
16
16
  interface = GraphQL::InterfaceType.define do
17
17
  name "SomeInterface"
18
18
  field :someField, !types.Int
19
- resolve_type ->(obj, ctx) { nil }
20
19
  end
21
20
 
22
- GraphQL::ObjectType.define do
21
+ query_root = GraphQL::ObjectType.define do
23
22
  name "Query"
24
23
  field :tomorrow, day_of_week_enum do
25
24
  argument :today, day_of_week_enum
@@ -29,8 +28,13 @@ describe GraphQL::Query::SerialExecution::ValueResolution do
29
28
  resolve ->(obj, args, ctx) { Object.new }
30
29
  end
31
30
  end
31
+
32
+ GraphQL::Schema.define do
33
+ query(query_root)
34
+ resolve_type -> (obj, ctx) { nil }
35
+ end
32
36
  }
33
- let(:schema) { GraphQL::Schema.new(query: query_root) }
37
+
34
38
  let(:result) { schema.execute(
35
39
  query_string,
36
40
  )}
@@ -33,7 +33,7 @@ describe GraphQL::Relay::ArrayConnection do
33
33
  |}
34
34
 
35
35
  it 'limits the result' do
36
- result = query(query_string, "first" => 2)
36
+ result = star_wars_query(query_string, "first" => 2)
37
37
  number_of_ships = get_names(result).length
38
38
  assert_equal(2, number_of_ships)
39
39
  assert_equal(true, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"])
@@ -41,19 +41,19 @@ describe GraphQL::Relay::ArrayConnection do
41
41
  assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"])
42
42
  assert_equal("Mg==", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"])
43
43
 
44
- result = query(query_string, "first" => 3)
44
+ result = star_wars_query(query_string, "first" => 3)
45
45
  number_of_ships = get_names(result).length
46
46
  assert_equal(3, number_of_ships)
47
47
  end
48
48
 
49
49
  it 'provides pageInfo' do
50
- result = query(query_string, "first" => 2)
50
+ result = star_wars_query(query_string, "first" => 2)
51
51
  assert_equal(true, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"])
52
52
  assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"])
53
53
  assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"])
54
54
  assert_equal("Mg==", result["data"]["rebels"]["ships"]["pageInfo"]["endCursor"])
55
55
 
56
- result = query(query_string, "first" => 100)
56
+ result = star_wars_query(query_string, "first" => 100)
57
57
  assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"])
58
58
  assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"])
59
59
  assert_equal("MQ==", result["data"]["rebels"]["ships"]["pageInfo"]["startCursor"])
@@ -61,38 +61,38 @@ describe GraphQL::Relay::ArrayConnection do
61
61
  end
62
62
 
63
63
  it 'slices the result' do
64
- result = query(query_string, "first" => 1)
64
+ result = star_wars_query(query_string, "first" => 1)
65
65
  assert_equal(["X-Wing"], get_names(result))
66
66
 
67
67
  # After the last result, find the next 2:
68
68
  last_cursor = get_last_cursor(result)
69
69
 
70
- result = query(query_string, "after" => last_cursor, "first" => 2)
70
+ result = star_wars_query(query_string, "after" => last_cursor, "first" => 2)
71
71
  assert_equal(["Y-Wing", "A-Wing"], get_names(result))
72
72
 
73
73
  # After the last result, find the next 2:
74
74
  last_cursor = get_last_cursor(result)
75
75
 
76
- result = query(query_string, "after" => last_cursor, "first" => 2)
76
+ result = star_wars_query(query_string, "after" => last_cursor, "first" => 2)
77
77
  assert_equal(["Millenium Falcon", "Home One"], get_names(result))
78
78
 
79
- result = query(query_string, "before" => last_cursor, "last" => 2)
79
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 2)
80
80
  assert_equal(["X-Wing", "Y-Wing"], get_names(result))
81
81
  end
82
82
 
83
83
  it 'applies custom arguments' do
84
- result = query(query_string, "nameIncludes" => "Wing", "first" => 2)
84
+ result = star_wars_query(query_string, "nameIncludes" => "Wing", "first" => 2)
85
85
  names = get_names(result)
86
86
  assert_equal(2, names.length)
87
87
 
88
88
  after = get_last_cursor(result)
89
- result = query(query_string, "nameIncludes" => "Wing", "after" => after, "first" => 3)
89
+ result = star_wars_query(query_string, "nameIncludes" => "Wing", "after" => after, "first" => 3)
90
90
  names = get_names(result)
91
91
  assert_equal(1, names.length)
92
92
  end
93
93
 
94
94
  it 'works without first/last/after/before' do
95
- result = query(query_string)
95
+ result = star_wars_query(query_string)
96
96
 
97
97
  assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasNextPage"])
98
98
  assert_equal(false, result["data"]["rebels"]["ships"]["pageInfo"]["hasPreviousPage"])
@@ -130,12 +130,12 @@ describe GraphQL::Relay::ArrayConnection do
130
130
  |}
131
131
 
132
132
  it "applies to queries by `first`" do
133
- result = query(query_string, "first" => 100)
133
+ result = star_wars_query(query_string, "first" => 100)
134
134
  assert_equal(["Yavin", "Echo Base"], get_names(result))
135
135
  assert_equal(true, get_page_info(result)["hasNextPage"])
136
136
 
137
137
  # Max page size is applied _without_ `first`, also
138
- result = query(query_string)
138
+ result = star_wars_query(query_string)
139
139
  assert_equal(["Yavin", "Echo Base"], get_names(result))
140
140
  assert_equal(false, get_page_info(result)["hasNextPage"], "hasNextPage is false when first is not specified")
141
141
  end
@@ -143,20 +143,20 @@ describe GraphQL::Relay::ArrayConnection do
143
143
  it "applies to queries by `last`" do
144
144
  last_cursor = "Ng=="
145
145
  second_to_last_two_names = ["Death Star", "Shield Generator"]
146
- result = query(query_string, "last" => 100, "before" => last_cursor)
146
+ result = star_wars_query(query_string, "last" => 100, "before" => last_cursor)
147
147
  assert_equal(second_to_last_two_names, get_names(result))
148
148
  assert_equal(true, get_page_info(result)["hasPreviousPage"])
149
149
 
150
- result = query(query_string, "before" => last_cursor)
150
+ result = star_wars_query(query_string, "before" => last_cursor)
151
151
  assert_equal(second_to_last_two_names, get_names(result))
152
152
  assert_equal(false, get_page_info(result)["hasPreviousPage"], "hasPreviousPage is false when last is not specified")
153
153
 
154
154
  third_cursor = "Mw=="
155
155
  first_and_second_names = ["Yavin", "Echo Base"]
156
- result = query(query_string, "last" => 100, "before" => third_cursor)
156
+ result = star_wars_query(query_string, "last" => 100, "before" => third_cursor)
157
157
  assert_equal(first_and_second_names, get_names(result))
158
158
 
159
- result = query(query_string, "before" => third_cursor)
159
+ result = star_wars_query(query_string, "before" => third_cursor)
160
160
  assert_equal(first_and_second_names, get_names(result))
161
161
  end
162
162
  end
@@ -24,7 +24,7 @@ describe GraphQL::Relay::ConnectionType do
24
24
  |}
25
25
 
26
26
  it "uses the custom edge and custom connection" do
27
- result = query(query_string)
27
+ result = star_wars_query(query_string)
28
28
  bases = result["data"]["rebels"]["basesWithCustomEdge"]
29
29
  assert_equal 300, bases["totalCountTimes100"]
30
30
  assert_equal 'basesWithCustomEdge', bases["fieldName"]
@@ -5,7 +5,7 @@ describe GraphQL::Relay::GlobalNodeIdentification do
5
5
  describe 'NodeField' do
6
6
  it 'finds objects by id' do
7
7
  global_id = node_identification.to_global_id("Faction", "1")
8
- result = query(%|{
8
+ result = star_wars_query(%|{
9
9
  node(id: "#{global_id}") {
10
10
  id,
11
11
  ... on Faction {
@@ -107,7 +107,7 @@ describe GraphQL::Relay::GlobalNodeIdentification do
107
107
 
108
108
  describe "generating IDs" do
109
109
  it "Applies custom-defined ID generation" do
110
- result = query(%| { largestBase { id } }|)
110
+ result = star_wars_query(%| { largestBase { id } }|)
111
111
  generated_id = result["data"]["largestBase"]["id"]
112
112
  assert_equal "Base/3", generated_id
113
113
  end
@@ -115,7 +115,7 @@ describe GraphQL::Relay::GlobalNodeIdentification do
115
115
 
116
116
  describe "fetching by ID" do
117
117
  it "Deconstructs the ID by the custom proc" do
118
- result = query(%| { node(id: "Base/1") { ... on Base { name } } }|)
118
+ result = star_wars_query(%| { node(id: "Base/1") { ... on Base { name } } }|)
119
119
  base_name = result["data"]["node"]["name"]
120
120
  assert_equal "Yavin", base_name
121
121
  end
@@ -128,22 +128,4 @@ describe GraphQL::Relay::GlobalNodeIdentification do
128
128
  end
129
129
  end
130
130
  end
131
-
132
- describe "type_from_object" do
133
- describe "when the return value is nil" do
134
- it "returns nil" do
135
- result = node_identification.type_from_object(123)
136
- assert_equal(nil, result)
137
- end
138
- end
139
-
140
- describe "when the return value is not a BaseType" do
141
- it "raises an error " do
142
- err = assert_raises(RuntimeError) {
143
- node_identification.type_from_object(:test_error)
144
- }
145
- assert_includes err.message, "not_a_type (Symbol)"
146
- end
147
- end
148
- end
149
131
  end
@@ -26,7 +26,7 @@ describe GraphQL::Relay::Mutation do
26
26
  end
27
27
 
28
28
  it "returns the result & clientMutationId" do
29
- result = query(query_string, "clientMutationId" => "1234")
29
+ result = star_wars_query(query_string, "clientMutationId" => "1234")
30
30
  expected = {"data" => {
31
31
  "introduceShip" => {
32
32
  "clientMutationId" => "1234",
@@ -43,7 +43,7 @@ describe GraphQL::Relay::Mutation do
43
43
  end
44
44
 
45
45
  it "doesn't require a clientMutationId to perform mutations" do
46
- result = query(query_string)
46
+ result = star_wars_query(query_string)
47
47
  new_ship_name = result["data"]["introduceShip"]["shipEdge"]["node"]["name"]
48
48
  assert_equal("Bagel", new_ship_name)
49
49
  end
@@ -14,7 +14,7 @@ describe GraphQL::Relay::PageInfo do
14
14
  end
15
15
 
16
16
  let(:cursor_of_last_base) {
17
- result = query(query_string, "first" => 100)
17
+ result = star_wars_query(query_string, "first" => 100)
18
18
  last_cursor = get_last_cursor(result)
19
19
  }
20
20
 
@@ -38,14 +38,14 @@ describe GraphQL::Relay::PageInfo do
38
38
 
39
39
  describe 'hasNextPage / hasPreviousPage' do
40
40
  it "hasNextPage is true if there are more items" do
41
- result = query(query_string, "first" => 2)
41
+ result = star_wars_query(query_string, "first" => 2)
42
42
  assert_equal(true, get_page_info(result)["hasNextPage"])
43
43
  assert_equal(false, get_page_info(result)["hasPreviousPage"], "hasPreviousPage is false if 'last' is missing")
44
44
  assert_equal("MQ==", get_page_info(result)["startCursor"])
45
45
  assert_equal("Mg==", get_page_info(result)["endCursor"])
46
46
 
47
47
  last_cursor = get_last_cursor(result)
48
- result = query(query_string, "first" => 100, "after" => last_cursor)
48
+ result = star_wars_query(query_string, "first" => 100, "after" => last_cursor)
49
49
  assert_equal(false, get_page_info(result)["hasNextPage"])
50
50
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
51
51
  assert_equal("Mw==", get_page_info(result)["startCursor"])
@@ -53,13 +53,13 @@ describe GraphQL::Relay::PageInfo do
53
53
  end
54
54
 
55
55
  it "hasPreviousPage if there are more items" do
56
- result = query(query_string, "last" => 100, "before" => cursor_of_last_base)
56
+ result = star_wars_query(query_string, "last" => 100, "before" => cursor_of_last_base)
57
57
  assert_equal(false, get_page_info(result)["hasNextPage"])
58
58
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
59
59
  assert_equal("MQ==", get_page_info(result)["startCursor"])
60
60
  assert_equal("Mg==", get_page_info(result)["endCursor"])
61
61
 
62
- result = query(query_string, "last" => 1, "before" => cursor_of_last_base)
62
+ result = star_wars_query(query_string, "last" => 1, "before" => cursor_of_last_base)
63
63
  assert_equal(false, get_page_info(result)["hasNextPage"])
64
64
  assert_equal(true, get_page_info(result)["hasPreviousPage"])
65
65
  assert_equal("Mg==", get_page_info(result)["startCursor"])
@@ -67,7 +67,7 @@ describe GraphQL::Relay::PageInfo do
67
67
  end
68
68
 
69
69
  it "has both if first and last are present" do
70
- result = query(query_string, "last" => 1, "first" => 1, "before" => cursor_of_last_base)
70
+ result = star_wars_query(query_string, "last" => 1, "first" => 1, "before" => cursor_of_last_base)
71
71
  assert_equal(true, get_page_info(result)["hasNextPage"])
72
72
  assert_equal(true, get_page_info(result)["hasPreviousPage"])
73
73
  assert_equal("Mg==", get_page_info(result)["startCursor"])
@@ -75,7 +75,7 @@ describe GraphQL::Relay::PageInfo do
75
75
  end
76
76
 
77
77
  it "startCursor and endCursor are the cursors of the first and last edge" do
78
- result = query(query_string, "first" => 2)
78
+ result = star_wars_query(query_string, "first" => 2)
79
79
  assert_equal(true, get_page_info(result)["hasNextPage"])
80
80
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
81
81
  assert_equal("MQ==", get_page_info(result)["startCursor"])
@@ -83,7 +83,7 @@ describe GraphQL::Relay::PageInfo do
83
83
  assert_equal("MQ==", get_first_cursor(result))
84
84
  assert_equal("Mg==", get_last_cursor(result))
85
85
 
86
- result = query(query_string, "first" => 1, "after" => get_page_info(result)["endCursor"])
86
+ result = star_wars_query(query_string, "first" => 1, "after" => get_page_info(result)["endCursor"])
87
87
  assert_equal(false, get_page_info(result)["hasNextPage"])
88
88
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
89
89
  assert_equal("Mw==", get_page_info(result)["startCursor"])
@@ -91,7 +91,7 @@ describe GraphQL::Relay::PageInfo do
91
91
  assert_equal("Mw==", get_first_cursor(result))
92
92
  assert_equal("Mw==", get_last_cursor(result))
93
93
 
94
- result = query(query_string, "last" => 1, "before" => get_page_info(result)["endCursor"])
94
+ result = star_wars_query(query_string, "last" => 1, "before" => get_page_info(result)["endCursor"])
95
95
  assert_equal(false, get_page_info(result)["hasNextPage"])
96
96
  assert_equal(true, get_page_info(result)["hasPreviousPage"])
97
97
  assert_equal("Mg==", get_page_info(result)["startCursor"])
@@ -46,7 +46,7 @@ describe GraphQL::Relay::RelationConnection do
46
46
  |}
47
47
 
48
48
  it 'limits the result' do
49
- result = query(query_string, "first" => 2)
49
+ result = star_wars_query(query_string, "first" => 2)
50
50
  assert_equal(2, get_names(result).length)
51
51
  assert_equal(true, get_page_info(result)["hasNextPage"])
52
52
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
@@ -55,7 +55,7 @@ describe GraphQL::Relay::RelationConnection do
55
55
  assert_equal("MQ==", get_first_cursor(result))
56
56
  assert_equal("Mg==", get_last_cursor(result))
57
57
 
58
- result = query(query_string, "first" => 3)
58
+ result = star_wars_query(query_string, "first" => 3)
59
59
  assert_equal(3, get_names(result).length)
60
60
  assert_equal(false, get_page_info(result)["hasNextPage"])
61
61
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
@@ -66,7 +66,7 @@ describe GraphQL::Relay::RelationConnection do
66
66
  end
67
67
 
68
68
  it 'provides custom fields on the connection type' do
69
- result = query(query_string, "first" => 2)
69
+ result = star_wars_query(query_string, "first" => 2)
70
70
  assert_equal(
71
71
  Base.where(faction_id: 2).count,
72
72
  result["data"]["empire"]["bases"]["totalCount"]
@@ -74,44 +74,44 @@ describe GraphQL::Relay::RelationConnection do
74
74
  end
75
75
 
76
76
  it 'slices the result' do
77
- result = query(query_string, "first" => 2)
77
+ result = star_wars_query(query_string, "first" => 2)
78
78
  assert_equal(["Death Star", "Shield Generator"], get_names(result))
79
79
 
80
80
  # After the last result, find the next 2:
81
81
  last_cursor = get_last_cursor(result)
82
82
 
83
- result = query(query_string, "after" => last_cursor, "first" => 2)
83
+ result = star_wars_query(query_string, "after" => last_cursor, "first" => 2)
84
84
  assert_equal(["Headquarters"], get_names(result))
85
85
 
86
86
  last_cursor = get_last_cursor(result)
87
87
 
88
- result = query(query_string, "before" => last_cursor, "last" => 1)
88
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 1)
89
89
  assert_equal(["Shield Generator"], get_names(result))
90
90
 
91
- result = query(query_string, "before" => last_cursor, "last" => 2)
91
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 2)
92
92
  assert_equal(["Death Star", "Shield Generator"], get_names(result))
93
93
 
94
- result = query(query_string, "before" => last_cursor, "last" => 10)
94
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 10)
95
95
  assert_equal(["Death Star", "Shield Generator"], get_names(result))
96
96
 
97
97
  end
98
98
 
99
99
  it "applies custom arguments" do
100
- result = query(query_string, "first" => 1, "nameIncludes" => "ea")
100
+ result = star_wars_query(query_string, "first" => 1, "nameIncludes" => "ea")
101
101
  assert_equal(["Death Star"], get_names(result))
102
102
 
103
103
  after = get_last_cursor(result)
104
104
 
105
- result = query(query_string, "first" => 2, "nameIncludes" => "ea", "after" => after )
105
+ result = star_wars_query(query_string, "first" => 2, "nameIncludes" => "ea", "after" => after )
106
106
  assert_equal(["Headquarters"], get_names(result))
107
107
  before = get_last_cursor(result)
108
108
 
109
- result = query(query_string, "last" => 1, "nameIncludes" => "ea", "before" => before)
109
+ result = star_wars_query(query_string, "last" => 1, "nameIncludes" => "ea", "before" => before)
110
110
  assert_equal(["Death Star"], get_names(result))
111
111
  end
112
112
 
113
113
  it 'works without first/last/after/before' do
114
- result = query(query_string)
114
+ result = star_wars_query(query_string)
115
115
 
116
116
  assert_equal(3, result["data"]["empire"]["bases"]["edges"].length)
117
117
  end
@@ -143,12 +143,12 @@ describe GraphQL::Relay::RelationConnection do
143
143
  |}
144
144
 
145
145
  it "applies to queries by `first`" do
146
- result = query(query_string, "first" => 100)
146
+ result = star_wars_query(query_string, "first" => 100)
147
147
  assert_equal(2, result["data"]["empire"]["bases"]["edges"].size)
148
148
  assert_equal(true, result["data"]["empire"]["bases"]["pageInfo"]["hasNextPage"])
149
149
 
150
150
  # Max page size is applied _without_ `first`, also
151
- result = query(query_string)
151
+ result = star_wars_query(query_string)
152
152
  assert_equal(2, result["data"]["empire"]["bases"]["edges"].size)
153
153
  assert_equal(false, result["data"]["empire"]["bases"]["pageInfo"]["hasNextPage"], "hasNextPage is false when first is not specified")
154
154
  end
@@ -156,20 +156,20 @@ describe GraphQL::Relay::RelationConnection do
156
156
  it "applies to queries by `last`" do
157
157
  last_cursor = "Ng=="
158
158
  second_to_last_two_names = ["Death Star", "Shield Generator"]
159
- result = query(query_string, "last" => 100, "before" => last_cursor)
159
+ result = star_wars_query(query_string, "last" => 100, "before" => last_cursor)
160
160
  assert_equal(second_to_last_two_names, get_names(result))
161
161
  assert_equal(true, result["data"]["empire"]["bases"]["pageInfo"]["hasPreviousPage"])
162
162
 
163
- result = query(query_string, "before" => last_cursor)
163
+ result = star_wars_query(query_string, "before" => last_cursor)
164
164
  assert_equal(second_to_last_two_names, get_names(result))
165
165
  assert_equal(false, result["data"]["empire"]["bases"]["pageInfo"]["hasPreviousPage"], "hasPreviousPage is false when last is not specified")
166
166
 
167
167
  third_cursor = "Mw=="
168
168
  first_and_second_names = ["Yavin", "Echo Base"]
169
- result = query(query_string, "last" => 100, "before" => third_cursor)
169
+ result = star_wars_query(query_string, "last" => 100, "before" => third_cursor)
170
170
  assert_equal(first_and_second_names, get_names(result))
171
171
 
172
- result = query(query_string, "before" => third_cursor)
172
+ result = star_wars_query(query_string, "before" => third_cursor)
173
173
  assert_equal(first_and_second_names, get_names(result))
174
174
  end
175
175
  end
@@ -189,7 +189,7 @@ describe GraphQL::Relay::RelationConnection do
189
189
  }
190
190
  }|}
191
191
  it "uses default resolve" do
192
- result = query(query_string)
192
+ result = star_wars_query(query_string)
193
193
  bases = result["data"]["empire"]["basesClone"]["edges"]
194
194
  assert_equal(3, bases.length)
195
195
  end
@@ -225,7 +225,7 @@ describe GraphQL::Relay::RelationConnection do
225
225
  end
226
226
 
227
227
  it "applies the default value" do
228
- result = query(query_string)
228
+ result = star_wars_query(query_string)
229
229
  bases_by_id = ["Death Star", "Shield Generator", "Headquarters"]
230
230
  bases_by_name = ["Death Star", "Headquarters", "Shield Generator"]
231
231
 
@@ -280,7 +280,7 @@ describe GraphQL::Relay::RelationConnection do
280
280
  |}
281
281
 
282
282
  it 'limits the result' do
283
- result = query(query_string, "first" => 2)
283
+ result = star_wars_query(query_string, "first" => 2)
284
284
  assert_equal(2, get_names(result).length)
285
285
  assert_equal(true, get_page_info(result)["hasNextPage"])
286
286
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
@@ -289,7 +289,7 @@ describe GraphQL::Relay::RelationConnection do
289
289
  assert_equal("MQ==", get_first_cursor(result))
290
290
  assert_equal("Mg==", get_last_cursor(result))
291
291
 
292
- result = query(query_string, "first" => 3)
292
+ result = star_wars_query(query_string, "first" => 3)
293
293
  assert_equal(3, get_names(result).length)
294
294
  assert_equal(false, get_page_info(result)["hasNextPage"])
295
295
  assert_equal(false, get_page_info(result)["hasPreviousPage"])
@@ -300,7 +300,7 @@ describe GraphQL::Relay::RelationConnection do
300
300
  end
301
301
 
302
302
  it 'provides custom fields on the connection type' do
303
- result = query(query_string, "first" => 2)
303
+ result = star_wars_query(query_string, "first" => 2)
304
304
  assert_equal(
305
305
  Base.where(faction_id: 2).count,
306
306
  result["data"]["empire"]["basesAsSequelDataset"]["totalCount"]
@@ -308,39 +308,39 @@ describe GraphQL::Relay::RelationConnection do
308
308
  end
309
309
 
310
310
  it 'slices the result' do
311
- result = query(query_string, "first" => 2)
311
+ result = star_wars_query(query_string, "first" => 2)
312
312
  assert_equal(["Death Star", "Shield Generator"], get_names(result))
313
313
 
314
314
  # After the last result, find the next 2:
315
315
  last_cursor = get_last_cursor(result)
316
316
 
317
- result = query(query_string, "after" => last_cursor, "first" => 2)
317
+ result = star_wars_query(query_string, "after" => last_cursor, "first" => 2)
318
318
  assert_equal(["Headquarters"], get_names(result))
319
319
 
320
320
  last_cursor = get_last_cursor(result)
321
321
 
322
- result = query(query_string, "before" => last_cursor, "last" => 1)
322
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 1)
323
323
  assert_equal(["Shield Generator"], get_names(result))
324
324
 
325
- result = query(query_string, "before" => last_cursor, "last" => 2)
325
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 2)
326
326
  assert_equal(["Death Star", "Shield Generator"], get_names(result))
327
327
 
328
- result = query(query_string, "before" => last_cursor, "last" => 10)
328
+ result = star_wars_query(query_string, "before" => last_cursor, "last" => 10)
329
329
  assert_equal(["Death Star", "Shield Generator"], get_names(result))
330
330
 
331
331
  end
332
332
 
333
333
  it "applies custom arguments" do
334
- result = query(query_string, "first" => 1, "nameIncludes" => "ea")
334
+ result = star_wars_query(query_string, "first" => 1, "nameIncludes" => "ea")
335
335
  assert_equal(["Death Star"], get_names(result))
336
336
 
337
337
  after = get_last_cursor(result)
338
338
 
339
- result = query(query_string, "first" => 2, "nameIncludes" => "ea", "after" => after )
339
+ result = star_wars_query(query_string, "first" => 2, "nameIncludes" => "ea", "after" => after )
340
340
  assert_equal(["Headquarters"], get_names(result))
341
341
  before = get_last_cursor(result)
342
342
 
343
- result = query(query_string, "last" => 1, "nameIncludes" => "ea", "before" => before)
343
+ result = star_wars_query(query_string, "last" => 1, "nameIncludes" => "ea", "before" => before)
344
344
  assert_equal(["Death Star"], get_names(result))
345
345
  end
346
346
  end