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 +4 -4
- data/lib/graphql/relay/base_connection.rb +1 -1
- data/lib/graphql/relay/monkey_patches/definition_config.rb +7 -2
- data/lib/graphql/relay/version.rb +1 -1
- data/spec/graphql/relay/relation_connection_spec.rb +20 -0
- data/spec/support/star_wars_data.rb +16 -15
- data/spec/support/star_wars_schema.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21069cf0c93c8778043e7e9c6fc4e4e1276ca551
|
4
|
+
data.tar.gz: cda365ce7b19852d7d8639344fba45c3ed0b5503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb9fe462db0cc0f6754e5b6e671123c4d1f9306b145a560f977dfaa4d5680e83344ff12fd7a89ef8e0d774e7523a4dd1c81fe546ce481725fcc505915e3e1405
|
7
|
+
data.tar.gz: fec3348a276e523294f19b269b55fcd9914f7170ecd6c8bbe22813fc12f2daee76f49e581db749b0eefb2d22e37def7dc208a9c7b69207a90d7b181d206a19bb
|
@@ -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(
|
39
|
+
field(field_name, field: GraphQL::Relay::GlobalIdField.new(name))
|
35
40
|
end
|
36
41
|
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.
|
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-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|