TypeError: Class constructor RESTDataSource cannot be invoked without 'new'
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.
Hmm that's strange. Does this code work in your Lambda functions? As in, is this an issue with just the tests?
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.
@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!
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?
https://github.com/apollographql/apollo-server/issues/2216#issuecomment-790088169