relay-rb 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relay/connection/connection.rb +46 -42
- data/lib/relay/version.rb +1 -1
- data/spec/connection/connection_spec.rb +12 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec87b91c9635a192ce21a0721fb344b408762a05
|
4
|
+
data.tar.gz: f4e272b8c28c13c7893f9a545e387d159a0c33d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9eacea395189fa90297b5f25a5d8ad6a16dd65d73529cc0fb964db918ba313e96c39ef68110e5b4bef6ca06e453d5fb859a53506ff996a2b8915d51cc2aea9dd
|
7
|
+
data.tar.gz: 2df31c8fb5d99dcec342670de712c0bc18ec66e6cbdb53f8a5451bc1d05406efa289af876c81784ba8d858a9ca06af0bde5f42cef610f5c22d97459376b2da02
|
@@ -10,48 +10,6 @@ module Relay
|
|
10
10
|
GraphQL::GraphQLArgument.new(:last, GraphQL::GraphQLInt)
|
11
11
|
]
|
12
12
|
|
13
|
-
class ConnectionConfiguration < GraphQL::Configuration::Base
|
14
|
-
slot :name, String
|
15
|
-
slot :node_type, GraphQL::GraphQLObjectType
|
16
|
-
slot :edge_fields, [GraphQL::GraphQLField], singular: :edge_field
|
17
|
-
slot :connection_fields, [GraphQL::GraphQLField], singular: :connection_field
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.connection_definitions(configuration)
|
21
|
-
name, node_type = configuration.name, configuration.node_type
|
22
|
-
|
23
|
-
edge_type = GraphQL::GraphQLObjectType.new do
|
24
|
-
name name + 'Edge'
|
25
|
-
description 'An edge in a connection'
|
26
|
-
|
27
|
-
field :node, node_type do
|
28
|
-
description 'The item at the end of the edge'
|
29
|
-
end
|
30
|
-
|
31
|
-
field :cursor, ! GraphQL::GraphQLString do
|
32
|
-
description 'A cursor for use in pagination'
|
33
|
-
end
|
34
|
-
|
35
|
-
fields configuration.edge_fields
|
36
|
-
end
|
37
|
-
|
38
|
-
connection_type = GraphQL::GraphQLObjectType.new do
|
39
|
-
name name + 'Connection'
|
40
|
-
description 'A connection to a list of items.'
|
41
|
-
|
42
|
-
field :pageInfo, !PageInfoType do
|
43
|
-
description 'Information to aid in pagination.'
|
44
|
-
end
|
45
|
-
|
46
|
-
field :edges, +edge_type do
|
47
|
-
description 'Information to aid in pagination.'
|
48
|
-
end
|
49
|
-
|
50
|
-
fields configuration.connection_fields
|
51
|
-
end
|
52
|
-
|
53
|
-
return edge_type, connection_type
|
54
|
-
end
|
55
13
|
|
56
14
|
PageInfoType = GraphQL::GraphQLObjectType.new do
|
57
15
|
name 'PageInfo'
|
@@ -74,5 +32,51 @@ module Relay
|
|
74
32
|
end
|
75
33
|
end
|
76
34
|
|
35
|
+
|
36
|
+
class CompositeTypeConfiguration < GraphQL::Configuration::Base
|
37
|
+
slot :name, String
|
38
|
+
slot :node_type, GraphQL::GraphQLObjectType
|
39
|
+
slot :edge_fields, [GraphQL::GraphQLField], singular: :edge_field
|
40
|
+
slot :connection_fields, [GraphQL::GraphQLField], singular: :connection_field
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
class CompositeType < GraphQL::Configuration::Configurable
|
45
|
+
configure_with CompositeTypeConfiguration
|
46
|
+
|
47
|
+
def connection
|
48
|
+
@connection ||= GraphQL::GraphQLObjectType.new(connection_arguments)
|
49
|
+
end
|
50
|
+
|
51
|
+
def edge_type
|
52
|
+
@edge_type ||= GraphQL::GraphQLObjectType.new(edge_type_arguments)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def connection_arguments
|
58
|
+
{
|
59
|
+
name: name + 'Connection',
|
60
|
+
description: 'A connection to a list of items.',
|
61
|
+
fields: @configuration.connection_fields.concat([
|
62
|
+
{ name: 'pageInfo', type: !PageInfoType, description: 'Information to aid in pagination.' },
|
63
|
+
{ name: 'edges', type: +edge_type, description: 'Information to aid in pagination.' }
|
64
|
+
])
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def edge_type_arguments
|
69
|
+
{
|
70
|
+
name: name + 'Edge',
|
71
|
+
description: 'An edge in a connection.',
|
72
|
+
fields: @configuration.edge_fields.concat([
|
73
|
+
{ name: :node, type: @configuration.node_type, description: 'The item at the end of the edge.' },
|
74
|
+
{ name: :cursor, type: !GraphQL::GraphQLString, description: 'A cursor for use in pagination.' }
|
75
|
+
])
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
77
81
|
end
|
78
82
|
end
|
data/lib/relay/version.rb
CHANGED
@@ -12,20 +12,18 @@ RSpec.describe 'Relay Connection' do
|
|
12
12
|
User.new('Tim')
|
13
13
|
]
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
resolve -> { Users.size }
|
26
|
-
end
|
15
|
+
FriendConnection = Relay::Connection::CompositeType.new do
|
16
|
+
name 'Friend'
|
17
|
+
node_type -> { ConnectionUserType }
|
18
|
+
|
19
|
+
edge_field :friendship_time, GraphQL::GraphQLString do
|
20
|
+
resolve -> { 'Yesterday' }
|
21
|
+
end
|
22
|
+
|
23
|
+
connection_field :total_count, GraphQL::GraphQLInt do
|
24
|
+
resolve -> { Users.size }
|
27
25
|
end
|
28
|
-
|
26
|
+
end
|
29
27
|
|
30
28
|
ConnectionUserType = GraphQL::GraphQLObjectType.new do
|
31
29
|
name 'User'
|
@@ -33,7 +31,7 @@ RSpec.describe 'Relay Connection' do
|
|
33
31
|
field :name, GraphQL::GraphQLString
|
34
32
|
|
35
33
|
field :friends do
|
36
|
-
type
|
34
|
+
type FriendConnection.connection
|
37
35
|
args Relay::Connection::ConnectionArguments
|
38
36
|
resolve lambda { |user, params|
|
39
37
|
Relay::Connection.connection_from_array(Users, params)
|