From 072eca0e5038a7755ca9b2c94dfe1a0c3f110968 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 24 May 2018 15:19:21 -0400 Subject: colocate queries and components --- frontend/components/Pagination.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'frontend/components/Pagination.js') diff --git a/frontend/components/Pagination.js b/frontend/components/Pagination.js index 380026d..8b25e06 100644 --- a/frontend/components/Pagination.js +++ b/frontend/components/Pagination.js @@ -3,8 +3,18 @@ import { Query } from 'react-apollo'; import styled from 'styled-components'; import Link from 'next/link'; import PropTypes from 'prop-types'; +import gql from 'graphql-tag'; import { perPage } from '../config'; -import { ALL_ITEMS_QUERY } from '../queries/queries.graphql'; + +const PAGINATION_QUERY = gql` + query itemsConnection($skip: Int = 0, $first: Int = 4) { + itemsConnection(orderBy: createdAt_DESC, first: $first, skip: $skip) { + aggregate { + count + } + } + } +`; const PaginationStyles = styled.div` text-align: center; @@ -31,7 +41,7 @@ const PaginationStyles = styled.div` `; const Pagination = props => ( - + {({ data, loading, error }) => { if (loading || error) return null; const { aggregate } = data.itemsConnection; @@ -78,3 +88,4 @@ Pagination.propTypes = { }; export default Pagination; +export { PAGINATION_QUERY }; -- cgit v1.3