From 00d1968d58327bab558fad325ac543837b8c0777 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 5 Nov 2025 15:18:04 -0600 Subject: [PATCH] Update GraphQL server setup instructions Added instructions for setting 'type' in package.json and using the ruru module for GraphiQL. --- .../graphql-js/running-an-express-graphql-server.mdx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pages/graphql-js/running-an-express-graphql-server.mdx b/src/pages/graphql-js/running-an-express-graphql-server.mdx index 6789f42b51..31ffeae44b 100644 --- a/src/pages/graphql-js/running-an-express-graphql-server.mdx +++ b/src/pages/graphql-js/running-an-express-graphql-server.mdx @@ -47,6 +47,14 @@ app.listen(4000, () => { }); ``` +Also, check your `package.json` file and ensure that `type` is set to `module`: + +```json +{ + "type": "module", +} +``` + You can run this GraphQL server with: ```sh @@ -59,7 +67,7 @@ At this point you will have a running GraphQL API; but you can't just visit it i [GraphiQL](https://github.com/graphql/graphiql) is GraphQL's IDE; a great way of querying and exploring your GraphQL API. 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. -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: +To do so, install the `ruru` module with `npm install --save ruru` and then add the following to your `server.js` file: ```js import { ruruHTML } from "ruru/server"; @@ -71,6 +79,8 @@ app.get("/", (_req, res) => { }); ``` +Now restart the `node server.js` command. + If you navigate to [http://localhost:4000](http://localhost:4000), you should see an interface that lets you enter queries; now you can use the GraphiQL IDE tool to issue GraphQL queries directly in the browser.