Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 5662d69

Browse files
committed
refactor(reactions-test): re-org wip
1 parent f3af7dd commit 5662d69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+291
-207
lines changed

cover/excoveralls.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/groupher_server/accounts/user.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule GroupherServer.Accounts.User do
44

55
use Ecto.Schema
66

7-
# import GroupherServerWeb.Schema.Utils.Helper
7+
# import GroupherServerWeb.Schema.Helper.Fields
88
import Ecto.Changeset
99

1010
alias GroupherServer.Accounts.{

lib/groupher_server_web/schema.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ defmodule GroupherServerWeb.Schema do
66
# use ApolloTracing
77

88
alias GroupherServerWeb.Middleware, as: M
9-
alias GroupherServerWeb.Schema.{Account, Billing, CMS, Delivery, Statistics, Utils}
9+
alias GroupherServerWeb.Schema.{Account, Billing, CMS, Delivery, Statistics, Helper}
1010

1111
import_types(Absinthe.Type.Custom)
1212

1313
# utils
14-
import_types(Utils.CommonTypes)
14+
import_types(Helper.CommonTypes)
1515

1616
# account
1717
import_types(Account.Types)

lib/groupher_server_web/schema/utils/common_types.ex renamed to lib/groupher_server_web/schema/Helper/common_types.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
defmodule GroupherServerWeb.Schema.Utils.CommonTypes do
1+
defmodule GroupherServerWeb.Schema.Helper.CommonTypes do
22
@moduledoc """
33
common types might be used in all context
44
"""
5-
import GroupherServerWeb.Schema.Utils.Helper
5+
import GroupherServerWeb.Schema.Helper.Fields
66

77
use Absinthe.Schema.Notation
88

lib/groupher_server_web/schema/utils/helper.ex renamed to lib/groupher_server_web/schema/Helper/fields.ex

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule GroupherServerWeb.Schema.Utils.Helper do
1+
defmodule GroupherServerWeb.Schema.Helper.Fields do
22
@moduledoc """
33
common fields
44
"""
@@ -97,46 +97,6 @@ defmodule GroupherServerWeb.Schema.Utils.Helper do
9797
end
9898
end
9999

100-
@doc """
101-
query generator for threads, like:
102-
103-
post, page_posts ...
104-
"""
105-
defmacro article_queries(thread) do
106-
quote do
107-
@desc unquote("get #{thread} by id")
108-
field unquote(thread), non_null(unquote(thread)) do
109-
arg(:id, non_null(:id))
110-
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
111-
112-
resolve(&R.CMS.read_article/3)
113-
end
114-
115-
@desc unquote("get paged #{thread}s")
116-
field unquote(:"paged_#{thread}s"), unquote(:"paged_#{thread}s") do
117-
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
118-
arg(:filter, non_null(unquote(:"paged_#{thread}s_filter")))
119-
120-
middleware(M.PageSizeProof)
121-
resolve(&R.CMS.paged_articles/3)
122-
end
123-
end
124-
end
125-
126-
defmacro article_reacted_users_query(action, resolver) do
127-
quote do
128-
@desc unquote("get paged #{action}ed users of an article")
129-
field unquote(:"#{action}ed_users"), :paged_users do
130-
arg(:id, non_null(:id))
131-
arg(:thread, :cms_thread, default_value: :post)
132-
arg(:filter, non_null(:paged_filter))
133-
134-
middleware(M.PageSizeProof)
135-
resolve(unquote(resolver))
136-
end
137-
end
138-
end
139-
140100
defmacro comments_fields do
141101
quote do
142102
field(:id, :id)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule GroupherServerWeb.Schema.Helper.Mutations do
2+
@moduledoc """
3+
common fields
4+
"""
5+
alias GroupherServerWeb.Middleware, as: M
6+
alias GroupherServerWeb.Resolvers, as: R
7+
8+
defmacro article_upvote_mutation(thread) do
9+
quote do
10+
@desc unquote("upvote to #{thread}")
11+
field unquote(:"upvote_#{thread}"), :article do
12+
arg(:id, non_null(:id))
13+
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
14+
15+
middleware(M.Authorize, :login)
16+
resolve(&R.CMS.upvote_article/3)
17+
end
18+
19+
@desc unquote("undo upvote to #{thread}")
20+
field unquote(:"undo_upvote_#{thread}"), :article do
21+
arg(:id, non_null(:id))
22+
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
23+
24+
middleware(M.Authorize, :login)
25+
resolve(&R.CMS.undo_upvote_article/3)
26+
end
27+
end
28+
end
29+
end
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
defmodule GroupherServerWeb.Schema.Helper.Queries do
2+
@moduledoc """
3+
common fields
4+
"""
5+
alias GroupherServerWeb.Middleware, as: M
6+
alias GroupherServerWeb.Resolvers, as: R
7+
8+
@doc """
9+
query generator for threads, like:
10+
11+
post, page_posts ...
12+
"""
13+
defmacro article_queries(thread) do
14+
quote do
15+
@desc unquote("get #{thread} by id")
16+
field unquote(thread), non_null(unquote(thread)) do
17+
arg(:id, non_null(:id))
18+
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
19+
20+
resolve(&R.CMS.read_article/3)
21+
end
22+
23+
@desc unquote("get paged #{thread}s")
24+
field unquote(:"paged_#{thread}s"), unquote(:"paged_#{thread}s") do
25+
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))
26+
arg(:filter, non_null(unquote(:"paged_#{thread}s_filter")))
27+
28+
middleware(M.PageSizeProof)
29+
resolve(&R.CMS.paged_articles/3)
30+
end
31+
end
32+
end
33+
34+
defmacro article_reacted_users_query(action, resolver) do
35+
quote do
36+
@desc unquote("get paged #{action}ed users of an article")
37+
field unquote(:"#{action}ed_users"), :paged_users do
38+
arg(:id, non_null(:id))
39+
arg(:thread, :cms_thread, default_value: :post)
40+
arg(:filter, non_null(:paged_filter))
41+
42+
middleware(M.PageSizeProof)
43+
resolve(unquote(resolver))
44+
end
45+
end
46+
end
47+
end

lib/groupher_server_web/schema/account/account_misc.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule GroupherServerWeb.Schema.Account.Misc do
22
@moduledoc false
33

44
use Absinthe.Schema.Notation
5-
import GroupherServerWeb.Schema.Utils.Helper
5+
import GroupherServerWeb.Schema.Helper.Fields
66

77
@desc "article_filter doc"
88
input_object :paged_users_filter do

lib/groupher_server_web/schema/account/account_types.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule GroupherServerWeb.Schema.Account.Types do
44
"""
55
use Helper.GqlSchemaSuite
66

7-
import GroupherServerWeb.Schema.Utils.Helper
7+
import GroupherServerWeb.Schema.Helper.Fields
88
import Absinthe.Resolution.Helpers
99

1010
alias GroupherServer.Accounts

lib/groupher_server_web/schema/billing/billing_types.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule GroupherServerWeb.Schema.Billing.Types do
44
"""
55
use Helper.GqlSchemaSuite
66

7-
import GroupherServerWeb.Schema.Utils.Helper
7+
import GroupherServerWeb.Schema.Helper.Fields
88

99
enum :bill_state_enum do
1010
value(:pending)

0 commit comments

Comments
 (0)