异步等待内部函数不能正常工作?

时间:2017-08-31 18:25:08

标签: javascript reactjs relayjs relaymodern

我有这个功能,我需要在其中定义一个异步函数:

  _refetchConnection = (page) => { // query for cursor page

    const refetchVariables =  async (fragmentVariables) => {
    let pageCursor;
    if(page !== 1) {
      const getAfterCursorQueryText = `
        query($count: Int!, $cursor:String) {# filename+Query
          viewer {
            publicTodos (first: $count, after: $cursor) {
              edges {
                cursor
                node {
                  id
                }
              }     

           pageInfo { # for pagination
            hasPreviousPage
            startCursor 
            hasNextPage
            endCursor 
          }         
            }
          }
        }`;
      let cursor = fragmentVariables.cursor;
      let count = 5;
      const getAfterCursorQuery = { text: getAfterCursorQueryText };
      const result = await this.props.relay.environment._network.fetch(getAfterCursorQuery, {cursor, count});

      pageCursor = result.data.viewer.publicTodos.pageInfo.endCursor;

    } else if (page === 1) {
      pageCursor = null;
    } 

      return {
          cursor: pageCursor,
          count:5 
        }
  }
    this.props.relay.refetch(refetchVariables, null);
  };

但是refetchVariables没有返回值,它只有在我不使用异步但我需要执行等待此代码的时候,我需要访问fragmentVariables:

const result = await this.props.relay.environment._network.fetch(getAfterCursorQuery, {cursor, count});

也许使refetchVariables不是异步工作?但我不知道如何编码。救命?顺便说一下这是async refetchVariables上返回的值:

ƒ refetchVariables(_x2) {
                    return _ref3.apply(this, arguments);
                  }

0 个答案:

没有答案
相关问题