serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

TypeError: Class constructor RESTDataSource cannot be invoked without 'new'

Open DuncanLewis opened this issue 5 years ago • 5 comments

When trying to run a test that utilises Apollo GraphQL REST Data Source I'm facing the following error:

 TypeError: Class constructor RESTDataSource cannot be invoked without 'new'

      3 | class MatchAPI extends RESTDataSource {
      4 |   constructor() {
    > 5 |     super();
        |     ^
      6 |     this.baseURL = 'https://api-dev.playerslounge.co/v1/';
      7 |   }
      8 | 

A fix for the particular issue is listed here: https://github.com/apollographql/apollo-server/issues/2216 - but I'm unable to implement this while using serverless-bundle.

Note that if I just run jest as the test command, rather than serverless-bundle test, I don't face the issue.

DuncanLewis avatar Feb 06 '20 14:02 DuncanLewis

Hmm that's strange. Does this code work in your Lambda functions? As in, is this an issue with just the tests?

jayair avatar Feb 08 '20 19:02 jayair

Hmm that's strange. Does this code work in your Lambda functions? As in, is this an issue with just the tests?

@jayair Yeah thats correct, it works fine when run in Lambda environment but when running in tests it fails.

DuncanLewis avatar Feb 10 '20 11:02 DuncanLewis

@jayair This is still happening and haven't been able to figure this out for myself yet - any suggestions for implementing the suggested fix on the apollo repo?

As a reminder, this was the suggested fix:

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "plugins": ["@babel/plugin-transform-runtime"]
}

Thank you!

DuncanLewis avatar Mar 21 '20 16:03 DuncanLewis

Ah @DuncanLewis I think we might need to add this plugin to the Jest config for the tests. Can you possibly try adding it here and testing it? https://github.com/AnomalyInnovations/serverless-bundle/blob/master/scripts/config/babelJestTransform.js#L6

If it works, open a PR with it?

jayair avatar Mar 30 '20 21:03 jayair

https://github.com/apollographql/apollo-server/issues/2216#issuecomment-790088169

jrvidotti avatar Mar 03 '21 21:03 jrvidotti