Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions website/pages/docs/mutations-and-input-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ type Message {

type Query {
getMessage(id: ID!): Message
getMessages: [Message]
}

const root = {
getMessage: ({ id }) => {
return fakeDatabase[id]
},
getMessages: () => {
return Object.values(fakeDatabase)
},
createMessage: ({ input }) => {
const id = String(Object.keys(fakeDatabase).length + 1)
const message = new Message(id, input)
fakeDatabase[id] = message
return message
},
updateMessage: ({ id, input }) => {
const message = fakeDatabase[id]
Object.assign(message, input)
return message
}
}

type Mutation {
Expand All @@ -244,6 +265,7 @@ app.all(
'/graphql',
createHandler({
schema: schema,
rootValue: root,
}),
);
app.listen(4000, () => {
Expand Down
Loading