Skip to content

Commit 4b33adf

Browse files
author
Roshan Jossy
committed
save story with createStory mutation
1 parent 77b840d commit 4b33adf

File tree

5 files changed

+244
-11
lines changed

5 files changed

+244
-11
lines changed

schema/schema.graphql

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Query {
1212
# The ID of an object
1313
id: ID!
1414
): Node
15+
feeds(first: Int, last: Int, after: String, before: String): StoriesConnection!
1516
}
1617

1718
interface Node {
@@ -45,6 +46,35 @@ type BadgeEdge {
4546
cursor: String!
4647
}
4748

49+
type Comment implements Node {
50+
abstractContent: String!
51+
contentJson: String!
52+
createdBy: User!
53+
id: ID!
54+
reactions(first: Int, last: Int, after: String, before: String): ReactionsConnection!
55+
timeCreated: Time!
56+
timeUpdated: Time!
57+
}
58+
59+
input CommentInput {
60+
abstractContent: String!
61+
contentJson: String!
62+
storyID: ID!
63+
}
64+
input UpdateCommentInput {
65+
id: ID!
66+
}
67+
68+
type CommentsConnection {
69+
edges: [CommentEdge]!
70+
pageInfo: PageInfo!
71+
}
72+
73+
type CommentEdge {
74+
node: Comment!
75+
cursor: String!
76+
}
77+
4878
type GitContributionStats {
4979
issues: Int!
5080
pullRequests: Int!
@@ -78,6 +108,31 @@ type IssueEdge {
78108
cursor: String!
79109
}
80110

111+
type Reaction implements Node {
112+
createdBy: User!
113+
id: ID!
114+
timeCreated: Time!
115+
timeUpdated: Time!
116+
}
117+
118+
input ReactionInput {
119+
commentID: ID!
120+
storyID: ID!
121+
}
122+
input UpdateReactionInput {
123+
id: ID!
124+
}
125+
126+
type ReactionsConnection {
127+
edges: [ReactionEdge]!
128+
pageInfo: PageInfo!
129+
}
130+
131+
type ReactionEdge {
132+
node: Reaction!
133+
cursor: String!
134+
}
135+
81136
type Reputation {
82137
value: Float!
83138
}
@@ -86,6 +141,41 @@ input ReputationInput {
86141
value: Float!
87142
}
88143

144+
type Story implements Node {
145+
abstractContent: String!
146+
comments(first: Int, last: Int, after: String, before: String): CommentsConnection!
147+
contentJson: String!
148+
createdBy: User!
149+
id: ID!
150+
reactions(first: Int, last: Int, after: String, before: String): ReactionsConnection!
151+
thumbnail: String!
152+
timeCreated: Time!
153+
timeUpdated: Time!
154+
title: String!
155+
urlSuffix: String!
156+
}
157+
158+
input StoryInput {
159+
abstractContent: String!
160+
contentJson: String!
161+
thumbnail: String!
162+
title: String!
163+
urlSuffix: String!
164+
}
165+
input UpdateStoryInput {
166+
id: ID!
167+
}
168+
169+
type StoriesConnection {
170+
edges: [StoryEdge]!
171+
pageInfo: PageInfo!
172+
}
173+
174+
type StoryEdge {
175+
node: Story!
176+
cursor: String!
177+
}
178+
89179
type User implements Node {
90180
avatar: String!
91181
badges(first: Int, last: Int, after: String, before: String): BadgesConnection!
@@ -98,6 +188,7 @@ type User implements Node {
98188
name: String!
99189
relevantIssues(first: Int, last: Int, after: String, before: String): IssuesConnection!
100190
reputation: Reputation!
191+
stories(first: Int, last: Int, after: String, before: String): StoriesConnection!
101192
timeCreated: Time!
102193
timeUpdated: Time!
103194
}
@@ -112,13 +203,20 @@ input UserInput {
112203
}
113204
input UpdateUserInput {
114205
id: ID!
206+
avatar: String
115207
bio: String
116208
gitContributionStats: GitContributionStatsInput
117209
name: String
118210
reputation: ReputationInput
119211
}
120212

121213
type Mutation {
214+
createComment(comment:CommentInput!): Comment!
215+
updateComment(comment: UpdateCommentInput!): Comment!
216+
createReaction(reaction:ReactionInput!): Reaction!
217+
updateReaction(reaction: UpdateReactionInput!): Reaction!
218+
createStory(story:StoryInput!): Story!
219+
updateStory(story: UpdateStoryInput!): Story!
122220
createUser(user:UserInput!): User!
123221
updateUser(user: UpdateUserInput!): User!
124222
}

src/components/editor/Editor.tsx renamed to src/components/editor/StoryEditor.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import EditorJS from '@editorjs/editorjs';
2-
import React, { useCallback, useEffect, useRef, useState } from 'react';
3-
import Header from '@editorjs/header'
2+
import React, { useEffect, useRef, useState } from 'react';
3+
import { graphql, useMutation } from 'react-relay';
44
import Card from '../Card';
5-
5+
import { EDITOR_JS_TOOLS } from './editorTools';
66

77
const DEFAULT_INITIAL_DATA = () => {
88
return {
@@ -45,22 +45,37 @@ export default function Editor () {
4545
ejInstance.current = editor;
4646
},
4747
onChange: async () => {
48-
let content = await this.editorjs.saver.save();
48+
let content = await editor.saver.save();
4949
// Put your logic here to save this data to your DB
5050
setEditorData(content);
5151
},
5252
autofocus: true,
53-
tools: {
54-
header: Header,
55-
},
53+
tools: EDITOR_JS_TOOLS,
54+
inlineToolbar: true,
55+
placehodler: 'water'
5656
});
5757
};
58+
const [commitMutation, isMutationInFlight] = useMutation(
59+
graphql`
60+
mutation StoryEditorCreateMutation($input: StoryInput!) {
61+
createStory(story:$input) {
62+
id
63+
}
64+
}
65+
`
66+
);
5867
const handleStorySubmit = () => {
5968
console.log(postTitle)
69+
console.log(editorData)
70+
commitMutation({
71+
variables: {
72+
input: {title: postTitle, contentJson: JSON.stringify(editorData), abstractContent: '', urlSuffix: '', thumbnail: ''},
73+
},
74+
})
6075
}
6176
return (
6277
<Card classes="prose">
63-
<h2 contentEditable onInput={(e) => setPostTitle(e.target.textContent)}>{postTitle}</h2>
78+
<h1 contentEditable onInput={(e) => setPostTitle(e.target.textContent)}>{postTitle}</h1>
6479
<div>
6580
<div id={EDITTOR_HOLDER_ID}> </div>
6681
</div>

src/pages/story.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dynamic from 'next/dynamic'
22
import Layout from '../components/Layout'
33

4-
const Editor = dynamic(() => import('../components/editor/Editor'))
4+
const Editor = dynamic(() => import('../components/editor/StoryEditor'))
55
export default function Story () {
66
return (
77
<div>

src/queries/__generated__/BioUpdateMutation.graphql.ts

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/queries/__generated__/StoryEditorCreateMutation.graphql.ts

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)