1

I'm building a single GraphQL endpoint that has underlying REST services being called from different end points. I was able to execute Query successfully, but for mutation I refer a separate endpoint. How can I incorporate this in my code?

export class VinylAPI extends RESTDataSource {
  constructor() {
    super();
    this.baseURL = 'https://api.whitelabel.com/v2/';
  } // I have one more different URL I want to use
Min Yoongi
  • 396
  • 5
  • 16

1 Answers1

1

Thanks to @Ajantha Bandara comment, I was able to solve the above question. I defined another data source with different URL and created a second instance of it in Apollo server i.e.

class VinylAPI extends RESTDataSource {
  constructor() {
   super();
    this.baseURL = 'https://api.whitelabel.com/v2/';
  }

 class SecondAPI extends RESTDataSource {
   constructor() {
     super();
    this.baseURL = 'https://something.whitelabel.com/v5/';
  }

 const server = new ApolloServer({
  // All initialisation
 return {
 a:new VinylAPI,
 b:new SecondAPI
}

})

Min Yoongi
  • 396
  • 5
  • 16