Skip to content
This repository was archived by the owner on Sep 24, 2019. It is now read-only.

Commit be0cfe9

Browse files
authored
Merge pull request #24 from GraphQLAcademy/connections
Add connectiosn to types
2 parents 46776b8 + b956b13 commit be0cfe9

File tree

9 files changed

+29
-27
lines changed

9 files changed

+29
-27
lines changed

app/models/graph/types/film.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ module Types
88

99
global_id_field :id
1010

11+
connection :starships, Graph::Types::Starship.connection_type
12+
connection :vehicles, Graph::Types::Vehicle.connection_type
13+
connection :species, Graph::Types::Species.connection_type
14+
connection :characters, Graph::Types::Person.connection_type
15+
connection :planets, Graph::Types::Planet.connection_type
16+
1117
field :title, types.String, "The title of this film"
1218
field :episodeID, types.Int, "The episode number of this film.", property: :episode_id
1319
field :openingCrawl, types.String,
@@ -24,12 +30,6 @@ module Types
2430

2531
field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created."
2632
field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was edited."
27-
28-
# TODO field :species
29-
# TODO field :starships
30-
# TODO field :vehicles
31-
# TODO field :characters
32-
# TODO field :planets
3333
end
3434
end
3535
end

app/models/graph/types/person.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module Types
88

99
global_id_field :id
1010

11+
connection :starships, Graph::Types::Starship.connection_type
12+
connection :vehicles, Graph::Types::Vehicle.connection_type
13+
connection :films, Graph::Types::Film.connection_type
14+
1115
field :birthYear, types.String,
1216
"The birth year of the person, using the in-universe standard of BBY or ABY"\
1317
" - Before the Battle of Yavin or After the Battle of Yavin. The Battle of Yavin"\

app/models/graph/types/planet.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Types
88

99
global_id_field :id
1010

11+
connection :films, Graph::Types::Film.connection_type
12+
connection :residents, Graph::Types::Person.connection_type
13+
1114
field :name, types.String, "The name of this planet."
1215
field :diameter, types.Int, "The diameter of this planet in kilometers."
1316

app/models/graph/types/species.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Types
88

99
global_id_field :id
1010

11+
connection :people, Graph::Types::Person.connection_type
12+
connection :films, Graph::Types::Film.connection_type
13+
1114
field :name, types.String, "The name of this species."
1215
field :classification, types.String, "The classification of this species, such as \"mammal\" or \"reptile\"."
1316
field :designation, types.String, "The designation of this species, such as \"sentient\"."

app/models/graph/types/starship.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Types
5151
end
5252

5353
field :consumables, types.String, "The maximum length of time that this starship can provide consumables for its entire crew without having to resupply."
54-
field :pilots, types[Graph::Types::Person], "The pilots on this starship."
54+
connection :pilots, Graph::Types::Person.connection_type
5555

5656
field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created."
5757
field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was updated."

app/models/graph/types/transport_interface.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Types
1414
field :maxAtmospheringSpeed, types.Int
1515
field :cargoCapacity, types.Float
1616
field :consumables, types.String
17-
field :pilots, types[Graph::Types::Person]
17+
connection :pilots, Graph::Types::Person.connection_type
1818
end
1919
end
2020
end

app/models/graph/types/vehicle.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module Types
3737
end
3838

3939
field :consumables, types.String, "The maximum length of time that this vehicle can provide consumables for its entire crew without having to resupply."
40-
field :pilots, types[Graph::Types::Person], "The pilots on this vehicle."
40+
connection :pilots, Graph::Types::Person.connection_type
4141

4242
field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created."
4343
field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was updated."

config/initializers/graphql.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TODO(xuorig) remove this when
2+
# https://github.com/rmosolgo/graphql-ruby/pull/535 is fixed
3+
module GraphQL
4+
class BaseType
5+
def connection_type
6+
name # lolwat
7+
@connection_type ||= define_connection
8+
end
9+
end
10+
end

test/controllers/graphql_controller_test.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest
6666
"manufacturer" => "Corellian Engineering Corporation",
6767
"maxAtmospheringSpeed" => 1050,
6868
"passengers" => "6",
69-
"pilots" => [
70-
{ "name" => "Chewbacca" },
71-
{ "name" => "Han Solo" },
72-
{ "name" => "Lando Calrissian" },
73-
{ "name" => "Nien Nunb" },
74-
{ "name" => "Chewbacca" },
75-
{ "name" => "Han Solo" },
76-
{ "name" => "Lando Calrissian" },
77-
{ "name" => "Nien Nunb" }
78-
],
7969
"starshipClass" => "Light freighter"
8070
},
8171
"vehicle" => {
@@ -91,12 +81,6 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest
9181
"manufacturer" => "Incom corporation",
9282
"maxAtmospheringSpeed" => 650,
9383
"passengers" => "0",
94-
"pilots" => [
95-
{ "name" => "Luke Skywalker" },
96-
{ "name" => "Wedge Antilles" },
97-
{ "name" => "Luke Skywalker" },
98-
{ "name" => "Wedge Antilles" },
99-
],
10084
"vehicleClass"=>"airspeeder"
10185
}
10286
}
@@ -190,7 +174,6 @@ def full_graphql_query
190174
manufacturer
191175
maxAtmospheringSpeed
192176
passengers
193-
pilots { name }
194177
starshipClass
195178
}
196179
vehicle(id: $vehicleID) {
@@ -206,7 +189,6 @@ def full_graphql_query
206189
manufacturer
207190
maxAtmospheringSpeed
208191
passengers
209-
pilots { name }
210192
vehicleClass
211193
}
212194
}

0 commit comments

Comments
 (0)