GraphQL возвращает "Не удается запросить поле \" курсор \ "в запросах на нумерацию страниц - PullRequest
0 голосов
/ 17 апреля 2020

Я выполняю разбиение на страницы с GraphQL, reactjs, клиентом apollo, express сервером, но мне кажется, что мой инструмент разработчика сервера-песочницы не принимает ни одно из зарезервированных слов, указанных в официальных документах, для разбивки на страницы, вместо этого возвращайте ошибки:

"message": "Невозможно запросить поле \" курсор \ "" message ":" Неизвестный аргумент \ "last \" "message": "Невозможно запросить поле \" pageInfo \ "" message ":" Неизвестный аргумент \ "страница \" на

нужно ли мне что-то включать в схемах или моделях?

const MORE_COMMENTS_QUERY = gql`
  query MoreComments($cursor: String) {
    moreComments(cursor: $cursor) {
      cursor
      comments {
        author
        text
      }
    }
  }
`;

function CommentsWithData() {
  const { data: { comments, cursor }, loading, fetchMore } = useQuery(
    MORE_COMMENTS_QUERY
  );

  return (
    <Comments
      entries={comments || []}
      onLoadMore={() =>
        fetchMore({
          // note this is a different query than the one used in the
          // Query component
          query: MORE_COMMENTS_QUERY,
          variables: { cursor: cursor },
          updateQuery: (previousResult, { fetchMoreResult }) => {
            const previousEntry = previousResult.entry;
            const newComments = fetchMoreResult.moreComments.comments;
            const newCursor = fetchMoreResult.moreComments.cursor;

            return {
              // By returning `cursor` here, we update the `fetchMore` function
              // to the new cursor.
              cursor: newCursor,
              entry: {
                // Put the new comments in the front of the list
                comments: [...newComments, ...previousEntry.comments]
              },
              __typename: previousEntry.__typename
            };
          }
        })
      }
    />
  );
...