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

Commit 6e1cc4f

Browse files
authored
Merge pull request #16 from GraphQLAcademy/film-type
Add Film Type & Species Type
2 parents a519f92 + 0043ca7 commit 6e1cc4f

11 files changed

Lines changed: 402 additions & 53 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pickle-email-*.html
1414

1515
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
1616
config/initializers/secret_token.rb
17-
config/secrets.yml
17+
# config/secrets.yml
1818

1919
# dotenv
2020
# TODO Comment out this rule if environment variables can be committed

app/models/graph/query.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/models/graph/schema.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Graph
22
Schema = GraphQL::Schema.define do
3-
query Query
3+
query Graph::Types::Query
44
end
55
end

app/models/graph/types/film.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Graph
2+
module Types
3+
Film = GraphQL::ObjectType.define do
4+
name "Film"
5+
description "A single film."
6+
7+
field :id, types.ID, "The ID of the Film."
8+
9+
field :title, types.String, "The title of this film"
10+
field :episodeID, types.Int, "The episode number of this film.", property: :episode_id
11+
field :openingCrawl, types.String,
12+
"The opening paragraphs at the beginning of this film.", property: :opening_crawl
13+
14+
field :director, types.String, "The name of the director of this film."
15+
field :producers, types[types.String] do
16+
description "The name(s) of the producer(s) of this film."
17+
resolve ->(film, _, _) { film.producer.split(", ") }
18+
end
19+
20+
field :releaseDate, types.String,
21+
"The ISO 8601 date format of film release at original creator country.", property: :release_date
22+
23+
field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created."
24+
field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was edited."
25+
26+
# TODO field :species
27+
# TODO field :starships
28+
# TODO field :vehicles
29+
# TODO field :characters
30+
# TODO field :planets
31+
end
32+
end
33+
end

app/models/graph/types/person.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Types
2525
field :homeworld, Planet, "A planet that this person was born on or inhabits."
2626
field :mass, types.Int, "The mass of the person in kilograms."
2727
field :name, types.String, "The name of this person."
28-
field :skinColor, types.String, "The skin color of this person."
28+
field :skinColor, types.String, "The skin color of this person.", property: :skin_color
2929
end
3030
end
3131
end

app/models/graph/types/query.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Graph
2+
module Types
3+
Query = GraphQL::ObjectType.define do
4+
name "Query"
5+
description "The query root of this schema"
6+
7+
field :person, Graph::Types::Person do
8+
argument :id, types.ID
9+
resolve ->(_, args, _) { ::Person.find_by(id: args['id']) }
10+
end
11+
12+
field :people, types[Graph::Types::Person] do
13+
resolve ->(_, _, _) { ::Person.all }
14+
end
15+
16+
field :planet, Graph::Types::Planet do
17+
argument :id, types.ID
18+
resolve ->(_, args, _) { ::Planet.find(args['id']) }
19+
end
20+
21+
field :planets, types[Graph::Types::Planet] do
22+
resolve ->(_, _, _) { ::Planet.all }
23+
end
24+
25+
field :film, Graph::Types::Film do
26+
argument :id, types.ID
27+
resolve ->(_, args, _) { ::Film.find(args['id']) }
28+
end
29+
30+
field :films, types[Graph::Types::Film] do
31+
resolve ->(_, _, _) { ::Film.all }
32+
end
33+
34+
field :species, Graph::Types::Species do
35+
argument :id, types.ID
36+
resolve ->(_, args, _) { ::Species.find(args['id']) }
37+
end
38+
39+
field :allSpecies, types[Graph::Types::Species] do
40+
resolve ->(_, _, _) { ::Species.all }
41+
end
42+
43+
field :starship, Graph::Types::Starship do
44+
argument :id, types.ID
45+
resolve ->(_, args, _) { ::Starship.find(args['id']) }
46+
end
47+
48+
field :starships, types[Graph::Types::Starship] do
49+
resolve ->(_, _, _) { ::Starship.all }
50+
end
51+
end
52+
end
53+
end

app/models/graph/types/species.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Graph
2+
module Types
3+
Species = GraphQL::ObjectType.define do
4+
name "Species"
5+
description "A type of person or character within the Star Wars Universe."
6+
7+
field :id, types.ID, "The ID of this species."
8+
9+
field :name, types.String, "The name of this species."
10+
field :classification, types.String, "The classification of this species, such as \"mammal\" or \"reptile\"."
11+
field :designation, types.String, "The designation of this species, such as \"sentient\"."
12+
13+
field :averageHeight, types.Float do
14+
description "The average height of this species in centimeters."
15+
property :average_height
16+
end
17+
18+
field :averageLifespan, types.Int do
19+
description "The average lifespan of this species in years, null if unknown."
20+
property :average_lifespan
21+
end
22+
23+
field :eyeColors, types[types.String] do
24+
description "Common eye colors for this species, null if this species does not typically have eyes."
25+
resolve ->(species, _, _) do
26+
return unless colors = species.eye_colors
27+
colors.split(", ")
28+
end
29+
end
30+
31+
field :hairColors, types[types.String] do
32+
description "Common hair colors for this species, null if this species does not typically have hair."
33+
resolve ->(species, _, _) do
34+
return unless colors = species.hair_colors
35+
colors.split(", ")
36+
end
37+
end
38+
39+
field :skinColors, types[types.String] do
40+
description "Common skin colors for this species, null if this species does not typically have skin."
41+
resolve ->(species, _, _) do
42+
return unless colors = species.skin_colors
43+
colors.split(", ")
44+
end
45+
end
46+
47+
field :language, types.String, "The language commonly spoken by this species."
48+
field :homeworld, Graph::Types::Planet, "A planet that this species originates from type."
49+
end
50+
end
51+
end

app/models/graph/types/starship.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module Graph
2+
module Types
3+
Starship = GraphQL::ObjectType.define do
4+
name "Starship"
5+
description "A single transport craft that has hyperdrive capability."
6+
7+
field :id, types.ID, "The ID of this species."
8+
9+
field :name, types.String, "The name of this starship. The common name, such as \"Death Star\"."
10+
field :model, types.String, "The model or official name of this starship. Such as \"T-65 X-wing\" or \"DS-1 Orbital Battle Station\"."
11+
12+
field :starshipClass, types.String do
13+
description "The class of this starship, such as \"Starfighter\" or \"Deep Space Mobile Battlestation\""
14+
property :starship_class
15+
end
16+
17+
field :manufacturer, types.String, "The manufacturer of this starship."
18+
field :costInCredits, types.Float, "The cost of this starship new, in galactic credits", property: :cost_in_credits
19+
field :length, types.Float, "The length of this starship in meters."
20+
field :crew, types.String, "The number of personnel needed to run or pilot this starship."
21+
field :passengers, types.String, "The number of non-essential people this starship can transport."
22+
23+
field :maxAtmospheringSpeed, types.Int do
24+
description "The maximum speed of this starship in atmosphere. null
25+
if this starship is incapable of atmosphering flight."
26+
property :max_atmosphering_speed
27+
end
28+
29+
field :hyperdriveRating, types.Float, "The class of this starships hyperdrive.", property: :hyperdrive_rating
30+
31+
field :MGLT, types.Int do
32+
description "
33+
The Maximum number of Megalights this starship can travel in a standard hour.
34+
A \"Megalight\" is a standard unit of distance and has never been
35+
defined before within the Star Wars universe.
36+
This figure is only really useful for measuring the difference in speed of starships.
37+
We can assume it is similar to AU, the distance between our Sun (Sol) and Earth.
38+
"
39+
property :mglt
40+
end
41+
42+
field :cargoCapacity, types.Float do
43+
description "The maximum number of kilograms that this starship can transport."
44+
property :cargo_capacity
45+
end
46+
47+
field :consumables, types.String, "The maximum length of time that this starship can provide consumables for its entire crew without having to resupply."
48+
field :pilots, types[Graph::Types::Person], "The pilots on this starship."
49+
50+
field :created_at, types.String, "The ISO 8601 date format of the time that this resource was created."
51+
field :updated_at, types.String, "The ISO 8601 date format of the time that this resource was updated."
52+
end
53+
end
54+
end

config/secrets.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
development:
2+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
3+
4+
test:
5+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
6+
7+
production:
8+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

0 commit comments

Comments
 (0)