"Troubleshooting problem with graphql and express related to syntax and pre-compilation

Hey there, I'm currently trying to create a booking system by following a tutorial video. You can check out the video here

The issue I'm facing is that even though my code is identical to the one in the tutorial, it's not working and I'm getting this error message:

    [nodemon] restarting due to changes...
[nodemon] starting `node app.js`
C:\Users\Abdulrahman\Desktop\bookings1\app.js:12
    graphqlHttp({
    ^

TypeError: graphqlHttp is not a function
    at Object.<anonymous> (C:\Users\Abdulrahman\Desktop\bookings1\app.js:12:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47
[nodemon] app crashed - waiting for file changes before starting...

Here is the code snippet from my app.js file:

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);

Do you have any suggestions on how to troubleshoot and fix this error? Any help or guidance would be greatly appreciated! Thanks in advance!

Answer №1

To resolve the issue of

TypeError: graphqlHttp is not a function
, you should substitute

const graphqlHttp = require('express-graphql');

with

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

(Please note the change in case from HTTP to Http)

Remember to replace all instances of graphqlHttp with graphqlHTTP in your code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Next.js is perplexing me by throwing an error about Event handlers not being able to be passed to Client Component props, even though the component clearly has "use client" at

My bundler generates a basic React component like this "use client"; "use strict";var a=Object.create;var r=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,s=Objec ...

Obtaining numerous files in base64 along with their respective file names using FileReaderAPI in Javascript

When I upload 3 items named png1, png2, and png3, the result will be as follows: alert 1 png1 / base64 string conversion alert 2 png2 / base64 string conversion alert 3 png3 / base64 string conversion I experimented with this code snippet. fu ...

Submit the form only when the specified conditions are met, otherwise return

Is there a way to submit a form after it has been prevented from submitting? I've searched for solutions on StackOverflow but haven't found one that works for me. Below is the code snippet in question: $(function(){ $("#loginform").submit(f ...

Troubleshooting line break appearance glitch in Vue.js

When using my VueJS form, I encounter an issue where line breaks in my textarea content are ignored when rendering the email format on the Java backend side. How can I ensure that my line breaks are preserved when sending the content from the front end t ...

Is it possible for jquery.find() to only target immediate children?

How can I use jQuery.find() to specifically target only the direct children of an element without selecting their descendants? Leading the selector with '>' or using '*' doesn't give me the desired result. While I know about jQ ...

Obtaining a date and time in PHP from a JavaScript array

I am currently working on implementing a JQuery datetime picker and my goal is to save the selected date and time into a PHP variable for storage in a MySQL database. Despite browsing through various examples, none of them seem to be effective in achieving ...

typescript defining callback parameter type based on callback arguments

function funcOneCustom<T extends boolean = false>(isTrue: T) { type RETURN = T extends true ? string : number; return (isTrue ? "Nice" : 20) as RETURN; } function funcCbCustom<T>(cb: (isTrue: boolean) => T) { const getFirst = () => ...

Insert PHP File into Division Element

Need help loading a PHP file into a div element without removing existing content? Here's an example: $('.Load_Div').load('example.php'); Let's say the Load_Div already has some content that you want to keep, and you want th ...

A guide on incorporating an unflattened SVG file into a React component

I am having trouble embedding an SVG file in a React component because it seems to appear flattened. Is there a way to display it as pure SVG? Please take a look at where it is posted: Also, this is how it's supposed to be viewed: This is the metho ...

What is the process of passing a request parameter from an Express server to a React application?

How can I pass these specific request headers to my react application? app.get('/',function(req, res, next){ req.user = req.headers["id"]; next(null, req.user); }) ...

The C# method is receiving a null array through Ajax

When I retrieve an array in a loop and pass it through an ajax call to my C# method, I'm encountering a problem where only null values are being received in my parameter. The count of the array is coming through, but the actual data seems to be lost. ...

At the ready stance for a particular grade of students attending a class

I have created a page with a navigation menu that can be scrolled using the wheel mouse. My goal is to ensure that the li item with the 'selected' class is always positioned in the first position on the left. Is there a way to achieve this using ...

I am having trouble running my JavaScript code outside of JSFiddle

It's strange how my code functions perfectly in JSFiddle, but when I attempt to use it outside of JSFiddle, it fails to work. Can anyone provide a solution or insight into what might be causing this issue? Feel free to check out the JSFiddle code here ...

Question from Student: Can a single function be created to manage all text fields, regardless of the number of fields present?

In my SPFX project using React, TypeScript, and Office UI Fabric, I've noticed that I'm creating separate functions for each text field in a form. Is there a way to create a single function that can handle multiple similar fields, but still maint ...

Effective methods for managing dependencies in a library

I'm struggling to determine the most effective way to pass dependencies to my Express routes. The issue lies in the fact that some of my libraries are interconnected, such as my session manager being linked to my redis queue client. Additionally, my l ...

Is it possible for me to use ts files just like I use js files in the same manner?

So I recently stumbled upon TypeScript and found it intriguing, especially since I enjoy adding annotations in my code. The only downside is that I would have to change all my .js files to .ts files in order to fully utilize TypeScript's capabilities. ...

Losing values due to custom $validator and getterSetter in AngularJS / UI Bootstrap

My objective is to create a UI Bootstrap datepicker with an input mask feature. The datepicker directive only validates dates selected using the popup window and not dates manually typed in by the user. To address this, I researched how to implement custo ...

My goal is to exclusively create illustrations of items within a camera's view

Currently, I am using THREEJS to create a dynamically generated 'minecraft' world utilizing a perlin noise generator. Check out the progress so far: Block World Everything is going smoothly except that I am facing significant performance issues ...

MEAN Stack: Utilizing Expressjs Routes with query strings

I am facing an issue with my schemas - User and Plans. I need to retrieve all the plans associated with a specific user, but for some reason, using query parameters in a GET request is not yielding the desired results. Can anyone provide assistance with th ...

Gaining entry to information while an HTML form is being submitted

After a 15-year break, I am diving back into web development and currently learning Node.js and ExpressJS. I have set up a registration form on index.html and now want to transfer the entered data to response.html. However, when I hit Submit, the form is p ...