I am experiencing issues with the GraphQL Documentation Explorer failing to load my schema

https://i.stack.imgur.com/GPmVm.pngI'm currently setting up a GraphQL Schema using Express, but I'm facing an issue where Graphiql is not recognizing the schema. When I execute a query, it prompts me to provide a query string. Below is my code. Can anyone identify any mistakes? The console does not show any errors and the documentation explorer displays a spinning loading circle indefinitely. Could this be causing an infinite loop somehow?

Here is the schema:

const graphql = require('graphql');
const _= require('lodash');

const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql;

//dummy data 

var books = [
    {name: 'book1', genre: 'genre1', id: '1'},
    {name: 'book2', genre: 'genre2', id: '2'},
    {name: 'book3', genre: 'genre3', id: '3'}
]

const BookType = new GraphQLObjectType({
    name: 'Book',
    fields: () => ({
        id: {type: GraphQLString},
        name: {type: GraphQLString},
        genre: {type: GraphQLString}
    })
});

const RootQuery = new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
        book: {
            type: BookType,
            args: {id: {type: GraphQLString}},
            resolve(parent, args) {
                //code to get data from db / other source
                return _.find(books, {id: args.id});
            }
        }
    }
});

module.exports = new GraphQLSchema({
    query: RootQuery
})

And here is the server setup:

const express = require("express");
const bodyParser = require("body-parser");
const app = express();
require("dotenv").config();
const axios = require("axios");
const {graphqlHTTP} = require('express-graphql')
const schema = require('./schema/schema')

// set up our middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("server/public"));
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
}));

   //loading on port 5000
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
  console.log("Server running on: ", PORT);
});

Answer №1

After encountering compatibility issues between bodyparser and graphQL, I successfully resolved the issue by removing the bodyparser middleware. For anyone facing similar challenges, this solution should help resolve the problem.

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

Tips on recognizing the origin of incoming requests in a Node.js interface

In the development of my application using Node.js, Express.js, and Mongoose, I'm wondering how to determine if a request hitting my REST API service is coming from my front-end application rather than an unknown source. What steps or methods should I ...

Troubleshooting the error "The 'listener' argument must be a function" in Node.js HTTP applications

I'm facing an issue resolving this error in my code. It works perfectly fine on my local environment, but once it reaches the 'http.get' call, it keeps throwing the error: "listener argument must be a function." Both Nodejs versions are iden ...

Client.db is undefined error encountered in MongoDB backend API

I'm having trouble retrieving data from a collection in my MongoDB backend. Every time I try, I encounter an error stating that the client is not defined. Has anyone else experienced this issue and knows how to resolve it? Error: Client is not define ...

Numerous routers available for enhancing functionality in an Ember application

Can an Ember app have multiple router.js files? By default, one router.js file will look like this: import Ember from 'ember'; import config from '../../config/environment'; var Router = Ember.Router.extend({ location: config.locat ...

Communicating between a Python Client and a nodeJS Server using Socket.IO

I am attempting to transmit data from my Raspberry Pi (using Python 2.7.9) to my NodeJS server with socket.io. My objective is to continuously send multiple values from my Pi through a websocket connection to my local Node Server, which will then display ...

Retrieve information from a sensor within an Express server and display it on the user interface

Looking for suggestions on resolving a challenge: I have a Node.js module that retrieves data from a sensor, and I am interested in incorporating a UI element to showcase the sensor data (either in real-time or pseudo-realtime). Is there a way to establ ...

Having trouble with installing Vue CLI?

I am encountering issues while attempting to set up VueJS. I am currently utilizing Bash on Ubuntu on Windows node -v v15.12.0 npm -v 7.6.3 Initially, I attempted the following: npm install -g @vue/cli However, this resulted in various warnings and ...

Encountering difficulties with installing firebase tools

Struggling with installing Firebase all morning, I followed the official tutorial on setting up Firebase hosting using the command line: npm install -g firebase-tools However, I kept encountering errors. Here's the error message that appeared: pm WA ...

Accessing robots.txt through Node.js routes is not displaying the expected plain text content

I'm going crazy trying to figure this out... I added a route in my router configuration to serve a plain text robots.txt file. The strange thing is, the /robots.txt route works fine on my local machine, but once deployed to the server, it just doesn&a ...

Having trouble executing 'npm install' command

I've been attempting to utilize micromdm-ui, but I keep encountering errors when trying to run npm i. Here is the output: npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '<a href="/cdn-cgi/l/email-protection" class="__ ...

Running a JavaScript test using the Mocha framework with an 'import' statement for a JS file

I am familiar with the module.export and require method: Requiring external js file for mocha testing While it is useful when dealing with modules, I find it inconvenient as I now need to test code in a specific file. For example, I have code in a file: ...

Sending information from a rails controller to a react component

Wondering how to pass the example @post = Post.all from the controller to React component props while integrating Rails with React via Webpacker. Is it necessary to do this through an API or is there another way? ...

decoding JSON node in Android

I am new to Android development. I have written a request code in Node.js to retrieve data from a database table. When I test this using Postman, it returns the JSON data correctly. However, when I run the same code in Android Studio, the response is empty ...

Tips for correctly sending the response code from a Node.js API

I have a straightforward node-based API that is responsible for parsing JSON data, saving it into a Postgres database, and sending the correct response code (e.g., HTTP 201). Here is an excerpt of my code: router.route('/customer') .post(fu ...

Executing npx triggers a node version that is not currently installed on my system

When attempting to execute the command npx create-react-app my-app, I encountered the following error: Error @typescript-eslint/[email protected]: The engine "node" is incompatible with this module. Expected version "^10.12.0 || >=12.0.0". Got "11.13.0" ...

Open the CSV document

Why am I receiving an error stating ./vacancy-data.csv cannot be found when attempting to pass the csv file into the csvtojson npm package? The csv file is located in the same directory as the code below: var express = require('express'), route ...

Is there a way for me to ensure that a response is only returned once a method call has been completed in

Seeking assistance with a Node.js application using Express. I am trying to create a REST endpoint that returns the response of an HTTP call. However, no matter what I attempt, it always returns before the HTTP request has completed. Can anyone provide g ...

When configuring a domain for Express sessions, it prevents the cookie from being stored

I have encountered an issue with my node.js service application and react frontend. I am utilizing Discord OAuth and express sessions for authentication on my application frontend. Everything functions perfectly when running locally, but upon deploying to ...

Accessing information from req.files in a TypeScript environment

I am currently using multer for uploading images. How can I retrieve a specific file from req.files? Trying to access it by index or fieldname has been unsuccessful. Even when I log it, I see that it's a normal array, so I suspect the issue may be rel ...

How to access a static TypeScript variable in Node.js across different files

I encountered a situation like this while working on a node.js project: code-example.ts export class CodeExample { private static example: string = 'hello'; public static initialize() { CodeExample.example = 'modified'; } ...