Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit fc44076

Browse files
committed
Add example server. Useful to manually test GraphiQL
1 parent 24ac2f1 commit fc44076

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

examples/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import express from 'express';
2+
import graphqlHTTP from '../src/';
3+
import { buildSchema } from 'graphql';
4+
5+
// Construct a schema, using GraphQL schema language
6+
var schema = buildSchema(`
7+
type Query {
8+
hello: String
9+
}
10+
`);
11+
12+
// The root provides a resolver function for each API endpoint
13+
var root = {
14+
hello: () => 'Hello world!',
15+
};
16+
17+
var app = express();
18+
app.use('/graphql', graphqlHTTP({
19+
schema: schema,
20+
rootValue: root,
21+
graphiql: true,
22+
}));
23+
app.listen(4000);
24+
console.log('Running a GraphQL API server at http://localhost:4000/graphql');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha",
5555
"pretty": "node resources/pretty.js",
5656
"pretty-check": "node resources/pretty.js --check",
57-
"preversion": "npm test"
57+
"preversion": "npm test",
58+
"start": "babel-node examples/index.js"
5859
},
5960
"dependencies": {
6061
"accepts": "^1.3.0",

0 commit comments

Comments
 (0)