Skip to content

Commit f22c3f8

Browse files
author
Guillaume Chau
committed
fix(types): apollo methods generics, fixes #773
1 parent 21a4de0 commit f22c3f8

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

types/test/App.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const SUB_QUERY = gql`subscription tags($type: String!) {
1515
}
1616
}`
1717

18+
interface Foo {
19+
foo: string
20+
}
21+
22+
interface HelloVars {
23+
hello: string
24+
}
25+
1826
export const hey = Vue.extend({
1927
props: {
2028
meow: String,
@@ -161,13 +169,16 @@ export const hey = Vue.extend({
161169
}
162170
},
163171

164-
created () {
165-
this.$apollo.mutate({
172+
async created () {
173+
const { data } = await this.$apollo.mutate<Foo, HelloVars>({
166174
mutation: gql`mutation {}`,
167175
variables: {
168176
hello: this.hello
169177
},
170178
})
179+
if (data) {
180+
console.log(data.foo)
181+
}
171182
this.hello.toUpperCase()
172183
this.$apollo.vm.hello.toUpperCase()
173184
}

types/vue-apollo.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
WatchQueryOptions,
88
MutationOptions,
99
SubscriptionOptions,
10+
OperationVariables,
1011
} from 'apollo-client'
1112
import { FetchResult } from 'apollo-link'
1213
import { Observable } from 'apollo-client/util/Observable'
@@ -54,14 +55,14 @@ interface ClientOptions {
5455
client?: string
5556
}
5657

57-
interface ApolloClientMethods<R> {
58-
query: (options: QueryOptions & ClientOptions) => ReturnType<ApolloClient<R>['query']>
59-
watchQuery: (options: WatchQueryOptions & ClientOptions) => ReturnType<ApolloClient<R>['watchQuery']>
60-
mutate: (options: MutationOptions & ClientOptions) => ReturnType<ApolloClient<R>['mutate']>
61-
subscribe: (options: SubscriptionOptions & ClientOptions) => ReturnType<ApolloClient<R>['subscribe']>
58+
interface ApolloClientMethods {
59+
query<R = any, TVariables = OperationVariables>(options: QueryOptions<TVariables> & ClientOptions): Promise<ApolloQueryResult<R>>
60+
watchQuery<R = any, TVariables = OperationVariables>(options: WatchQueryOptions<TVariables> & ClientOptions): ObservableQuery<R, TVariables>
61+
mutate<R = any, TVariables = OperationVariables>(options: MutationOptions<R, TVariables> & ClientOptions): Promise<FetchResult<R>>
62+
subscribe<R = any, TVariables = OperationVariables>(options: SubscriptionOptions<TVariables> & ClientOptions): Observable<FetchResult<R>>
6263
}
6364

64-
export interface DollarApollo<V, R = any> extends ApolloClientMethods<R> {
65+
export interface DollarApollo<V> extends ApolloClientMethods {
6566
vm: V
6667
queries: Record<string, SmartQuery<V>>
6768
subscriptions: Record<string, SmartSubscription<V>>

0 commit comments

Comments
 (0)