Skip to content
Closed
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
25 changes: 10 additions & 15 deletions website/pages/docs/running-an-express-graphql-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,30 @@ console.log('Running a GraphQL API server at http://localhost:4000/graphql');
</Tabs.Tab>
<Tabs.Tab>
```javascript
const { GraphQLObjectType, GraphQLSchema } = require('graphql');
const { GraphQLObjectType, GraphQLSchema, GraphQLString } = require('graphql');
const { createHandler } = require('graphql-http/lib/use/express');
const express = require('express');

// Construct a schema
// Construct a schema and resolver
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
hello: { type: GraphQLString },
hello: {
type: GraphQLString,
resolve: () => 'Hello world!'
},
},
}),
});

// The root provides a resolver function for each API endpoint
const root = {
hello() {
return 'Hello world!';
},
};


const app = express();

// Create and use the GraphQL handler.
app.all(
'/graphql',
createHandler({
schema: schema,
rootValue: root,
schema: schema
}),
);

Expand Down