File tree Expand file tree Collapse file tree 4 files changed +73
-2
lines changed
elixir_boilerplate_graphql
elixir_boilerplate/planning Expand file tree Collapse file tree 4 files changed +73
-2
lines changed Original file line number Diff line number Diff line change 1+ defmodule ElixirBoilerplate.Planning do
2+ alias ElixirBoilerplate.Planning.Project
3+ alias ElixirBoilerplate.Repo
4+
5+ import Ecto.Query
6+
7+ def list ( ) do
8+ projects =
9+ queryable ( )
10+ |> Repo . all ( )
11+
12+ { :ok , projects }
13+ end
14+
15+ def get ( project_id ) do
16+ project =
17+ queryable ( )
18+ |> where ( id: ^ project_id )
19+ |> Repo . one ( )
20+
21+ { :ok , project }
22+ end
23+
24+ defp queryable ( ) do
25+ from ( p in Project ,
26+ join: t in assoc ( p , :tasks ) ,
27+ order_by: [ asc: field ( t , :priority ) ] ,
28+ preload: [ tasks: t ]
29+ )
30+ end
31+ end
Original file line number Diff line number Diff line change 11defmodule ElixirBoilerplate.Planning.Project do
22 use ElixirBoilerplate.Schema
33
4+ alias ElixirBoilerplate.Planning.Task
5+
46 schema "projects" do
57 field :description , :string
6- field :launch_at , :naive_datetime
7- field :next_milestone_at , :naive_datetime
8+ field :launch_at , :utc_datetime
9+ field :next_milestone_at , :utc_datetime
810 field :title , :string
911
12+ has_many :tasks , Task
13+
1014 timestamps ( )
1115 end
1216
Original file line number Diff line number Diff line change 1+ defmodule ElixirBoilerplateGraphQL.Planning.Types do
2+ use Absinthe.Schema.Notation
3+
4+ object :project do
5+ @ desc "A sample project"
6+ field ( :id , :id )
7+ field ( :title , :string )
8+ field ( :description , :string )
9+ field ( :launch_at , :datetime )
10+ field ( :tasks , list_of ( :task ) )
11+ end
12+
13+ object :task do
14+ @ desc "A sample task"
15+ field ( :id , :id )
16+ field ( :description , :string )
17+ field ( :priority , :integer )
18+ field ( :due_at , :datetime )
19+ end
20+
21+ object :planning_queries do
22+ @ desc "A list of projects"
23+ field :projects , list_of ( :project ) do
24+ resolve ( fn _parent , _args , _resolution -> ElixirBoilerplate.Planning . list ( ) end )
25+ end
26+
27+ @ desc "A project"
28+ field :project , :project do
29+ arg ( :id , :id )
30+ resolve ( fn _parent , % { id: id } , _resolution -> ElixirBoilerplate.Planning . get ( id ) end )
31+ end
32+ end
33+ end
Original file line number Diff line number Diff line change @@ -3,16 +3,19 @@ defmodule ElixirBoilerplateGraphQL.Schema do
33
44 import_types ( Absinthe.Type.Custom )
55 import_types ( ElixirBoilerplateGraphQL.Application.Types )
6+ import_types ( ElixirBoilerplateGraphQL.Planning.Types )
67
78 query do
89 import_fields ( :application_queries )
10+ import_fields ( :planning_queries )
911 end
1012
1113 # Having an empty mutation block is invalid and raises an error in Absinthe.
1214 # Uncomment it when you add the first mutation.
1315 #
1416 # mutation do
1517 # import_fields(:application_mutations)
18+ # import_fields(:planning_mutations)
1619 # end
1720
1821 def context ( context ) do
You can’t perform that action at this time.
0 commit comments