You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/tutorial/queries.md
+56-44Lines changed: 56 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,8 @@ import { Query } from 'react-apollo';
25
25
importgqlfrom'graphql-tag';
26
26
importstyledfrom'react-emotion';
27
27
28
+
importLaunchTilefrom'./launch-tile';
29
+
28
30
constLIST_LAUNCHES=gql`
29
31
querylaunchList($after: String) {
30
32
isLoggedIn@client
@@ -98,10 +100,12 @@ To fetch data using the `Query` component, a query string needs to be passed to
98
100
99
101
The `Query` component uses a render prop pattern, so we passed a function as a child to the component that contains what React will render to the screen. The `Query` component provides us with a `loading`, `error`, and `data` property that keeps the user informed about the status of the query operation on the screen. If it's in a loading state, the user sees **Loading...** on the screen. If there's an error, the user sees **ERROR** on the screen.
100
102
101
-
If the data was returned successfully, then the launches are retrieved from the `data` property and displayed on the screen via the `LaunchTile` component.
103
+
If the data was returned successfully, then the launches are retrieved from the `data` property and displayed on the screen via the `LaunchTile` component. For now, you can copy the contents of `src/components/launch-tile.js` from the [Launch Tile component on GitHub](https://github.com/apollographql/fullstack-tutorial/blob/client/client/src/components/launch-tile.js).
102
104
103
105
Now, there are a lot of launches. If all the launches are fetched at once and displayed, the result will be a long undesirable list. Therefore, let's build a pagination feature that accomodates the loading of a few items at once and display a `Load More` button for loading more items on the screen.
104
106
107
+
The `@client` directive added to the `isLoggedIn` field fetches local data from the Apollo Cache instead of making a network request like the rest of the fields in the `launchlist` query. You'll know more about this in the [Managing local State](./local-state.html) section.
108
+
105
109
<h2id="pagination">Build a paginated list</h2>
106
110
107
111
There are different approaches to building a paginated list. You'll build a pagination feature using the `cursor-based` approach. The cursor keeps track of where in the data set the next items should be fetched from.
@@ -111,52 +115,60 @@ In the code below, we use a `fetchMore` query to continuously load new launches,
111
115
Copy the code below and add to the `LaunchList` class.
The easiest way to go about pagination with Apollo is with the `fetchMore` function which is provided as a property by the `Query` component. By default, 20 launches are returned at once. Why 20? The paginate helper function in the `src/utils.js` file accepts a page size of 20 if no argument was passed to specify the number of launches to return.
0 commit comments