From 14fd177a2e0f6ae8ad572625494b8b32402a47f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Giroux?= Date: Sat, 11 Feb 2017 22:17:21 -0500 Subject: [PATCH 1/2] Add connectiosn to types --- app/models/graph/types/film.rb | 12 ++++++------ app/models/graph/types/person.rb | 4 ++++ app/models/graph/types/planet.rb | 3 +++ app/models/graph/types/species.rb | 3 +++ app/models/graph/types/starship.rb | 2 +- app/models/graph/types/transport_interface.rb | 2 +- app/models/graph/types/vehicle.rb | 2 +- test/controllers/graphql_controller_test.rb | 18 ------------------ 8 files changed, 19 insertions(+), 27 deletions(-) diff --git a/app/models/graph/types/film.rb b/app/models/graph/types/film.rb index 049d8c1..bb7931a 100644 --- a/app/models/graph/types/film.rb +++ b/app/models/graph/types/film.rb @@ -8,6 +8,12 @@ module Types global_id_field :id + connection :starships, Graph::Types::Starship.connection_type + connection :vehicles, Graph::Types::Vehicle.connection_type + connection :species, Graph::Types::Species.connection_type + connection :characters, Graph::Types::Person.connection_type + connection :planets, Graph::Types::Planet.connection_type + field :title, types.String, "The title of this film" field :episodeID, types.Int, "The episode number of this film.", property: :episode_id field :openingCrawl, types.String, @@ -24,12 +30,6 @@ module Types field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created." field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was edited." - - # TODO field :species - # TODO field :starships - # TODO field :vehicles - # TODO field :characters - # TODO field :planets end end end diff --git a/app/models/graph/types/person.rb b/app/models/graph/types/person.rb index aa1e5a4..7971b05 100644 --- a/app/models/graph/types/person.rb +++ b/app/models/graph/types/person.rb @@ -8,6 +8,10 @@ module Types global_id_field :id + connection :starships, Graph::Types::Starship.connection_type + connection :vehicles, Graph::Types::Vehicle.connection_type + connection :films, Graph::Types::Film.connection_type + field :birthYear, types.String, "The birth year of the person, using the in-universe standard of BBY or ABY"\ " - Before the Battle of Yavin or After the Battle of Yavin. The Battle of Yavin"\ diff --git a/app/models/graph/types/planet.rb b/app/models/graph/types/planet.rb index 283aff6..fa10d32 100644 --- a/app/models/graph/types/planet.rb +++ b/app/models/graph/types/planet.rb @@ -8,6 +8,9 @@ module Types global_id_field :id + connection :films, Graph::Types::Film.connection_type + connection :residents, Graph::Types::Person.connection_type + field :name, types.String, "The name of this planet." field :diameter, types.Int, "The diameter of this planet in kilometers." diff --git a/app/models/graph/types/species.rb b/app/models/graph/types/species.rb index ec6acad..17eb84c 100644 --- a/app/models/graph/types/species.rb +++ b/app/models/graph/types/species.rb @@ -8,6 +8,9 @@ module Types global_id_field :id + connection :people, Graph::Types::Person.connection_type + connection :films, Graph::Types::Film.connection_type + field :name, types.String, "The name of this species." field :classification, types.String, "The classification of this species, such as \"mammal\" or \"reptile\"." field :designation, types.String, "The designation of this species, such as \"sentient\"." diff --git a/app/models/graph/types/starship.rb b/app/models/graph/types/starship.rb index 5486fde..3ca8df8 100644 --- a/app/models/graph/types/starship.rb +++ b/app/models/graph/types/starship.rb @@ -51,7 +51,7 @@ module Types end field :consumables, types.String, "The maximum length of time that this starship can provide consumables for its entire crew without having to resupply." - field :pilots, types[Graph::Types::Person], "The pilots on this starship." + connection :pilots, Graph::Types::Person.connection_type field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created." field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was updated." diff --git a/app/models/graph/types/transport_interface.rb b/app/models/graph/types/transport_interface.rb index 04048a1..7c848e5 100644 --- a/app/models/graph/types/transport_interface.rb +++ b/app/models/graph/types/transport_interface.rb @@ -14,7 +14,7 @@ module Types field :maxAtmospheringSpeed, types.Int field :cargoCapacity, types.Float field :consumables, types.String - field :pilots, types[Graph::Types::Person] + connection :pilots, Graph::Types::Person.connection_type end end end diff --git a/app/models/graph/types/vehicle.rb b/app/models/graph/types/vehicle.rb index d03944c..9343008 100644 --- a/app/models/graph/types/vehicle.rb +++ b/app/models/graph/types/vehicle.rb @@ -37,7 +37,7 @@ module Types end field :consumables, types.String, "The maximum length of time that this vehicle can provide consumables for its entire crew without having to resupply." - field :pilots, types[Graph::Types::Person], "The pilots on this vehicle." + connection :pilots, Graph::Types::Person.connection_type field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created." field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was updated." diff --git a/test/controllers/graphql_controller_test.rb b/test/controllers/graphql_controller_test.rb index 4d81ed0..a70f06a 100644 --- a/test/controllers/graphql_controller_test.rb +++ b/test/controllers/graphql_controller_test.rb @@ -66,16 +66,6 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest "manufacturer" => "Corellian Engineering Corporation", "maxAtmospheringSpeed" => 1050, "passengers" => "6", - "pilots" => [ - { "name" => "Chewbacca" }, - { "name" => "Han Solo" }, - { "name" => "Lando Calrissian" }, - { "name" => "Nien Nunb" }, - { "name" => "Chewbacca" }, - { "name" => "Han Solo" }, - { "name" => "Lando Calrissian" }, - { "name" => "Nien Nunb" } - ], "starshipClass" => "Light freighter" }, "vehicle" => { @@ -91,12 +81,6 @@ class GraphQLControllerTest < ActionDispatch::IntegrationTest "manufacturer" => "Incom corporation", "maxAtmospheringSpeed" => 650, "passengers" => "0", - "pilots" => [ - { "name" => "Luke Skywalker" }, - { "name" => "Wedge Antilles" }, - { "name" => "Luke Skywalker" }, - { "name" => "Wedge Antilles" }, - ], "vehicleClass"=>"airspeeder" } } @@ -190,7 +174,6 @@ def full_graphql_query manufacturer maxAtmospheringSpeed passengers - pilots { name } starshipClass } vehicle(id: $vehicleID) { @@ -206,7 +189,6 @@ def full_graphql_query manufacturer maxAtmospheringSpeed passengers - pilots { name } vehicleClass } } From b956b13f044e9130118acfa1aef31c9dff0d0905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Giroux?= Date: Sun, 12 Feb 2017 12:53:13 -0500 Subject: [PATCH 2/2] yoloest fix ever --- config/initializers/graphql.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 config/initializers/graphql.rb diff --git a/config/initializers/graphql.rb b/config/initializers/graphql.rb new file mode 100644 index 0000000..f3f8599 --- /dev/null +++ b/config/initializers/graphql.rb @@ -0,0 +1,10 @@ +# TODO(xuorig) remove this when +# https://github.com/rmosolgo/graphql-ruby/pull/535 is fixed +module GraphQL + class BaseType + def connection_type + name # lolwat + @connection_type ||= define_connection + end + end +end