Skip to content

Commit 16d4f43

Browse files
author
Guillaume Chau
committed
chore(types): update type tests/examples
1 parent c5ac6d9 commit 16d4f43

File tree

4 files changed

+87
-16
lines changed

4 files changed

+87
-16
lines changed

types/test/App.ts

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// this example src is https://github.com/Akryum/vue-apollo-example
22
import gql from 'graphql-tag'
33
import 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'
66
import { DocumentNode } from 'graphql'
77

88
const pageSize = 10
@@ -23,6 +23,12 @@ interface HelloVars {
2323
hello: string
2424
}
2525

26+
interface FooResult {
27+
foo: {
28+
bar: string
29+
}
30+
}
31+
2632
export 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: {

types/test/App.vue

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script>
2+
import gql from 'graphql-tag'
3+
4+
export default {
5+
data () {
6+
return {
7+
hey: 'hey'
8+
}
9+
},
10+
11+
apollo: {
12+
foobar: {
13+
query: gql``,
14+
variables () {
15+
return {
16+
var1: this.hey,
17+
}
18+
},
19+
subscribeToMore: [
20+
{
21+
document: gql``,
22+
variables () {
23+
return {
24+
var1: this.hey
25+
}
26+
}
27+
}
28+
],
29+
},
30+
},
31+
}
32+
</script>

types/test/Decorator.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import { Component, Vue } from 'vue-property-decorator'
2+
import gql from 'graphql-tag'
3+
import { OperationVariables } from 'apollo-client'
4+
import { VueApolloComponentOptions } from '../options'
25

36
@Component({
47
apollo: {
5-
allFilms: '',
6-
},
8+
allFilms: {
9+
query: gql``,
10+
variables (): OperationVariables {
11+
return {
12+
foo: this.foo
13+
}
14+
}
15+
},
16+
} as VueApolloComponentOptions<Decorator>,
717
})
818
export default class Decorator extends Vue {
919
allFilms = []
20+
foo = 'bar'
1021
}

types/test/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"moduleResolution": "node",
2121
"experimentalDecorators": true,
2222
"strict": true,
23-
"noImplicitAny": true
23+
"noImplicitAny": true,
24+
"allowJs": true
2425
},
2526
"include": [
2627
"*.ts",

0 commit comments

Comments
 (0)