Skip to content

Commit 563c932

Browse files
joe-reAkryum
authored andcommitted
fix: update typings (#447)
* add clients and defaultClient property to ApolloProvider * remove client property from DollerApollo * enable to specity client name to query
1 parent 3d6da43 commit 563c932

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

docs/api/dollar-apollo.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ This is the Apollo manager added to any component that uses Apollo. It can be ac
77
- `vm`: related component
88
- `queries`: array of the component's Smart Queries.
99
- `subscriptions`: array of the component's Smart Subscriptions.
10-
- `client`: current Apollo client for the component.
1110
- `provider`: injected [Apollo Provider](./apollo-provider.md).
1211
- `loading`: whether at least one query is loading.
1312
- `skipAllQueries`: (setter) boolean to pause or unpause all Smart Queries.

types/apollo-provider.d.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
/* eslint no-unused-vars: 0 */
22

3-
import { ApolloClient, ApolloQueryResult } from 'apollo-client'
4-
import Vue, { PluginFunction, AsyncComponent } from 'vue'
3+
import Vue, { AsyncComponent } from 'vue'
54
import { VueApolloComponentOption } from './options'
5+
import { ApolloClient } from 'apollo-client';
6+
import { WatchLoading, ErrorHandler, VueApolloOptions } from './options'
67

78
export type VueApolloComponent<V extends Vue = Vue> = VueApolloComponentOption<V> | typeof Vue | AsyncComponent;
89

9-
export class ApolloProvider {
10+
export class ApolloProvider<TCacheShape=any> {
1011
provide: (key?: string) => this
12+
constructor (options: {
13+
defaultClient: ApolloClient<TCacheShape>,
14+
defaultOptions?: VueApolloOptions<any>,
15+
clients?: { [key: string]: ApolloClient<TCacheShape> },
16+
watchLoading?: WatchLoading<any>,
17+
errorHandler?: ErrorHandler<any>
18+
})
19+
clients: { [key: string]: ApolloClient<TCacheShape> }
20+
defaultClient: ApolloClient<TCacheShape>
21+
prefetchQueries: any
1122
}

types/options.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface ExtendableVueApolloQueryOptions<V, R> extends _WatchQueryOptions {
4141
export interface VueApolloQueryOptions<V, R> extends ExtendableVueApolloQueryOptions<V, R> {
4242
query: ((this: ApolloVueThisType<V>) => DocumentNode) | DocumentNode;
4343
variables?: VariableFn<V>;
44+
client?: String
4445
}
4546

4647
export interface VueApolloMutationOptions<V, R> extends MutationOptions<R> {

types/test/App.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,8 @@ export default Vue.extend({
193193
console.log('this.$apollo.subscribe', data);
194194
},
195195
});
196+
197+
// enable to specify client when execute request
198+
this.$apollo.query({ query: gql`query mockQuery { id }`, client: 'test' })
196199
},
197200
});

types/test/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const apolloProvider = new VueApollo({
2525
})
2626

2727
Vue.use(VueApollo)
28-
2928
/* eslint no-new: 0 */
3029
new Vue({
3130
el: '#app',
@@ -34,3 +33,7 @@ new Vue({
3433
h(Decorator)
3534
])
3635
})
36+
37+
// test to able to call below methods
38+
console.log(apolloProvider.defaultClient.query)
39+
console.log(apolloProvider.clients['key'].query)

types/vue-apollo.d.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ import { GraphQLError } from 'graphql';
1515
export class VueApollo extends ApolloProvider implements PluginObject<{}>{
1616
[key: string]: any;
1717
install: PluginFunction<{}>;
18-
constructor (options: {
19-
defaultClient: ApolloClient<{}>,
20-
defaultOptions?: VueApolloOptions<{}>,
21-
clients?: { [key: string]: ApolloClient<{}> },
22-
watchLoading?: WatchLoading<{}>,
23-
errorHandler?: ErrorHandler<{}>
24-
});
18+
2519
static install(pVue: typeof Vue, options?:{} | undefined): void;
2620
}
2721

@@ -55,7 +49,6 @@ export interface DollarApollo<V> {
5549
vm: V;
5650
queries: Record<string, SmartQuery<V>>;
5751
subscriptions: Record<string, SmartSubscription<V>>;
58-
client: ApolloClient<{}>;
5952
readonly provider: ApolloProvider;
6053
readonly loading: boolean;
6154

0 commit comments

Comments
 (0)