skip to Main Content
const express = require('express');
const bodyParser = require('body-parser');
const graphqlHttp = require('express-graphql');
const { buildSchema } = require('graphql');

const app = express();

app.use(bodyParser.json());

app.use(
  '/graphql',
  graphqlHttp({
    schema: buildSchema(`
        type RootQuery {
            events: [String!]!
        }

        type RootMutation {
            createEvent(name: String): String
        }

        schema {
            query: RootQuery
            mutation: RootMutation
        }
    `),
    rootValue: {
      events: () => {
        return ['Romantic Cooking', 'Sailing', 'All-Night Coding'];
      },
      createEvent: (args) => {
        const eventName = args.name;
        return eventName;
      }
    },
    graphiql: true
  })
);

app.listen(3000);

I tried using the following tutorial from YouTube.

https://www.youtube.com/watch?v=LXTyzk2uud0&list=PL55RiY5tL51rG1x02Yyj93iypUuHYXcB_&index=3

It didn’t work. Instead I get:

nodemon app crashed – waiting for file changes before starting…

2

Answers


  1. Chosen as BEST ANSWER
        F:Files not on HDD1ProjectsCodegraphql-react-event-booking>npm start
    
    > [email protected] start
    > nodemon app.js
    
    [nodemon] 3.1.4
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching path(s): *.*
    [nodemon] watching extensions: js,mjs,cjs,json
    [nodemon] starting `node app.js`
    node:internal/modules/cjs/loader:1056
      throw err;
      ^
    
    Error: Cannot find module 'express-graphql'
    Require stack:
    - F:Files not on HDD1ProjectsCodegraphql-react-event-bookingapp.js
        at Module._resolveFilename (node:internal/modules/cjs/loader:1053:15)
        at Module._load (node:internal/modules/cjs/loader:898:27)
        at Module.require (node:internal/modules/cjs/loader:1120:19)
        at require (node:internal/modules/helpers:112:18)
        at Object.<anonymous> (F:Files not on HDD1ProjectsCodegraphql-react-event-bookingapp.js:3:23)
        at Module._compile (node:internal/modules/cjs/loader:1239:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1293:10)
        at Module.load (node:internal/modules/cjs/loader:1096:32)
        at Module._load (node:internal/modules/cjs/loader:935:12)
        at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:84:12) {
      code: 'MODULE_NOT_FOUND',
      requireStack: [
        'F:\Files not on HDD1\Projects\Code\graphql-react-event-booking\app.js'
      ]
    }
    
    Node.js v19.4.0
    [nodemon] app crashed - waiting for file changes before starting...
    

  2. There should be a more detailed error message above "nodemon app crashed". But anyways, there is a top comment in the youtube video that says graphqlHttp is not imported properly. It should be:

    const { graphqlHTTP } = require('express-graphql');

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search