async await inside function not working properly?

407 Views Asked by At

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

There are 0 best solutions below