Skip to content

Commit 5985d0e

Browse files
authored
Clarify Ruru's relation to GraphiQL (#1699)
* Clarify Ruru's relation to GraphiQL * Vercel fails to render italic 'i'
1 parent 2454640 commit 5985d0e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/pages/graphql-js/running-an-express-graphql-server.mdx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebarTitle: Running Express + GraphQL
66
The simplest way to run a GraphQL API server is to use [Express](https://expressjs.com), a popular web application framework for Node.js. You will need to install two additional dependencies:
77

88
```bash
9-
npm install express graphql-http graphql ruru --save
9+
npm install express graphql-http graphql --save
1010
```
1111

1212
Let's modify our “hello world” example so that it's an API server rather than a script that runs a single query. We can use the 'express' module to run a webserver, and instead of executing a query directly with the `graphql` function, we can use the `graphql-http` library to mount a GraphQL API server on the “/graphql” HTTP endpoint:
@@ -15,7 +15,6 @@ Let's modify our “hello world” example so that it's an API server rather tha
1515
var express = require("express")
1616
var { createHandler } = require("graphql-http/lib/use/express")
1717
var { buildSchema } = require("graphql")
18-
var { ruruHTML } = require("ruru/server")
1918

2019
// Construct a schema, using GraphQL schema language
2120
var schema = buildSchema(`
@@ -42,12 +41,6 @@ app.all(
4241
})
4342
)
4443

45-
// Serve the GraphiQL IDE.
46-
app.get("/", (_req, res) => {
47-
res.type("html")
48-
res.end(ruruHTML({ endpoint: "/graphql" }))
49-
})
50-
5144
// Start the server at port
5245
app.listen(4000)
5346
console.log("Running a GraphQL API server at http://localhost:4000/graphql")
@@ -59,6 +52,23 @@ You can run this GraphQL server with:
5952
node server.js
6053
```
6154

62-
You can use the Graph_i_QL IDE tool to issue GraphQL queries directly in the browser. If you navigate to [http://localhost:4000](http://localhost:4000), you should see an interface that lets you enter queries.
55+
## Using GraphiQL
56+
57+
[GraphiQL](https://github.com/graphql/graphiql) is GraphQL's IDE; a great way of querying and exploring your GraphQL API.
58+
One easy way to add it to your server is via the MIT-licensed [ruru](https://github.com/graphile/crystal/blob/main/grafast/ruru/README.md) package which bundles a prebuilt GraphiQL with some popular enhancements.
59+
To do so, install the `ruru` module with `npm install --save ruru` and then add the following to your `server.js` file, then restart the `node server.js` command:
60+
61+
```js
62+
var { ruruHTML } = require("ruru/server")
63+
64+
// Serve the GraphiQL IDE.
65+
app.get("/", (_req, res) => {
66+
res.type("html")
67+
res.end(ruruHTML({ endpoint: "/graphql" }))
68+
})
69+
```
70+
71+
If you navigate to [http://localhost:4000](http://localhost:4000), you should see an interface that lets you enter queries;
72+
now you can use the GraphiQL IDE tool to issue GraphQL queries directly in the browser.
6373

6474
At this point you have learned how to run a GraphQL server. The next step is to learn how to [issue GraphQL queries from client code](/graphql-js/graphql-clients/).

0 commit comments

Comments
 (0)