Class constructor RESTDataSource cannot be invoked without 'new' using Babel
See original GitHub issueVery 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:
- Created 5 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have tried all the workarounds I could find and still have the issue. Could this be reopened?
@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.