11// this example src is https://github.com/Akryum/vue-apollo-example
22import gql from 'graphql-tag'
33import Vue from 'vue'
4- import { OperationVariables } from 'apollo-client'
5- import { VueApolloQueryDefinition } from '../options'
4+ import { OperationVariables , ApolloQueryResult , ApolloError } from 'apollo-client'
5+ import { VueApolloQueryDefinition , VueApolloSubscribeToMoreOptions } from '../options'
66import { DocumentNode } from 'graphql'
77
88const pageSize = 10
@@ -23,6 +23,12 @@ interface HelloVars {
2323 hello : string
2424}
2525
26+ interface FooResult {
27+ foo : {
28+ bar : string
29+ }
30+ }
31+
2632export const hey = Vue . extend ( {
2733 props : {
2834 meow : String ,
@@ -44,17 +50,19 @@ export const hey = Vue.extend({
4450 message : {
4551 query : gql `query` ,
4652 // https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types
47- variables ( ) : OperationVariables {
53+ variables ( ) : HelloVars {
4854 this . hello . toUpperCase ( )
4955 this . meow
5056 return {
5157 hello : this . hello . toUpperCase ( )
5258 }
5359 } ,
54- update : data => data . foo . bar ,
55- result ( result , key ) {
60+ update : ( data : FooResult ) => data . foo . bar ,
61+ result ( result : ApolloQueryResult < FooResult > , key ) {
5662 this . meow
63+ console . log ( result . data . foo . bar . toUpperCase ( ) )
5764 console . log ( this . hello . toUpperCase ( ) )
65+ console . log ( key )
5866 } ,
5967 error ( error ) {
6068 console . error ( error . graphQLErrors , error . networkError )
@@ -98,6 +106,11 @@ export const hey = Vue.extend({
98106
99107 testMultiSubs : {
100108 query : gql `query` ,
109+ variables ( ) : HelloVars {
110+ return {
111+ hello : this . hello ,
112+ }
113+ } ,
101114 subscribeToMore : [
102115 {
103116 document : gql `subscription` ,
@@ -114,9 +127,11 @@ export const hey = Vue.extend({
114127 {
115128 document : gql `subscription` ,
116129 // https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types
117- variables ( ) : OperationVariables {
130+ variables ( ) : HelloVars {
118131 return {
119- foo : this . hello ,
132+ // Typescript Bug: https://github.com/microsoft/TypeScript/issues/33392
133+ // @ts -ignore
134+ hello : this . hello ,
120135 }
121136 } ,
122137 updateQuery ( previousResult , options ) {
@@ -129,23 +144,31 @@ export const hey = Vue.extend({
129144 ] ,
130145 } ,
131146
132- // https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types
133- tags ( ) : VueApolloQueryDefinition {
147+ tags ( ) : VueApolloQueryDefinition < FooResult , HelloVars > {
134148 this . hello . toUpperCase ( )
135149 this . meow
136150 return {
137151 query : gql `query` ,
138152 // https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types
139- variables : ( ) : OperationVariables => {
153+ variables : ( ) => {
140154 this . hello . toUpperCase ( )
141155 this . meow
142156 return {
143157 hello : this . hello . toUpperCase ( )
144158 }
145159 } ,
146- result : ( ) => {
160+ result : ( result ) => {
147161 console . log ( this . hello . toUpperCase ( ) )
148- }
162+ console . log ( result . data . foo . bar . toUpperCase ( ) )
163+ } ,
164+ subscribeToMore : [
165+ {
166+ document : gql `` ,
167+ variables : ( ) => ( {
168+ hello : this . hello . toUpperCase ( )
169+ } ) ,
170+ } ,
171+ ] ,
149172 }
150173 } ,
151174
@@ -204,7 +227,7 @@ export default Vue.extend({
204227 $client : 'a' ,
205228 $query : {
206229 loadingKey : 'loading' ,
207- fetchPolicy : 'cache-first'
230+ fetchPolicy : 'cache-first' ,
208231 } ,
209232 tags ( ) : VueApolloQueryDefinition {
210233 return {
@@ -289,6 +312,10 @@ export default Vue.extend({
289312 page : 0 ,
290313 pageSize,
291314 } ,
315+ result ( result ) {
316+ console . log ( result )
317+ console . log ( this . loading )
318+ } ,
292319 } ,
293320 } ,
294321 methods : {
0 commit comments