relay-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +26 -0
- data/lib/relay/connection/array.rb +54 -0
- data/lib/relay/connection/connection.rb +78 -0
- data/lib/relay/node/global_id_field.rb +38 -0
- data/lib/relay/node/plural_identifying_root_field.rb +35 -0
- data/lib/relay/node.rb +50 -0
- data/lib/relay/version.rb +3 -0
- data/lib/relay.rb +6 -0
- data/spec/connection/connection_spec.rb +85 -0
- data/spec/node/data.rb +69 -0
- data/spec/node/data_global.rb +78 -0
- data/spec/node/node_global_spec.rb +50 -0
- data/spec/node/node_plural_spec.rb +51 -0
- data/spec/node/node_spec.rb +106 -0
- data/spec/spec_helper.rb +96 -0
- data/spec/star_wars/connection_spec.rb +251 -0
- data/spec/star_wars/data.rb +54 -0
- data/spec/star_wars/object_identification_spec.rb +139 -0
- data/spec/star_wars/schema.rb +115 -0
- metadata +116 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'graphql'
|
2
|
+
require 'relay'
|
3
|
+
require_relative 'data'
|
4
|
+
|
5
|
+
module StarWars
|
6
|
+
|
7
|
+
|
8
|
+
NodeInterface = GraphQL::GraphQLInterfaceType.new do
|
9
|
+
name 'NodeInterface'
|
10
|
+
description 'An object with id.'
|
11
|
+
|
12
|
+
field :id, ! GraphQL::GraphQLID, description: 'The id of the object.'
|
13
|
+
|
14
|
+
resolve_type lambda { |object|
|
15
|
+
case object
|
16
|
+
when Data::Faction
|
17
|
+
FactionType
|
18
|
+
when Data::Ship
|
19
|
+
ShipType
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
NodeField = GraphQL::GraphQLField.new do
|
28
|
+
name 'node'
|
29
|
+
description 'Fetches an object given its global id.'
|
30
|
+
type NodeInterface
|
31
|
+
|
32
|
+
arg :id, ! GraphQL::GraphQLID, description: 'The global id of the object.'
|
33
|
+
|
34
|
+
resolve lambda { |object, params, context|
|
35
|
+
type, id = Relay::Node.from_global_id(params[:id])
|
36
|
+
id = id.to_i
|
37
|
+
|
38
|
+
case type
|
39
|
+
when 'Faction'
|
40
|
+
Data.faction(id)
|
41
|
+
when 'Ship'
|
42
|
+
Data.ship(id)
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
ShipEdge = GraphQL::GraphQLObjectType.new do
|
51
|
+
name 'ShipEdge'
|
52
|
+
description 'Ship edge for ships connection.'
|
53
|
+
|
54
|
+
field :node, -> { ShipType }
|
55
|
+
field :cursor, ! GraphQL::GraphQLString
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
ShipsConnection = GraphQL::GraphQLObjectType.new do
|
60
|
+
name 'ShipsConnection'
|
61
|
+
description 'A connection to a list of ships.'
|
62
|
+
|
63
|
+
field :pageInfo, ! Relay::Connection::PageInfoType
|
64
|
+
field :edges, + ShipEdge
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
ShipType = GraphQL::GraphQLObjectType.new do
|
69
|
+
name 'Ship'
|
70
|
+
description 'A ship in the Star Wars saga.'
|
71
|
+
|
72
|
+
global_id_field :id, type_name: 'Ship'
|
73
|
+
|
74
|
+
field :name, GraphQL::GraphQLString, description: 'The name of the ship.'
|
75
|
+
|
76
|
+
interface NodeInterface
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
FactionType = GraphQL::GraphQLObjectType.new do
|
81
|
+
name 'Faction'
|
82
|
+
description 'A faction in the Star Wars saga.'
|
83
|
+
|
84
|
+
global_id_field :id, type_name: 'Faction'
|
85
|
+
|
86
|
+
field :name, GraphQL::GraphQLString, description: 'The name of the faction.'
|
87
|
+
|
88
|
+
field :ships, ShipsConnection do
|
89
|
+
args Relay::Connection::ConnectionArguments
|
90
|
+
resolve lambda { |faction, params|
|
91
|
+
ships = faction.ships.map { |id| Data.ship(id) }
|
92
|
+
Relay::Connection.connection_from_array(ships, params)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
interface NodeInterface
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
QueryType = GraphQL::GraphQLObjectType.new do
|
101
|
+
name 'Query'
|
102
|
+
|
103
|
+
field :rebels, FactionType, resolve: -> { Data.rebels }
|
104
|
+
|
105
|
+
field :empire, FactionType, resolve: -> { Data.empire }
|
106
|
+
|
107
|
+
field NodeField
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
Schema = GraphQL::GraphQLSchema.new do
|
112
|
+
query QueryType
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: relay-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Kovalev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: graphql-rb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Description of Relay Ruby.
|
56
|
+
email:
|
57
|
+
- seanchas@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Rakefile
|
63
|
+
- lib/relay.rb
|
64
|
+
- lib/relay/connection/array.rb
|
65
|
+
- lib/relay/connection/connection.rb
|
66
|
+
- lib/relay/node.rb
|
67
|
+
- lib/relay/node/global_id_field.rb
|
68
|
+
- lib/relay/node/plural_identifying_root_field.rb
|
69
|
+
- lib/relay/version.rb
|
70
|
+
- spec/connection/connection_spec.rb
|
71
|
+
- spec/node/data.rb
|
72
|
+
- spec/node/data_global.rb
|
73
|
+
- spec/node/node_global_spec.rb
|
74
|
+
- spec/node/node_plural_spec.rb
|
75
|
+
- spec/node/node_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/star_wars/connection_spec.rb
|
78
|
+
- spec/star_wars/data.rb
|
79
|
+
- spec/star_wars/object_identification_spec.rb
|
80
|
+
- spec/star_wars/schema.rb
|
81
|
+
homepage: https://github.com/seanchas/relay-rb
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Summary of Relay Ruby.
|
105
|
+
test_files:
|
106
|
+
- spec/connection/connection_spec.rb
|
107
|
+
- spec/node/data.rb
|
108
|
+
- spec/node/data_global.rb
|
109
|
+
- spec/node/node_global_spec.rb
|
110
|
+
- spec/node/node_plural_spec.rb
|
111
|
+
- spec/node/node_spec.rb
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/star_wars/connection_spec.rb
|
114
|
+
- spec/star_wars/data.rb
|
115
|
+
- spec/star_wars/object_identification_spec.rb
|
116
|
+
- spec/star_wars/schema.rb
|