0

我正在构建一个单一的 GraphQL 端点,该端点具有从不同端点调用的底层 REST 服务。我能够成功执行查询,但是对于突变,我引用了一个单独的端点。如何将其合并到我的代码中?

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

1 回答 1

0

感谢@Ajantha Bandara 的评论,我能够解决上述问题。我用不同的 URL 定义了另一个数据源,并在 Apollo 服务器中创建了它的第二个实例,即

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
}

})

于 2022-01-03T12:49:05.153 回答