我有这个功能,我需要在其中定义一个异步函数:
_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);
}