@@ -4,6 +4,20 @@ Integrates [apollo](http://www.apollostack.com/) in your vue components with dec
44
55[ Apollo "hello world" app] ( https://github.com/Akryum/frontpage-vue-app )
66
7+ - [ Installation] ( #installation )
8+ - [ Usage] ( #usage )
9+ - [ Configuration] ( #configuration )
10+ - [ Usage in components] ( #usage-in-components )
11+ - [ Queries] ( #queries )
12+ - [ Simple query] ( #simple-query )
13+ - [ Query with parameters] ( #query-with-parameters )
14+ - [ Reactive parameters] ( #reactive-parameters )
15+ - [ Advanced options] ( #advanced-options )
16+ - [ Reactive Query Example] ( #reactive-query-example )
17+ - [ Mutations] ( #mutations )
18+ - [ Subscriptions] ( #subscriptions )
19+ - [ Pagination with ` fetchMore ` ] ( #pagination-with-fetchMore )
20+
721## Installation
822
923
@@ -69,6 +83,8 @@ apollo: {
6983},
7084```
7185
86+ You can then access the subscription ` ObservableQuery ` object with ` this.$apollo.queries.<name> ` .
87+
7288You can initialize the property in your vue component's ` data ` hook:
7389
7490``` javascript
@@ -627,8 +643,95 @@ apollo: {
627643 },
628644},
629645```
646+
647+ You can then access the subscription ` ObservableQuery ` object with ` this.$apollo.subscriptions.<name> ` .
648+
630649For the server implementation, you can take a look at [ this simple example] ( https://github.com/Akryum/apollo-server-example ) .
631650
651+ ### Pagination with ` fetchMore `
652+
653+ Use the ` fetchMore() ` method on the query:
654+
655+ ``` javascript
656+ < template>
657+ < div id= " app" >
658+ < h2> Pagination< / h2>
659+ < div class = " tag-list" v- if = " tagsPage" >
660+ < div class = " tag-list-item" v- for = " tag in tagsPage.tags" >
661+ {{ tag .id }} - {{ tag .label }} - {{ tag .type }}
662+ < / div>
663+ < div class = " actions" >
664+ < button v- if = " showMoreEnabled" @click= " showMore" > Show more< / button>
665+ < / div>
666+ < / div>
667+ < / div>
668+ < / template>
669+
670+ < script>
671+ import gql from ' graphql-tag' ;
672+
673+ const pageSize = 10 ;
674+
675+ export default {
676+ name: ' app' ,
677+ data : () => ({
678+ page: 0 ,
679+ showMoreEnabled: true ,
680+ }),
681+ apollo: {
682+ // Pages
683+ tagsPage: {
684+ // GraphQL Query
685+ query: gql ` query tagsPage ($page : Int ! , $pageSize : Int ! ) {
686+ tagsPage (page : $page , size : $pageSize ) {
687+ tags {
688+ id
689+ label
690+ type
691+ }
692+ hasMore
693+ }
694+ }` ,
695+ // Initial variables
696+ variables: {
697+ page: 0 ,
698+ pageSize,
699+ },
700+ },
701+ },
702+ methods: {
703+ showMore () {
704+ this .page ++ ;
705+ // Fetch more data and transform the original result
706+ this .$apollo .queries .tagsPage .fetchMore ({
707+ // New variables
708+ variables: {
709+ page: this .page ,
710+ pageSize,
711+ },
712+ // Transform the previous result with new data
713+ updateQuery : (previousResult , { fetchMoreResult }) => {
714+ const newTags = fetchMoreResult .data .tagsPage .tags ;
715+ const hasMore = fetchMoreResult .data .tagsPage .hasMore ;
716+
717+ this .showMoreEnabled = hasMore;
718+
719+ return {
720+ tagsPage: {
721+ // Merging the tag list
722+ tags: [... previousResult .tagsPage .tags , ... newTags],
723+ hasMore,
724+ },
725+ };
726+ },
727+ });
728+ },
729+ },
730+ };
731+ < / script>
732+ ```
733+
734+ [ Here] ( https://github.com/Akryum/apollo-server-example/blob/master/schema.js#L21 ) is a simple example for the server.
632735
633736---
634737
0 commit comments