async await inside function not working properly?

混江龙づ霸主 提交于 2019-12-12 04:44:07

问题


I have this function, that i need to define an async function inside it:

  _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);
  };

but there's no returned value on refetchVariables, it only had when I do not use async but i need to perform await for this code, and I need access on fragmentVariables:

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

maybe making refetchVariables not an async works? but I have no idea how to code it. help? btw this is the value returned on async refetchVariables:

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

来源:https://stackoverflow.com/questions/45987879/async-await-inside-function-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!