diff --git a/website/pages/docs/mutations-and-input-types.mdx b/website/pages/docs/mutations-and-input-types.mdx index 065ef37a9e..bf0e3925e6 100644 --- a/website/pages/docs/mutations-and-input-types.mdx +++ b/website/pages/docs/mutations-and-input-types.mdx @@ -207,6 +207,8 @@ const express = require('express'); const { createHandler } = require('graphql-http/lib/use/express'); const { buildSchema } = require('graphql'); +const fakeDatabase = {}; + // Construct a schema, using GraphQL schema language const schema = buildSchema(` input MessageInput { @@ -222,6 +224,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 { @@ -244,6 +267,7 @@ app.all( '/graphql', createHandler({ schema: schema, + rootValue: root, }), ); app.listen(4000, () => {