diff --git a/docs/api/dollar-apollo.md b/docs/api/dollar-apollo.md index 63ebc932..e7665e21 100644 --- a/docs/api/dollar-apollo.md +++ b/docs/api/dollar-apollo.md @@ -7,7 +7,6 @@ This is the Apollo manager added to any component that uses Apollo. It can be ac - `vm`: related component - `queries`: array of the component's Smart Queries. - `subscriptions`: array of the component's Smart Subscriptions. -- `client`: current Apollo client for the component. - `provider`: injected [Apollo Provider](./apollo-provider.md). - `loading`: whether at least one query is loading. - `skipAllQueries`: (setter) boolean to pause or unpause all Smart Queries. diff --git a/types/apollo-provider.d.ts b/types/apollo-provider.d.ts index 95319ba7..aded8932 100644 --- a/types/apollo-provider.d.ts +++ b/types/apollo-provider.d.ts @@ -1,11 +1,22 @@ /* eslint no-unused-vars: 0 */ -import { ApolloClient, ApolloQueryResult } from 'apollo-client' -import Vue, { PluginFunction, AsyncComponent } from 'vue' +import Vue, { AsyncComponent } from 'vue' import { VueApolloComponentOption } from './options' +import { ApolloClient } from 'apollo-client'; +import { WatchLoading, ErrorHandler, VueApolloOptions } from './options' export type VueApolloComponent = VueApolloComponentOption | typeof Vue | AsyncComponent; -export class ApolloProvider { +export class ApolloProvider { provide: (key?: string) => this + constructor (options: { + defaultClient: ApolloClient, + defaultOptions?: VueApolloOptions, + clients?: { [key: string]: ApolloClient }, + watchLoading?: WatchLoading, + errorHandler?: ErrorHandler + }) + clients: { [key: string]: ApolloClient } + defaultClient: ApolloClient + prefetchQueries: any } diff --git a/types/options.d.ts b/types/options.d.ts index 67ffc7cf..a59553c7 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -41,6 +41,7 @@ interface ExtendableVueApolloQueryOptions extends _WatchQueryOptions { export interface VueApolloQueryOptions extends ExtendableVueApolloQueryOptions { query: ((this: ApolloVueThisType) => DocumentNode) | DocumentNode; variables?: VariableFn; + client?: String } export interface VueApolloMutationOptions extends MutationOptions { diff --git a/types/test/App.ts b/types/test/App.ts index 20370d3f..b6a9bf3a 100644 --- a/types/test/App.ts +++ b/types/test/App.ts @@ -193,5 +193,8 @@ export default Vue.extend({ console.log('this.$apollo.subscribe', data); }, }); + + // enable to specify client when execute request + this.$apollo.query({ query: gql`query mockQuery { id }`, client: 'test' }) }, }); \ No newline at end of file diff --git a/types/test/index.ts b/types/test/index.ts index 1861ac1f..390dbfa4 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -25,7 +25,6 @@ const apolloProvider = new VueApollo({ }) Vue.use(VueApollo) - /* eslint no-new: 0 */ new Vue({ el: '#app', @@ -34,3 +33,7 @@ new Vue({ h(Decorator) ]) }) + +// test to able to call below methods +console.log(apolloProvider.defaultClient.query) +console.log(apolloProvider.clients['key'].query) diff --git a/types/vue-apollo.d.ts b/types/vue-apollo.d.ts index 6495ba33..701bec23 100644 --- a/types/vue-apollo.d.ts +++ b/types/vue-apollo.d.ts @@ -15,13 +15,7 @@ import { GraphQLError } from 'graphql'; export class VueApollo extends ApolloProvider implements PluginObject<{}>{ [key: string]: any; install: PluginFunction<{}>; - constructor (options: { - defaultClient: ApolloClient<{}>, - defaultOptions?: VueApolloOptions<{}>, - clients?: { [key: string]: ApolloClient<{}> }, - watchLoading?: WatchLoading<{}>, - errorHandler?: ErrorHandler<{}> - }); + static install(pVue: typeof Vue, options?:{} | undefined): void; } @@ -55,7 +49,6 @@ export interface DollarApollo { vm: V; queries: Record>; subscriptions: Record>; - client: ApolloClient<{}>; readonly provider: ApolloProvider; readonly loading: boolean;