graphql-relay 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cff9bd7fdbd2903d3d9ec7b809a6503e864e8ae
4
- data.tar.gz: 77f663466bc1cd668b9b2f95d6aa55cd094ed9f9
3
+ metadata.gz: 21069cf0c93c8778043e7e9c6fc4e4e1276ca551
4
+ data.tar.gz: cda365ce7b19852d7d8639344fba45c3ed0b5503
5
5
  SHA512:
6
- metadata.gz: cb399be33857dd51f6359d7a11c35ae0a3a8a8ea1b82d7f226db392528d96e6106c860ba867cbf68e82ba6d9eb6623134be046b6484e1765e4d0cea05e26fa1c
7
- data.tar.gz: 5fd3264c767cdf54d321f9553ca2a23a3e6818e6df4e27bdfb559a2d6ab7744a57a93e658e05f5d7c47ab25c2d467c427c1e38dcad7d4bf849344de5a68c1d9f
6
+ metadata.gz: cb9fe462db0cc0f6754e5b6e671123c4d1f9306b145a560f977dfaa4d5680e83344ff12fd7a89ef8e0d774e7523a4dd1c81fe546ce481725fcc505915e3e1405
7
+ data.tar.gz: fec3348a276e523294f19b269b55fcd9914f7170ecd6c8bbe22813fc12f2daee76f49e581db749b0eefb2d22e37def7dc208a9c7b69207a90d7b181d206a19bb
@@ -37,7 +37,7 @@ module GraphQL
37
37
  items.is_a?(items_class)
38
38
  end
39
39
  if implementation.nil?
40
- raise("No connection implementation to wrap #{items.class}")
40
+ raise("No connection implementation to wrap #{items.class} (#{items})")
41
41
  else
42
42
  implementation[1]
43
43
  end
@@ -11,7 +11,7 @@ class GraphQL::DefinitionHelpers::DefinedByConfig::DefinitionConfig
11
11
  argument :last, types.Int
12
12
  argument :before, types.String
13
13
  argument :order, types.String
14
- self.instance_eval(&block)
14
+ self.instance_eval(&block) if block_given?
15
15
  }
16
16
  connection_field = field(name, type, desc, property: property, &definition_block)
17
17
  # Wrap the defined resolve proc
@@ -19,6 +19,11 @@ class GraphQL::DefinitionHelpers::DefinedByConfig::DefinitionConfig
19
19
  original_resolve = connection_field.instance_variable_get(:@resolve_proc)
20
20
  connection_resolve = -> (obj, args, ctx) {
21
21
  items = original_resolve.call(obj, args, ctx)
22
+ if items == GraphQL::Query::DEFAULT_RESOLVE
23
+ method_name = property || name
24
+ p "Obj: #{obj} ##{method_name}"
25
+ items = obj.public_send(method_name)
26
+ end
22
27
  connection_class = GraphQL::Relay::BaseConnection.connection_for_items(items)
23
28
  connection_class.new(items, args)
24
29
  }
@@ -31,6 +36,6 @@ class GraphQL::DefinitionHelpers::DefinedByConfig::DefinitionConfig
31
36
 
32
37
  def global_id_field(field_name)
33
38
  name || raise("You must define the type's name before creating a GlobalIdField")
34
- field(name, field: GraphQL::Relay::GlobalIdField.new(name))
39
+ field(field_name, field: GraphQL::Relay::GlobalIdField.new(name))
35
40
  end
36
41
  end
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Relay
3
- VERSION = '0.3.5'
3
+ VERSION = '0.3.6'
4
4
  end
5
5
  end
@@ -117,4 +117,24 @@ describe GraphQL::Relay::RelationConnection do
117
117
  assert_equal(["Death Star"], get_names(result))
118
118
  end
119
119
  end
120
+
121
+ describe "without a block" do
122
+ let(:query_string) {%|
123
+ {
124
+ empire {
125
+ noArgsBases {
126
+ edges {
127
+ node {
128
+ name
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }|}
134
+ it "uses default resolve" do
135
+ result = query(query_string)
136
+ bases = result["data"]["empire"]["noArgsBases"]["edges"]
137
+ assert_equal(3, bases.length)
138
+ end
139
+ end
120
140
  end
@@ -10,21 +10,6 @@ names = [
10
10
  'Executor',
11
11
  ]
12
12
 
13
- rebels = OpenStruct.new({
14
- id: '1',
15
- name: 'Alliance to Restore the Republic',
16
- ships: ['1', '2', '3', '4', '5'],
17
- bases: ['11', '12']
18
- })
19
-
20
-
21
- empire = OpenStruct.new({
22
- id: '2',
23
- name: 'Galactic Empire',
24
- ships: ['6', '7', '8'],
25
- bases: ['13', '14', '15']
26
- })
27
-
28
13
  ## Set up "Bases" in ActiveRecord
29
14
  # ActiveRecord::Base.logger = Logger.new(STDOUT)
30
15
  ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
@@ -47,6 +32,22 @@ Base.create(id: 13, name: "Death Star", planet: nil, faction_id: 2)
47
32
  Base.create(id: 14, name: "Shield Generator", planet: "Endor", faction_id: 2)
48
33
  Base.create(id: 15, name: "Headquarters", planet: "Coruscant", faction_id: 2)
49
34
 
35
+
36
+ rebels = OpenStruct.new({
37
+ id: '1',
38
+ name: 'Alliance to Restore the Republic',
39
+ ships: ['1', '2', '3', '4', '5'],
40
+ bases: Base.where(faction_id: 1)
41
+ })
42
+
43
+
44
+ empire = OpenStruct.new({
45
+ id: '2',
46
+ name: 'Galactic Empire',
47
+ ships: ['6', '7', '8'],
48
+ bases: Base.where(faction_id: 2)
49
+ })
50
+
50
51
  STAR_WARS_DATA = {
51
52
  "Faction" => {
52
53
  "1" => rebels,
@@ -14,8 +14,6 @@ end
14
14
 
15
15
  NodeInterface, NodeField = GraphQL::Relay::Node.create(NodeImplementation.new)
16
16
 
17
-
18
-
19
17
  Ship = GraphQL::ObjectType.define do
20
18
  name "Ship"
21
19
  interfaces [NodeInterface]
@@ -71,6 +69,8 @@ Faction = GraphQL::ObjectType.define do
71
69
  }
72
70
  argument :nameIncludes, types.String
73
71
  end
72
+
73
+ connection :noArgsBases, BaseConnection, property: :bases
74
74
  end
75
75
 
76
76
  # Define a mutation. It will also:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-relay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.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: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql