The first argument to this.get and other verbs must be non-null.
resolveURL function in apollo-datasource-rest/src/RESTDataSource.ts (https://github.com/apollographql/apollo-server/blob/39e678c58f984a52c8d5299449c333bda9f1e0be/packages/apollo-datasource-rest/src/RESTDataSource.ts#L76) calls path.startsWith('/') therefore path must be non-null (as can also be seen in Typescript definition of RequestOptions). However, there're use cases where only root url needs to be accessed in the API so this.get() can be called without any additional pathname or query params. This should be mentioned in the docs.
this is the use case I recently ran into:
import { RESTDataSource } from 'apollo-datasource-rest'
class MyAPI extends RESTDataSource {
constructor() {
super()
this.baseURL = 'https://myapi.com'
this.rootUrl = '/'
}
async getPromotion() {
return this.get(this.rootUrl)
}
}
In order to make the MyAPI work I had to use this.rootUrl because the first argument to this.get must be non-null. Of course, I'd rather call return this.get(). But in the absence of such option at least it should be mentioned in the docs that the first argument must be non-null.
Hey @yossisp, sorry for the delay. The REST datasource package has migrated to https://github.com/apollographql/datasource-rest. If this change is still interesting to you I'd be happy to review a PR over there.