skip to Main Content

I want to run my index.js file to access graphql endpoints so i can be able to query the data, access it but i keep getting the ‘ module not found’ error code.

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App.jsx';
import 'bootstrap/dist/css/bootstrap.css';
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
import { ApolloServer, gql } from 'apollo-server-express';
import { typeDefs } from './Schema/type-defs'; 
import { resolvers } from './Schema/resolvers'; 


const server = new ApolloServer({
  typeDefs,
  resolvers,
});


const client = new ApolloClient({
  uri: 'http://localhost:4000',
  cache: new InMemoryCache(),
});


ReactDOM.render(
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>,
  document.getElementById('root')
);


console.log('GraphQL server running at http://localhost:4000/graphql');

I have tried checking if the file is in the directory where nodejs can find it.

2

Answers


  1. I’m assuming you have issues with importing from apollo-server-express. Per the documentation, this package is now deprecated. You should use @apollo/server instead.

    On a related note, you are mixing server code into your React application, which will run on the client. These two things should run as completely separate applications.

    Login or Signup to reply.
  2. check all the following packages installed with npm

    @apollo/client,apollo-server-express

    and nodemon as dev dependency

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