File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,8 @@ const express = require('express');
207
207
const { createHandler } = require (' graphql-http/lib/use/express' );
208
208
const { buildSchema } = require (' graphql' );
209
209
210
+ const fakeDatabase = {};
211
+
210
212
// Construct a schema, using GraphQL schema language
211
213
const schema = buildSchema (`
212
214
input MessageInput {
@@ -222,6 +224,27 @@ type Message {
222
224
223
225
type Query {
224
226
getMessage(id: ID!): Message
227
+ getMessages: [Message]
228
+ }
229
+
230
+ const root = {
231
+ getMessage: ({ id }) => {
232
+ return fakeDatabase[id]
233
+ },
234
+ getMessages: () => {
235
+ return Object.values(fakeDatabase)
236
+ },
237
+ createMessage: ({ input }) => {
238
+ const id = String(Object.keys(fakeDatabase).length + 1)
239
+ const message = new Message(id, input)
240
+ fakeDatabase[id] = message
241
+ return message
242
+ },
243
+ updateMessage: ({ id, input }) => {
244
+ const message = fakeDatabase[id]
245
+ Object.assign(message, input)
246
+ return message
247
+ }
225
248
}
226
249
227
250
type Mutation {
@@ -244,6 +267,7 @@ app.all(
244
267
' /graphql' ,
245
268
createHandler ({
246
269
schema: schema,
270
+ rootValue: root,
247
271
}),
248
272
);
249
273
app .listen (4000 , () => {
You can’t perform that action at this time.
0 commit comments