-1

Here's my server setup:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => ({
    movieAPI: new MovieAPI()
  }),
  context: {
    hello: `world`
  }
});

server
  .listen({ port: 4000 })
  .then(({ url }) => console.log(` app running at ${url}`));

If I remove datasources everything works fine, otherwise I get an error in graphql playground "error": "Response not successful: Received status code 500"

I'm doing this Apollo Server tutorial but I have some babel config so I can use es6 syntax.

Here is my repo

karolis2017
  • 2,195
  • 8
  • 24
  • 49
  • I'm facing similar issues. I'm using axios for now. Check this link out, it might be helpful https://github.com/apollographql/apollo-server/issues/1828 – Deadfish Nov 26 '18 at 12:34

5 Answers5

4

in playground GUI there is a button: COPY CURL if you try it in the terminal you can get more details about the error. I had same problem and I got this response from curl:

{
  "errors": [
    {
      "message": "Class constructor DataSource cannot be invoked without 'new'",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "TypeError: Class constructor DataSource cannot be invoked without 'new'",
            "    at new UserAPI (/var/www/html/blog-project/server/src/datasources/user.ts:12:5)",
            "    at Object.dataSources (/var/www/html/blog-project/server/src/index.ts:30:14)",
            "    at /var/www/html/blog-project/server/node_modules/apollo-server-core/src/requestPipeline.ts:618:34",
            "    at Generator.next (<anonymous>)",
            "    at /var/www/html/blog-project/server/node_modules/apollo-server-core/dist/requestPipeline.js:8:71",
            "    at new Promise (<anonymous>)",
            "    at __awaiter (/var/www/html/blog-project/server/node_modules/apollo-server-core/dist/requestPipeline.js:4:12)",
            "    at initializeDataSources (/var/www/html/blog-project/server/node_modules/apollo-server-core/dist/requestPipeline.js:323:20)",
            "    at Object.<anonymous> (/var/www/html/blog-project/server/node_modules/apollo-server-core/src/requestPipeline.ts:117:9)",
            "    at Generator.next (<anonymous>)",
            "    at /var/www/html/blog-project/server/node_modules/apollo-server-core/dist/requestPipeline.js:8:71",
            "    at new Promise (<anonymous>)",
            "    at __awaiter (/var/www/html/blog-project/server/node_modules/apollo-server-core/dist/requestPipeline.js:4:12)",
            "    at Object.processGraphQLRequest (/var/www/html/blog-project/server/node_modules/apollo-server-core/dist/requestPipeline.js:41:12)",
            "    at /var/www/html/blog-project/server/node_modules/apollo-server-core/src/runHttpQuery.ts:310:32",
            "    at Generator.next (<anonymous>)"
          ]
        }
      }
    }
  ]
}

after search about Class constructor DataSource cannot be invoked without 'new' I found this solution

This problem should be solved in Node.js by setting TypeScript target option to es6. Modern Node.js versions support ES6 classes, there is no need to transpile them.

so the solution: in tsconfig.json setting target to es6

HosseinNedaee
  • 500
  • 5
  • 6
0

adding introspection: true solved the issue

karolis2017
  • 2,195
  • 8
  • 24
  • 49
  • 3
    Can you please be more specific. Adding introspection where? – Trevor de Koekkoek Sep 19 '19 at 08:39
  • 1
    Although the solution didn't work for me, `introspection: true` is an option in the ApolloServer config. [See Here](https://www.apollographql.com/docs/apollo-server/testing/graphql-playground/) – Cory Kleiser Jul 24 '20 at 17:13
0

in the setting of playground change request.credentials: "omit", to "request.credentials": "include".

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
0

For those using TypeScript and the Serverless Framework with AWS:

Make sure your tsconfig.json has the compilerOptions.target set to "es6" and compilerOptions.module set to "CommonJS".

It looks like this could be an issue with over-transpiling code(ref). So we need to set "target": "es6" as to include the class keyword. This presents a problem with the use of es6 modules, hence the need for the "module": "CommonJS" in the tsconfig.json

Full tsconfig.json

{
  "compilerOptions": {
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "allowJs": true,
    "target": "es6",
    "outDir": ".build",
    "moduleResolution": "node",
    "lib": ["es2015"],
    "rootDir": "./",
    "module": "CommonJS"
  }
}
Cory Kleiser
  • 1,969
  • 2
  • 13
  • 26
0

if you could have provided the error stack trace with the question then it would have been great!

There could be many reasons for why you got the 500 response from the apollo server but I am just gonna talk about the general reasons. For others, who are still facing this issue. Mostly, this should be an issue with the way you are creating and connecting the datasource to the apollo server. Please, look at the stacktrace of the error and for resolving the issue.

Ashfaq nisar
  • 2,500
  • 1
  • 12
  • 22