File tree 4 files changed +73
-2
lines changed
elixir_boilerplate/planning
elixir_boilerplate_graphql
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 1
1
defmodule ElixirBoilerplate.Planning.Project do
2
2
use ElixirBoilerplate.Schema
3
3
4
+ alias ElixirBoilerplate.Planning.Task
5
+
4
6
schema "projects" do
5
7
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
8
10
field :title , :string
9
11
12
+ has_many :tasks , Task
13
+
10
14
timestamps ( )
11
15
end
12
16
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
3
3
4
4
import_types ( Absinthe.Type.Custom )
5
5
import_types ( ElixirBoilerplateGraphQL.Application.Types )
6
+ import_types ( ElixirBoilerplateGraphQL.Planning.Types )
6
7
7
8
query do
8
9
import_fields ( :application_queries )
10
+ import_fields ( :planning_queries )
9
11
end
10
12
11
13
# Having an empty mutation block is invalid and raises an error in Absinthe.
12
14
# Uncomment it when you add the first mutation.
13
15
#
14
16
# mutation do
15
17
# import_fields(:application_mutations)
18
+ # import_fields(:planning_mutations)
16
19
# end
17
20
18
21
def context ( context ) do
You can’t perform that action at this time.
0 commit comments