Skip to content

Commit 34bd108

Browse files
author
Donatas Stundys
committed
Clean up schema
1 parent ecc49ba commit 34bd108

File tree

7 files changed

+7
-23
lines changed

7 files changed

+7
-23
lines changed

app/graphql/mutations/add_comment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Mutations::AddComment < Mutations::Base
2-
argument :articleId, ID, required: true, as: :article_id
2+
argument :article_id, ID, required: true
33
argument :body, String, required: true
44

55
field :comment, Types::CommentType, null: true

app/graphql/mutations/create_article.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Mutations::CreateArticle < Mutations::Base
22
argument :title, String, required: true
33
argument :description, String, required: true
44
argument :body, String, required: true
5-
argument :tagList, [String], required: true, as: :tag_list
5+
argument :tag_list, [String], required: true
66

77
field :article, Types::ArticleType, null: true
88
field :errors, [Types::UserErrorType], null: false

app/graphql/mutations/update_article.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Mutations::UpdateArticle < Mutations::Base
33
argument :title, String, required: true
44
argument :description, String, required: true
55
argument :body, String, required: true
6-
argument :tagList, [String], required: true, as: :tag_list
6+
argument :tag_list, [String], required: true
77

88
field :article, Types::ArticleType, null: true
99
field :errors, [Types::UserErrorType], null: false

app/graphql/schema.graphql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AddCommentPayload {
1616
}
1717

1818
type Article {
19-
author: User!
19+
author: User
2020
body: String!
2121
comments: [Comment!]!
2222
createdAt: DateTime!
@@ -202,11 +202,9 @@ type Query {
202202
articles(
203203
# Returns the elements in the list that come after the specified cursor.
204204
after: String
205-
authoredBy: String
206205

207206
# Returns the elements in the list that come before the specified cursor.
208207
before: String
209-
favoritedBy: String
210208

211209
# Returns the first _n_ elements from the list.
212210
first: Int
@@ -366,7 +364,7 @@ type UserEdge {
366364

367365
type UserError {
368366
message: String!
369-
path: [String!]
367+
path: String
370368
}
371369

372370
type Viewer {

app/graphql/types/article_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Types::ArticleType < GraphQL::Schema::Object
1111
field :updated_at, Types::DateTimeType, null: false
1212
field :viewer_has_favorited, Boolean, null: false
1313
field :favorites_count, Int, null: false
14-
field :author, Types::UserType, null: false
14+
field :author, Types::UserType, null: true
1515
field :comments, [Types::CommentType], null: false
1616

1717
def viewer_has_favorited

app/graphql/types/query_type.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,10 @@ def user(username:)
1313

1414
field :articles, Types::ArticleType.connection_type, null: false do
1515
argument :tag, String, required: false
16-
argument :authoredBy, String, required: false, as: :authored_by
17-
argument :favoritedBy, String, required: false, as: :favorited_by
1816
end
1917
def articles(tag: nil, authored_by: nil, favorited_by: nil)
2018
articles = Article.all
2119

22-
if authored_by.present?
23-
author = User.find_by(username: authored_by)
24-
raise GraphQL::ExecutionError, 'User not found' if author.blank?
25-
articles.where!(author: author)
26-
end
27-
28-
if favorited_by.present?
29-
user = User.find_by(username: favorited_by)
30-
raise GraphQL::ExecutionError, 'User not found' if user.blank?
31-
articles.where!(id: user.favorite_article_ids)
32-
end
33-
3420
if tag.present?
3521
articles = articles.tagged_with(tag)
3622
end

app/graphql/types/user_error_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class Types::UserErrorType < GraphQL::Schema::Object
22
graphql_name 'UserError'
33

44
field :message, String, null: false
5-
field :path, [String], null: true
5+
field :path, String, null: true
66
end

0 commit comments

Comments
 (0)