Say I have an 2 API classes that extend RESTDataSource:
class MoviesAPI extends RESTDataSource {
async getMovies() {}
}
class SongsAPI extends RESTDataSource {
async getSongs() {}
}
How can I call getSongs
from getMovies
within the existing Apollo server context?
You can get the apollo server context via
this.context
in the datasource class and getdataSources
viathis.context.dataSources
.E.g.
server.ts
:MoviesAPI.ts
:SongsAPI.ts
:Send a GraphQL query from the client-side:
Response payload:
Package versions:
"apollo-datasource-rest": "^0.8.1"
,"apollo-server": "^2.12.0"
source code: https://github.com/mrdulin/apollo-graphql-tutorial/tree/master/src/stackoverflow/61425326