question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Class constructor RESTDataSource cannot be invoked without 'new' using Babel

See original GitHub issue

Very similar in nature to https://github.com/apollographql/apollo-server/issues/1388, but I’m using Babel, not TypeScript

When using babel with apollo-datasource-rest I am getting the Class constructor RESTDataSource cannot be invoked without 'new'. Here’s a simplified version of my code.

// myapi.js
import { RESTDataSource } from "apollo-datasource-rest";

export default class extends RESTDataSource {
  constructor() {
    super();
    this.baseURL = "http://example.com";
  }

  hello() {
    return "Hello World!";
  }
}
// server.js
import express from "express";
import { ApolloServer } from "apollo-server-express";
import schema from "./data/schema";
import MyAPI from "./data/api/myapi";

const app = express();

const server = new ApolloServer({
  schema,
  dataSources: () => ({ MyAPI: new MyAPI() }),
});

server.applyMiddleware({ app, path: "/graphql" });

app.listen(8080, () => console.log(`Server is now running`));
// schema.js
import { makeExecutableSchema, gql } from "apollo-server-express";

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const resolvers = {
  Query: {
    hello: (_, __, { dataSources: { MyAPI } }) => MyAPI.hello(),
  },
};

const schema = makeExecutableSchema({ typeDefs, resolvers });

export default schema;

Is there any way that I can utilize apollo-datasource-rest with babel?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
mschipperheyncommented, Feb 3, 2019

I have tried all the workarounds I could find and still have the issue. Could this be reopened?

5reactions
sbrichardsoncommented, Aug 21, 2018

@danlunde - I added a pull request to your example repo, it seemed to have resolved the error, can you review? I’m not a babel expert, I just swapped out a few dev dependencies to what I use for starter repos and I didn’t get any errors afterward.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class constructor DataSource cannot be invoked without 'new ...
I created my own Custom DataSource class using Knex as the backend, but I keep getting this error about my call to the...
Read more >
Class constructor cannot be invoked without 'new' - typescript ...
I found a solution based on ES6/Babel Class constructor cannot be invoked without 'new'. I needed to explicitly include colyseus in my babel...
Read more >
Class constructor cannot be invoked without 'new' in TS
The "Class constructor cannot be invoked without new" error occurs when the target property in tsconfig.json is set to lower than es6 or...
Read more >
babel class constructor cannot be invoked without 'new'
Constructors requires the use of the new operator to create a new instance, as such invoking a class without the new operator results...
Read more >
Javascript ES6 TypeError Class constructor Client cannot be ...
When I try to execute nodemon command I always see this error TypeError: Class constructor Client cannot be invoked without 'new'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found