Skip to content

Commit 03caf88

Browse files
authored
Imported GraphQLString and fixed the resolver part as per code first approach.
1 parent 7dd7812 commit 03caf88

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,30 @@ console.log('Running a GraphQL API server at http://localhost:4000/graphql');
4949
</Tabs.Tab>
5050
<Tabs.Tab>
5151
```javascript
52-
const { GraphQLObjectType, GraphQLSchema } = require('graphql');
52+
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
55+
56+
// Construct a schema and resolver
5757
const schema = new GraphQLSchema({
5858
query: new GraphQLObjectType({
5959
name: 'Query',
6060
fields: {
61-
hello: { type: GraphQLString },
61+
hello: {
62+
type: GraphQLString,
63+
resolve: () => 'Hello world!'
64+
},
6265
},
6366
}),
6467
});
65-
66-
// The root provides a resolver function for each API endpoint
67-
const root = {
68-
hello() {
69-
return 'Hello world!';
70-
},
71-
};
72-
68+
7369
const app = express();
74-
70+
7571
// Create and use the GraphQL handler.
7672
app.all(
7773
'/graphql',
7874
createHandler({
79-
schema: schema,
80-
rootValue: root,
75+
schema: schema
8176
}),
8277
);
8378

0 commit comments

Comments
 (0)