parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.94k stars 4.78k forks source link

Cannot read property 'parseGraphQLController' of undefined #6567

Closed jcguarinpenaranda closed 4 years ago

jcguarinpenaranda commented 4 years ago

Issue Description

Hello,

I am getting the following error when I create the GraphQL server with express:

TypeError: Cannot read property 'parseGraphQLController' of undefined
    at new ParseGraphQLServer (some-path\node_modules\parse-server\src\GraphQL\ParseGraphQLServer.js:27:59)
    at Object.<anonymous> (some-path\src\index.ts:33:30)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Module.m._compile (some-path\node_modules\ts-node\src\index.ts:837:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Object.require.extensions.<computed> [as .ts] (some-path\node_modules\ts-node\src\index.ts:840:12)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at main (some-path\node_modules\ts-node\src\bin.ts:226:14)

Steps to reproduce

The code that I wrote is the following. All I do is create a Parse server + graphQL + dashboard, as follows:

   const app = express();
  const PORT = process.env.PORT;
  const api = new ParseServer({
    databaseURI: process.env.DB_URI,
    cloud: (getEnv() === "development") ?
      path.join(__dirname, "cloud.ts") : // on development, use the ts file
      path.join(__dirname, "cloud.js"),
    appId: process.env.APP_ID,
    fileKey: process.env.FILE_KEY,
    masterKey: process.env.MASTER_KEY,
    serverURL: process.env.SERVER_URL,
    publicServerURL: process.env.SERVER_URL,
  });

  const parseGraphQLServer = new ParseGraphQLServer(
    api,
    {
      graphQLPath: '/graphql',
      playgroundPath: '/playground'
    }
  );

  const dashboard = new ParseDashboard({
    apps: [
      {
        serverURL: process.env.SERVER_URL, // http://localhost:1337/parse
        graphQLServerURL: process.env.SERVER_GRAPHQL_URL, // http://localhost:1337/graphql
        appId: process.env.APP_ID,
        masterKey: process.env.MASTER_KEY,
        appName: process.env.APP_NAME
      }
    ]
  });

  app.use("/parse", api.app);
  parseGraphQLServer.applyGraphQL(app);
  parseGraphQLServer.applyPlayground(app);
  app.use("/dashboard", dashboard);

  app.listen(PORT, () => {
    // tslint:disable-next-line
    console.log(`App running on port ${PORT}`);
  });

Expected Results

The GraphQL endpoint should be mounted correctly and the application should not crash.

Actual Outcome

The application crashes due to an error with the GraphQL srever

Environment Setup

My dependencies are:

  "dependencies": {
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "parse": "^2.12.0",
    "parse-dashboard": "^2.0.5",
    "parse-server": "^4.2.0"
  }
davimacedo commented 4 years ago

Can you please share how you are importing the ParseServer and ParseGraphQLServer vars? You should try something like this:

const { default: ParseServer, ParseGraphQLServer } = require('parse-server');
jcguarinpenaranda commented 4 years ago

Hello @davimacedo, Thank youy so much, I confirm it's working :) Juan

chrisk8er commented 3 years ago

Can you please share how you are importing the ParseServer and ParseGraphQLServer vars? You should try something like this:

const { default: ParseServer, ParseGraphQLServer } = require('parse-server');

Hi @davimacedo, I got a new error after I changing the code.


2021-03-11T05:44:15.630914+00:00 app[web.1]: > node index.js
2021-03-11T05:44:15.630914+00:00 app[web.1]: 
2021-03-11T05:44:18.757458+00:00 app[web.1]: /app/node_modules/express/lib/router/index.js:458
2021-03-11T05:44:18.757487+00:00 app[web.1]:       throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
2021-03-11T05:44:18.757489+00:00 app[web.1]:       ^
2021-03-11T05:44:18.757489+00:00 app[web.1]: 
2021-03-11T05:44:18.757490+00:00 app[web.1]: TypeError: Router.use() requires a middleware function but got a Object
2021-03-11T05:44:18.757491+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/router/index.js:458:13)
2021-03-11T05:44:18.757493+00:00 app[web.1]:     at Function.<anonymous> (/app/node_modules/express/lib/application.js:220:21)
2021-03-11T05:44:18.757494+00:00 app[web.1]:     at Array.forEach (<anonymous>)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/application.js:217:7)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:47:7)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Module._compile (node:internal/modules/cjs/loader:1092:14)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Module.load (node:internal/modules/cjs/loader:972:32)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Function.Module._load (node:internal/modules/cjs/loader:813:14)
2021-03-11T05:44:18.757497+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
winstechnology commented 3 years ago

Same problem. Cant get it running.

juniarz commented 3 years ago

For those who are facing the problem:

1) const ParseServer = require('parse-server').default; and const ParseServer = require('parse-server').ParseServer; is different.

2) To fix this issue, use const { default: ParseServer, ParseGraphQLServer } = require('parse-server');. And change app.use(mountPath, api); to app.use(mountPath, api.app);.

anhtuank7c commented 3 years ago

To anyone who uses TypeScript, follow this import

import { ParseGraphQLServer, default as ParseServer } from 'parse-server'
import express from 'express'

const app = express()
const parseServer = new ParseServer(config) // passing configs as normal

// mounts the RESTFull API (optionals)
app.use('/parse', parseServer.app)

const parseGraphQLServer = new ParseGraphQLServer(
  parseServer,
  {
    graphQLPath: '/graphql',
    playgroundPath: '/playground'
  }
)

// Mounts the GraphQL API
parseGraphQLServer.applyGraphQL(app)

// Mounts the GraphQL Playground API (optionals)
if (isDev) {
  parseGraphQLServer.applyPlayground(app)
}

app.listen(1337, () => {
   console.log('Server is online')
})