-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[apollo-datasource-rest] - "TypeError cannot read property of 'fetch' of undefined" #2240
Comments
AH! I for some reason node-fetch wasn't included as a dependency! please close, sorry. |
I just ran into this and had to call
|
@jplock What version of Apollo Server were you using that Data Source with? Did you have that data source declared in the apollo-server/packages/apollo-server-core/src/requestPipeline.ts Lines 450 to 464 in 8850e0f
|
@abernix we're using |
Aha, that makes sense. Since I'll close this, but happy to assist further if I can be of help. |
Hit this issue. After reading @abernix 's explain. Here is my case: I don't inject my application datasources to const context = {} as ApplicationContext;
const cache = new InMemoryLRUCache();
const httpDataSourceConfig: DataSourceConfig<ApplicationContext> = { context, cache };
const customerDataSource = new CustomerDataSourceImpl(googleAdwordsDataSourceOptions);
customerDataSource.initialize(httpDataSourceConfig);
const managedCustomerDataSource = new ManagedCustomerDataSourceImpl({
baseURL: `https://us-central1-${process.env.GOOGLE_CLOUD_PROJECT}.cloudfunctions.net/`,
});
managedCustomerDataSource.initialize(httpDataSourceConfig);
const managedCustomerService = new ManagedCustomerService({
managedCustomerDataSource,
googleAccountDataSource,
userDataSource,
googleAdwordsDataSource,
}), And, I inject these serivces to Apollo context. If you don't call P.S. You can use some IoC implements the DIP, instead of using |
In my case error was in ~\node_modules\apollo-datasource-rest\src\RESTDataSource.ts, line await this.httpCache.fetch(request I resolved this by initializing httpCache as: constructor() { So it's not null. |
@mImranAziz DataSources have their apollo-server/packages/apollo-server-core/src/requestPipeline.ts Lines 580 to 587 in 1948d24
The default apollo-server/packages/apollo-server-core/src/ApolloServer.ts Lines 212 to 214 in 489cbb4
Do any of these things sound possible? Your workaround shouldn't be necessary. |
@abernix I also needed to use @mImranAziz fix. Running apollo server 2.8.1 as well. My solution was to not override |
@abernix Why does "DataSources have their initialize method called automatically by Apollo Server"? Is it necessary? Why not put the initializer() into the constructor? Or at least write this trick into document. |
@abernix |
And what does it mean? What actions are you expecting from us after your AH!-answer? |
I had the same problem with You can see my comments about it here |
Node - 10.15.0
Typescript - 3.1.2
apollo-datasource-rest - 0.1.5
I have a very simple data source class that extends the RESTDataSource class and makes a GET call to the star wars api. However at run time I'm getting the following error - "TypeError cannot read property fetch of undefined" which is located from line 148 in the RESTDataSource.js file on the following line -
const response = yield this.httpCache.fetch(...
The text was updated successfully, but these errors were encountered: