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

Commit f7c6845

Browse files
authored
Merge pull request #29 from GraphQLAcademy/paginate-fields-on-query-root
Paginate fields on query root
2 parents 019fa99 + f70ac93 commit f7c6845

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

app/models/graph/types/query.rb

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,45 @@ module Types
55
description "The query root of this schema"
66

77
field :person, Graph.find_by_id_field(Graph::Types::Person, ::Person)
8-
field :allPeople, !types[!Person] do
9-
resolve ->(_, _, _) { ::Person.all }
8+
connection :allPeople, Person.connection_type do
9+
resolve ->(_, _, _) {
10+
::Person.all
11+
}
1012
end
1113

1214
field :planet, Graph.find_by_id_field(Graph::Types::Planet, ::Planet)
13-
field :allPlanets, !types[!Planet] do
14-
resolve ->(_, _, _) { ::Planet.all }
15+
connection :allPlanets, Planet.connection_type do
16+
resolve ->(_, _, _) {
17+
::Planet.all
18+
}
1519
end
1620

1721
field :film, Graph.find_by_id_field(Graph::Types::Film, ::Film)
18-
field :allFilms, !types[!Film] do
19-
resolve ->(_, _, _) { ::Film.all }
22+
connection :allFilms, Film.connection_type do
23+
resolve ->(_, _, _) {
24+
::Film.all
25+
}
2026
end
2127

2228
field :species, Graph.find_by_id_field(Graph::Types::Species, ::Species)
23-
field :allSpecies, !types[!Species] do
24-
resolve ->(_, _, _) { ::Species.all }
29+
connection :allSpecies, Species.connection_type do
30+
resolve ->(_, _, _) {
31+
::Species.all
32+
}
2533
end
2634

2735
field :starship, Graph.find_by_id_field(Graph::Types::Starship, ::Starship)
28-
field :allStarships, !types[!Starship] do
29-
resolve ->(_, _, _) { ::Starship.all }
36+
connection :allStarships, Starship.connection_type do
37+
resolve ->(_, _, _) {
38+
::Starship.all
39+
}
3040
end
3141

3242
field :vehicle, Graph.find_by_id_field(Graph::Types::Vehicle, ::Vehicle)
33-
field :allVehicles, !types[!Vehicle] do
34-
resolve ->(_, _, _) { ::Vehicle.all }
43+
connection :allVehicles, Vehicle.connection_type do
44+
resolve ->(_, _, _) {
45+
::Vehicle.all
46+
}
3547
end
3648

3749
# Relay

0 commit comments

Comments
 (0)