Skip to content

Commit da74676

Browse files
author
Donatas Stundys
committed
Add input object to mutations
1 parent 648dbbb commit da74676

File tree

5 files changed

+149
-17
lines changed

5 files changed

+149
-17
lines changed

app/graphql/mutations/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Mutations::Base < GraphQL::Schema::Mutation
1+
class Mutations::Base < GraphQL::Schema::RelayClassicMutation
22
def user_errors(errors)
33
errors.full_messages.map { |error| UserError.new(error) }
44
end

app/graphql/schema.graphql

Lines changed: 145 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
# Autogenerated input type of AddComment
2+
input AddCommentInput {
3+
articleId: ID!
4+
body: String!
5+
6+
# A unique identifier for the client performing the mutation.
7+
clientMutationId: String
8+
}
9+
110
# Autogenerated return type of AddComment
211
type AddCommentPayload {
12+
# A unique identifier for the client performing the mutation.
13+
clientMutationId: String
314
comment: Comment
415
errors: [UserError!]!
516
}
@@ -38,60 +49,123 @@ type ArticleEdge {
3849
}
3950

4051
type Comment {
41-
author: User!
52+
author: Profile!
4253
body: String!
4354
createdAt: DateTime!
4455
id: ID!
4556
updatedAt: DateTime!
4657
}
4758

59+
# Autogenerated input type of CreateArticle
60+
input CreateArticleInput {
61+
body: String!
62+
63+
# A unique identifier for the client performing the mutation.
64+
clientMutationId: String
65+
description: String!
66+
tagList: [String!]!
67+
title: String!
68+
}
69+
4870
# Autogenerated return type of CreateArticle
4971
type CreateArticlePayload {
5072
article: Article
73+
74+
# A unique identifier for the client performing the mutation.
75+
clientMutationId: String
5176
errors: [UserError!]!
5277
}
5378

79+
# Autogenerated input type of CreateUser
80+
input CreateUserInput {
81+
# A unique identifier for the client performing the mutation.
82+
clientMutationId: String
83+
email: String!
84+
password: String!
85+
username: String!
86+
}
87+
5488
# Autogenerated return type of CreateUser
5589
type CreateUserPayload {
90+
# A unique identifier for the client performing the mutation.
91+
clientMutationId: String
5692
errors: [UserError!]!
5793
user: User
5894
}
5995

6096
scalar DateTime
6197

98+
# Autogenerated input type of DeleteArticle
99+
input DeleteArticleInput {
100+
# A unique identifier for the client performing the mutation.
101+
clientMutationId: String
102+
id: ID!
103+
}
104+
62105
# Autogenerated return type of DeleteArticle
63106
type DeleteArticlePayload {
64107
article: Article!
108+
109+
# A unique identifier for the client performing the mutation.
110+
clientMutationId: String
111+
}
112+
113+
# Autogenerated input type of DeleteComment
114+
input DeleteCommentInput {
115+
# A unique identifier for the client performing the mutation.
116+
clientMutationId: String
117+
id: ID!
65118
}
66119

67120
# Autogenerated return type of DeleteComment
68121
type DeleteCommentPayload {
122+
# A unique identifier for the client performing the mutation.
123+
clientMutationId: String
69124
comment: Comment
70125
}
71126

127+
# Autogenerated input type of FavoriteArticle
128+
input FavoriteArticleInput {
129+
# A unique identifier for the client performing the mutation.
130+
clientMutationId: String
131+
id: ID!
132+
}
133+
72134
# Autogenerated return type of FavoriteArticle
73135
type FavoriteArticlePayload {
74136
article: Article
137+
138+
# A unique identifier for the client performing the mutation.
139+
clientMutationId: String
140+
}
141+
142+
# Autogenerated input type of FollowUser
143+
input FollowUserInput {
144+
# A unique identifier for the client performing the mutation.
145+
clientMutationId: String
146+
id: ID!
75147
}
76148

77149
# Autogenerated return type of FollowUser
78150
type FollowUserPayload {
151+
# A unique identifier for the client performing the mutation.
152+
clientMutationId: String
79153
user: Profile
80154
}
81155

82156
type Mutation {
83-
addComment(articleId: ID!, body: String!): AddCommentPayload
84-
createArticle(body: String!, description: String!, tagList: [String!]!, title: String!): CreateArticlePayload
85-
createUser(email: String!, password: String!, username: String!): CreateUserPayload
86-
deleteArticle(id: ID!): DeleteArticlePayload
87-
deleteComment(id: ID!): DeleteCommentPayload
88-
favoriteArticle(id: ID!): FavoriteArticlePayload
89-
followUser(id: ID!): FollowUserPayload
90-
signinUser(email: String!, password: String!): SignInUserPayload
91-
unfavoriteArticle(id: ID!): UnfavoriteArticlePayload
92-
unfollowUser(id: ID!): UnfollowUserPayload
93-
updateArticle(body: String!, description: String!, id: ID!, tagList: [String!]!, title: String!): UpdateArticlePayload
94-
updateUser(bio: String, email: String!, image: String, password: String, username: String!): UpdateUserPayload
157+
addComment(input: AddCommentInput!): AddCommentPayload
158+
createArticle(input: CreateArticleInput!): CreateArticlePayload
159+
createUser(input: CreateUserInput!): CreateUserPayload
160+
deleteArticle(input: DeleteArticleInput!): DeleteArticlePayload
161+
deleteComment(input: DeleteCommentInput!): DeleteCommentPayload
162+
favoriteArticle(input: FavoriteArticleInput!): FavoriteArticlePayload
163+
followUser(input: FollowUserInput!): FollowUserPayload
164+
signInUser(input: SignInUserInput!): SignInUserPayload
165+
unfavoriteArticle(input: UnfavoriteArticleInput!): UnfavoriteArticlePayload
166+
unfollowUser(input: UnfollowUserInput!): UnfollowUserPayload
167+
updateArticle(input: UpdateArticleInput!): UpdateArticlePayload
168+
updateUser(input: UpdateUserInput!): UpdateUserPayload
95169
}
96170

97171
# Information about pagination in a connection.
@@ -155,31 +229,89 @@ type Query {
155229
tags: [String!]!
156230
}
157231

232+
# Autogenerated input type of SignInUser
233+
input SignInUserInput {
234+
# A unique identifier for the client performing the mutation.
235+
clientMutationId: String
236+
email: String!
237+
password: String!
238+
}
239+
158240
# Autogenerated return type of SignInUser
159241
type SignInUserPayload {
242+
# A unique identifier for the client performing the mutation.
243+
clientMutationId: String
160244
errors: [UserError!]!
161245
token: String
162246
user: User
163247
}
164248

249+
# Autogenerated input type of UnfavoriteArticle
250+
input UnfavoriteArticleInput {
251+
# A unique identifier for the client performing the mutation.
252+
clientMutationId: String
253+
id: ID!
254+
}
255+
165256
# Autogenerated return type of UnfavoriteArticle
166257
type UnfavoriteArticlePayload {
167258
article: Article
259+
260+
# A unique identifier for the client performing the mutation.
261+
clientMutationId: String
262+
}
263+
264+
# Autogenerated input type of UnfollowUser
265+
input UnfollowUserInput {
266+
# A unique identifier for the client performing the mutation.
267+
clientMutationId: String
268+
id: ID!
168269
}
169270

170271
# Autogenerated return type of UnfollowUser
171272
type UnfollowUserPayload {
273+
# A unique identifier for the client performing the mutation.
274+
clientMutationId: String
172275
user: Profile
173276
}
174277

278+
# Autogenerated input type of UpdateArticle
279+
input UpdateArticleInput {
280+
body: String!
281+
282+
# A unique identifier for the client performing the mutation.
283+
clientMutationId: String
284+
description: String!
285+
id: ID!
286+
tagList: [String!]!
287+
title: String!
288+
}
289+
175290
# Autogenerated return type of UpdateArticle
176291
type UpdateArticlePayload {
177292
article: Article
293+
294+
# A unique identifier for the client performing the mutation.
295+
clientMutationId: String
178296
errors: [UserError!]!
179297
}
180298

299+
# Autogenerated input type of UpdateUser
300+
input UpdateUserInput {
301+
bio: String
302+
303+
# A unique identifier for the client performing the mutation.
304+
clientMutationId: String
305+
email: String!
306+
image: String
307+
password: String
308+
username: String!
309+
}
310+
181311
# Autogenerated return type of UpdateUser
182312
type UpdateUserPayload {
313+
# A unique identifier for the client performing the mutation.
314+
clientMutationId: String
183315
errors: [UserError!]!
184316
user: User
185317
}

app/graphql/types/comment_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Types::CommentType < GraphQL::Schema::Object
55
field :createdAt, Types::DateTimeType, null: false, method: :created_at
66
field :updatedAt, Types::DateTimeType, null: false, method: :updated_at
77
field :body, String, null: false
8-
field :author, Types::UserType, null: false
8+
field :author, Types::ProfileType, null: false
99

1010
def author
1111
Loaders::RecordLoader.for(User).load(object.author_id)

app/graphql/types/mutation_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Types::MutationType < GraphQL::Schema::Object
22
field :createUser, mutation: Mutations::CreateUser
33
field :updateUser, mutation: Mutations::UpdateUser
4-
field :signinUser, mutation: Mutations::SignInUser
4+
field :signInUser, mutation: Mutations::SignInUser
55
field :followUser, mutation: Mutations::FollowUser
66
field :unfollowUser, mutation: Mutations::UnfollowUser
77

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Rails.application.routes.draw do
22
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3-
post "/graphql", to: "graphql#execute"
3+
match '/graphql', to: 'graphql#execute', via: [:get, :post]
44

55
mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql'
66
end

0 commit comments

Comments
 (0)