Skip to content

Commit 86899be

Browse files
authored
Imported GraphQLString and fixed the error.
1 parent 03caf88 commit 86899be

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

website/pages/docs/running-an-express-graphql-server.mdx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,32 @@ console.log('Running a GraphQL API server at http://localhost:4000/graphql');
5252
const { GraphQLObjectType, GraphQLSchema, GraphQLString } = require('graphql');
5353
const { createHandler } = require('graphql-http/lib/use/express');
5454
const express = require('express');
55-
56-
// Construct a schema and resolver
55+
56+
// Construct a schema
5757
const schema = new GraphQLSchema({
5858
query: new GraphQLObjectType({
5959
name: 'Query',
6060
fields: {
61-
hello: {
62-
type: GraphQLString,
63-
resolve: () => 'Hello world!'
64-
},
61+
hello: { type: GraphQLString },
6562
},
6663
}),
6764
});
68-
65+
66+
// The root provides a resolver function for each API endpoint
67+
const root = {
68+
hello() {
69+
return 'Hello world!';
70+
},
71+
};
72+
6973
const app = express();
70-
74+
7175
// Create and use the GraphQL handler.
7276
app.all(
7377
'/graphql',
7478
createHandler({
75-
schema: schema
79+
schema: schema,
80+
rootValue: root,
7681
}),
7782
);
7883

0 commit comments

Comments
 (0)