0

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

  _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 不是异步工作?但我不知道如何编码。帮助?顺便说一句,这是异步 refetchVariables 返回的值:

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

0 回答 0