Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitaf04839

Browse files
authored
refactor(schema): make schema article unrelated (#388)
* refactor(schema): wip* refactor(schema): wip* chore: wip
1 parent02f4663 commitaf04839

File tree

6 files changed

+233
-93
lines changed

6 files changed

+233
-93
lines changed

‎lib/groupher_server_web/schema.ex‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule GroupherServerWeb.Schema do
44
"""
55
useAbsinthe.Schema
66
# use ApolloTracing
7+
importGroupherServerWeb.Schema.Helper.Imports
78

89
aliasGroupherServerWeb.Middleware,as:M
910
aliasGroupherServerWeb.Schema.{Account,Billing,CMS,Delivery,Statistics,Helper}
@@ -38,11 +39,11 @@ defmodule GroupherServerWeb.Schema do
3839
import_types(CMS.Queries)
3940
import_types(CMS.Mutations.Community)
4041
import_types(CMS.Mutations.Operation)
41-
import_types(CMS.Mutations.Post)
42-
import_types(CMS.Mutations.Job)
43-
import_types(CMS.Mutations.Repo)
42+
4443
import_types(CMS.Mutations.Comment)
4544

45+
import_article_fields(:mutations,:module)
46+
4647
querydo
4748
import_fields(:account_queries)
4849
import_fields(:billing_queries)
@@ -63,9 +64,8 @@ defmodule GroupherServerWeb.Schema do
6364
# cms
6465
import_fields(:cms_mutation_community)
6566
import_fields(:cms_opertion_mutations)
66-
import_fields(:cms_post_mutations)
67-
import_fields(:cms_job_mutations)
68-
import_fields(:cms_repo_mutations)
67+
68+
import_article_fields(:mutations)
6969

7070
import_fields(:cms_comment_mutations)
7171
end

‎lib/groupher_server_web/schema/Helper/fields.ex‎

Lines changed: 95 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
defmoduleGroupherServerWeb.Schema.Helper.Fieldsdo
22
@moduledoc"""
3-
common fields
3+
general fields used in schema definition
44
"""
55
importHelper.Utils,only:[get_config:2]
6+
importAbsinthe.Resolution.Helpers,only:[dataloader:2]
67

78
aliasGroupherServer.CMS
9+
aliasGroupherServerWeb.Middleware,as:M
10+
aliasGroupherServerWeb.Resolvers,as:R
811

912
@page_sizeget_config(:general,:page_size)
10-
@supported_emotionsget_config(:article,:emotions)
11-
@supported_comment_emotionsget_config(:article,:comment_emotions)
1213

14+
@emotionsget_config(:article,:emotions)
15+
@comment_emotionsget_config(:article,:comment_emotions)
1316
@article_threadsget_config(:article,:threads)
1417

1518
@doc"general article fields for grqphql resolve fields"
@@ -38,24 +41,95 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
3841
end
3942
end
4043

44+
@doc"""
45+
generate thread enum based on @article_threads
46+
47+
e.g:
48+
49+
enum :post_thread, do: value(:post)
50+
enum :job_thread, do: value(:job)
51+
# ..
52+
"""
4153
defmacroarticle_thread_enumsdo
4254
@article_threads
43-
|>Enum.map(fnthread->
44-
quotedo
45-
enum(unquote(:"#{thread}_thread"),do:value(unquote(thread)))
55+
|>Enum.map(
56+
&quotedo
57+
enum(unquote(:"#{&1}_thread"),do:value(unquote(&1)))
4658
end
47-
end)
59+
)
4860
end
4961

62+
@doc"""
63+
generate thread value based on @article_threads
64+
65+
e.g:
66+
67+
value(:post)
68+
value(:job)
69+
# ...
70+
"""
5071
defmacroarticle_valuesdo
5172
@article_threads
52-
|>Enum.map(fnthread->
53-
quotedo
54-
value(unquote(thread))
73+
|>Enum.map(
74+
&quotedo
75+
value(unquote(&1))
5576
end
56-
end)
77+
)
78+
end
79+
80+
@doc"""
81+
general emotion enum for articles
82+
#NOTE: xxx_user_logins field is not support for gq-endpoint
83+
"""
84+
defmacroemotion_values(metric\\:article)do
85+
emotions=
86+
casemetricdo
87+
:comment->@comment_emotions
88+
_->@emotions
89+
end
90+
91+
emotions
92+
|>Enum.map(
93+
&quotedo
94+
value(unquote(:"#{&1}"))
95+
end
96+
)
97+
end
98+
99+
@doc"""
100+
general emotions for articles
101+
102+
e.g:
103+
------
104+
beer_count
105+
viewer_has_beered
106+
latest_bear_users
107+
"""
108+
defmacroemotion_fields()do
109+
@emotions
110+
|>Enum.map(
111+
&quotedo
112+
field(unquote(:"#{&1}_count"),:integer)
113+
field(unquote(:"viewer_has_#{&1}ed"),:boolean)
114+
field(unquote(:"latest_#{&1}_users"),list_of(:simple_user))
115+
end
116+
)
117+
end
118+
119+
defmacroemotion_fields(:comment)do
120+
@comment_emotions
121+
|>Enum.map(
122+
&quotedo
123+
field(unquote(:"#{&1}_count"),:integer)
124+
field(unquote(:"viewer_has_#{&1}ed"),:boolean)
125+
field(unquote(:"latest_#{&1}_users"),list_of(:simple_user))
126+
end
127+
)
57128
end
58129

130+
@doc"""
131+
general timestamp with active_at for article
132+
"""
59133
defmacrotimestamp_fields(:article)do
60134
quotedo
61135
field(:inserted_at,:datetime)
@@ -79,6 +153,9 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
79153
end
80154
end
81155

156+
@doc"""
157+
general pagination fields except entries
158+
"""
82159
defmacropagination_fieldsdo
83160
quotedo
84161
field(:total_count,:integer)
@@ -98,6 +175,9 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
98175
end
99176
end
100177

178+
@doc"""
179+
general social used for user profile
180+
"""
101181
defmacrosocial_fieldsdo
102182
quotedo
103183
field(:qq,:string)
@@ -115,19 +195,13 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
115195
end
116196
end
117197

118-
importAbsinthe.Resolution.Helpers,only:[dataloader:2]
119-
120-
aliasGroupherServer.CMS
121-
aliasGroupherServerWeb.Middleware,as:M
122-
aliasGroupherServerWeb.Resolvers,as:R
123-
124198
defmacrothreads_count_fields()do
125199
@article_threads
126-
|>Enum.map(fnthread->
127-
quotedo
128-
field(unquote(:"#{thread}s_count"),:integer)
200+
|>Enum.map(
201+
&quotedo
202+
field(unquote(:"#{&1}s_count"),:integer)
129203
end
130-
end)
204+
)
131205
end
132206

133207
# TODO: remove
@@ -216,62 +290,6 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
216290
end
217291
end
218292

219-
@doc"""
220-
general emotion enum for articles
221-
#NOTE: xxx_user_logins field is not support for gq-endpoint
222-
"""
223-
defmacroemotion_enum()do
224-
@supported_emotions
225-
|>Enum.map(fnemotion->
226-
quotedo
227-
value(unquote(:"#{emotion}"))
228-
end
229-
end)
230-
end
231-
232-
@doc"""
233-
general emotion enum for comments
234-
#NOTE: xxx_user_logins field is not support for gq-endpoint
235-
"""
236-
defmacrocomment_emotion_enum()do
237-
@supported_comment_emotions
238-
|>Enum.map(fnemotion->
239-
quotedo
240-
value(unquote(:"#{emotion}"))
241-
end
242-
end)
243-
end
244-
245-
@doc"""
246-
general emotions for articles
247-
#NOTE: xxx_user_logins field is not support for gq-endpoint
248-
"""
249-
defmacroemotion_fields()do
250-
@supported_emotions
251-
|>Enum.map(fnemotion->
252-
quotedo
253-
field(unquote(:"#{emotion}_count"),:integer)
254-
field(unquote(:"viewer_has_#{emotion}ed"),:boolean)
255-
field(unquote(:"latest_#{emotion}_users"),list_of(:simple_user))
256-
end
257-
end)
258-
end
259-
260-
@doc"""
261-
general emotions for comments
262-
#NOTE: xxx_user_logins field is not support for gq-endpoint
263-
"""
264-
defmacrocomment_emotion_fields()do
265-
@supported_comment_emotions
266-
|>Enum.map(fnemotion->
267-
quotedo
268-
field(unquote(:"#{emotion}_count"),:integer)
269-
field(unquote(:"viewer_has_#{emotion}ed"),:boolean)
270-
field(unquote(:"latest_#{emotion}_users"),list_of(:simple_user))
271-
end
272-
end)
273-
end
274-
275293
@doc"""
276294
general collect folder meta info
277295
"""
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
defmoduleGroupherServerWeb.Schema.Helper.Importsdo
2+
@moduledoc"""
3+
helper for import cms article related fields
4+
"""
5+
6+
importHelper.Utils,only:[get_config:2]
7+
@article_threadsget_config(:article,:threads)
8+
9+
aliasGroupherServerWeb.Schema.{CMS}
10+
11+
@doc"""
12+
import article fields based on @article_threads
13+
e.g:
14+
----
15+
import_types(:cms_post_mutations)
16+
import_types(:cms_job_mutations)
17+
# ...
18+
"""
19+
defmacroimport_article_fields(:mutations)do
20+
@article_threads
21+
|>Enum.map(
22+
&quotedo
23+
import_fields(unquote(:"cms_#{&1}_mutations"))
24+
end
25+
)
26+
end
27+
28+
@doc"""
29+
import article fields based on @article_threads
30+
e.g:
31+
----
32+
import_types(CMS.Mutations.Post)
33+
import_types(CMS.Mutations.Job)
34+
# ...
35+
"""
36+
defmacroimport_article_fields(:mutations,:module)do
37+
@article_threads
38+
|>Enum.map(
39+
&quotedo
40+
import_types(unquote(Module.concat(CMS.Mutations,Recase.to_pascal(to_string(&1)))))
41+
end
42+
)
43+
end
44+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp