-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a56cb91
commit 5162e10
Showing
9 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule MobileAppBackendWeb.Resolvers.Route do | ||
def by_stop(%Stops.Stop{id: stop_id}, _args, _resolution) do | ||
{:ok, | ||
Routes.Repo.by_stop_with_route_pattern(stop_id) | ||
|> Enum.map(fn {route, route_patterns} -> Map.put(route, :route_patterns, route_patterns) end)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule MobileAppBackendWeb.Resolvers.Stop do | ||
def find_stop(_parent, %{id: id}, _resolution) do | ||
case Stops.Api.by_gtfs_id(id) do | ||
{:ok, stop} when not is_nil(stop) -> {:ok, stop} | ||
x -> {:error, x} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule MobileAppBackendWeb.Schema do | ||
use Absinthe.Schema | ||
import_types(MobileAppBackendWeb.Schema.RouteTypes) | ||
import_types(MobileAppBackendWeb.Schema.StopTypes) | ||
|
||
alias MobileAppBackendWeb.Resolvers | ||
|
||
query do | ||
@desc "Get a stop by ID" | ||
field :stop, :stop do | ||
arg(:id, non_null(:id)) | ||
resolve(&Resolvers.Stop.find_stop/3) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule MobileAppBackendWeb.Schema.RouteTypes do | ||
use Absinthe.Schema.Notation | ||
|
||
object :route do | ||
field(:id, non_null(:id)) | ||
field(:name, non_null(:string)) | ||
field(:long_name, non_null(:string)) | ||
|
||
field(:route_patterns, list_of(:route_pattern)) | ||
end | ||
|
||
object :route_pattern do | ||
field(:id, non_null(:id)) | ||
field(:name, non_null(:string)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule MobileAppBackendWeb.Schema.StopTypes do | ||
use Absinthe.Schema.Notation | ||
|
||
alias MobileAppBackendWeb.Resolvers | ||
|
||
object :stop do | ||
field(:id, non_null(:id)) | ||
field(:name, non_null(:string)) | ||
field(:latitude, non_null(:float)) | ||
field(:longitude, non_null(:float)) | ||
|
||
field :routes, list_of(:route) do | ||
resolve(&Resolvers.Route.by_stop/3) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters