Skip to content

Commit

Permalink
[GraphQL] New videos entry with paginated videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed Sep 27, 2018
1 parent a0fc4ee commit aa3781a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions apps/cf_graphql/lib/resolvers/videos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ defmodule CF.GraphQL.Resolvers.Videos do
|> Result.ok()
end

def paginated_list(_root, args = %{offset: offset, limit: limit}, _info) do
Video
|> Video.query_list(Map.get(args, :filters, []))
|> Repo.paginate(page: offset, page_size: limit)
|> Result.ok()
end

# Fields

def url(video, _, _) do
Expand Down
12 changes: 11 additions & 1 deletion apps/cf_graphql/lib/schema/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ defmodule CF.GraphQL.Schema do
end

query do
@desc "Get all videos"
@desc "[Deprecated] Get all videos"
@deprecated "Please update to the paginated version (videos). This will be removed in 0.9."
@since "0.8.16"
field :all_videos, list_of(:video) do
arg(:filters, :video_filter)
arg(:limit, :integer)
resolve(&Resolvers.Videos.list/3)
end

@desc "Get all videos"
field :videos, :paginated_videos do
arg(:filters, :video_filter)
arg(:offset, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
resolve(&Resolvers.Videos.paginated_list/3)
end

@desc "Get a single video"
field :video, :video do
arg(:id, :id)
Expand Down
8 changes: 7 additions & 1 deletion apps/cf_graphql/lib/schema/types/video.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule CF.GraphQL.Schema.Types.Video do
import CF.Graphql.Schema.Utils
alias CF.GraphQL.Resolvers

import_types(CF.GraphQL.Schema.Types.{Statement, Speaker})
import_types(CF.GraphQL.Schema.Types.{Paginated, Statement, Speaker})

@desc "Identifies a video. Only Youtube is supported at the moment"
object :video do
Expand Down Expand Up @@ -38,4 +38,10 @@ defmodule CF.GraphQL.Schema.Types.Video do
complexity(join_complexity())
end
end

@desc "A list a paginated videos"
object :paginated_videos do
import_fields(:paginated)
field(:entries, list_of(:video))
end
end

0 comments on commit aa3781a

Please sign in to comment.