Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Apollo GraphQL解析器上在一个函数中解析两种不同的方法?_Javascript_Ecmascript 6_Graphql_Apollo - Fatal编程技术网

Javascript 如何在Apollo GraphQL解析器上在一个函数中解析两种不同的方法?

Javascript 如何在Apollo GraphQL解析器上在一个函数中解析两种不同的方法?,javascript,ecmascript-6,graphql,apollo,Javascript,Ecmascript 6,Graphql,Apollo,我有这个解析器 SLAccount: (_, { imsUserId, imsToken }, context) => new Promise((resolve, reject) => { addAuth(context, imsUserId, imsToken); context.model .getUserAccount(getEndpoint(imsUserId, imsToken)) .then(resolve) .ca

我有这个解析器

SLAccount: (_, { imsUserId, imsToken }, context) =>
  new Promise((resolve, reject) => {
    addAuth(context, imsUserId, imsToken);
    context.model
      .getUserAccount(getEndpoint(imsUserId, imsToken))
      .then(resolve)
      .catch(reject);
  }),
但我还需要包括另一种方法/模型:

  getHardware(endpoint) {
    return this.connector
      .get(
        `${endpoint}/...`,
      )
      .catch(res => this.handleError(res));
  }
所以我需要这样的东西:

SLAccount: (_, { imsUserId, imsToken }, context) =>
  new Promise((resolve, reject) => {
    addAuth(context, imsUserId, imsToken);
    context.model
      .getUserAccount(getEndpoint(imsUserId, imsToken))
      .then(resolve)
      .catch(reject);

    context.model
      .getHardware(getEndpoint(imsUserId, imsToken))
      .then(resolve)
      .catch(reject);
  }),
问题是我不需要同时调用它们,有时我只需要SLAccount中的一个方法/模型


那么,处理这个问题的最佳方法是什么呢?

GraphQL是由需求查询驱动的

当您需要帐户时,只需查询即可。当您需要帐户和相关硬件时,只需查询两者-将自动调用其他解析器。这是graphQL背后的一个基本思想。在graphQL中查找任何涵盖关系的教程