1

i have this async code:

const getResult = async () => {
          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});
          return Promise.resolve(result)
        }
        pageCursor = getResult().then( result => {
          return result.data.viewer.publicTodos.pageInfo.endCursor;
        })

but pageCursor has value of a promise:

Promise proto : Promise [[PromiseStatus]] : "resolved" [[PromiseValue]] : "YXJyYXljb25uZWN0aW9uOjQ="

how do I return the value?

gpbaculio
  • 5,693
  • 13
  • 60
  • 102
  • Why do you return a promise in an `async` function? You should probably use one or the other ? – adeneo Aug 31 '17 at 19:14
  • this is not the full code: https://stackoverflow.com/questions/45987879/async-await-inside-function-not-working-properly?noredirect=1#comment78936575_45987879, I need to get the value of this.props.relay.environment._network.fetch(getAfterCursorQuery, {cursor, count}); – gpbaculio Aug 31 '17 at 19:16
  • This question is definitely NOT a duplicate of https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call. – Lennholm Aug 31 '17 at 19:16
  • Either use conventional promises and resolve your results or use async await. Don't try to combine the two. I recommend going through [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) Link – Nitish Phanse Aug 31 '17 at 19:16
  • Short answer: `return result` instead of `return Promise.resolve(result)` – Lennholm Aug 31 '17 at 19:18
  • Yes of course `pageCursor` is a promise. You did use `then()` to create it, right? – Bergi Aug 31 '17 at 19:50

0 Answers0