diff --git a/package.json b/package.json index 983a5ab..e66c6af 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-replace": "^2.0.0", "rollup-plugin-uglify": "^3.0.0", - "typescript": "^2.6.2", + "typescript": "^2.9.2", "uglify-es": "^3.1.6", "vue": "^2.5.9" } diff --git a/types/options.d.ts b/types/options.d.ts index 26cd004..1e6fac1 100644 --- a/types/options.d.ts +++ b/types/options.d.ts @@ -21,20 +21,26 @@ interface ApolloVueSubscribeToMoreOptions { onError?: (error: Error) => void; } +export type WatchLoading = (isLoading: boolean, countModifier: number) => void +export type ErrorHandler = (this: ApolloVueThisType, error: any) => void + type _WatchQueryOptions = Omit; // exclude query prop because it causes type incorrectly error -export interface VueApolloQueryOptions extends _WatchQueryOptions { - query: ((this: ApolloVueThisType) => DocumentNode) | DocumentNode; - variables?: VariableFn; + +interface ExtendableVueApolloQueryOptions extends _WatchQueryOptions { update?: (this: ApolloVueThisType, data: R) => any; result?: (this: ApolloVueThisType, data: R, loader: any, netWorkStatus: NetworkStatus) => void; - error?: (this: ApolloVueThisType, error: any) => void; + error?: ErrorHandler; loadingKey?: string; - watchLoading?: (isLoading: boolean, countModifier: number) => void; + watchLoading?: WatchLoading; skip?: (this: ApolloVueThisType) => boolean | boolean; manual?: boolean; subscribeToMore?: ApolloVueSubscribeToMoreOptions | ApolloVueSubscribeToMoreOptions[]; prefetch?: (context: any) => boolean | boolean; } +export interface VueApolloQueryOptions extends ExtendableVueApolloQueryOptions { + query: ((this: ApolloVueThisType) => DocumentNode) | DocumentNode; + variables?: VariableFn; +} export interface VueApolloMutationOptions extends MutationOptions { mutation: DocumentNode; @@ -51,16 +57,19 @@ export interface VueApolloSubscriptionOptions extends SubscriptionOptions type QueryComponentProperty = ((this: ApolloVueThisType) => VueApolloQueryOptions) | VueApolloQueryOptions type SubscribeComponentProperty = VueApolloSubscriptionOptions | { [key: string]: VueApolloSubscriptionOptions } -export type VueApolloOptions = { +export type VueApolloOptions = { $skip?: boolean, $skipAllQueries?: boolean, $skipAllSubscriptions?: boolean, + $deep?: boolean, $client?: string, $loadingKey?: string, - $error?: Function + $watchLoading?: WatchLoading, + $error?: ErrorHandler, + $query?: ExtendableVueApolloQueryOptions } -export interface VueApolloComponentOption extends VueApolloOptions { - [key: string]: QueryComponentProperty | SubscribeComponentProperty | string | boolean | Function | undefined; +export interface VueApolloComponentOption extends VueApolloOptions { + [key: string]: QueryComponentProperty | SubscribeComponentProperty | ExtendableVueApolloQueryOptions | string | boolean | Function | undefined; $subscribe?: SubscribeComponentProperty; } diff --git a/types/test/App.ts b/types/test/App.ts index 6cee410..de2fc08 100644 --- a/types/test/App.ts +++ b/types/test/App.ts @@ -27,7 +27,10 @@ export default Vue.extend({ }, apollo: { $client: 'a', - $loadingKey: 'loading', + $query: { + loadingKey: 'loading', + fetchPolicy: 'cache-first' + }, tags() { return { query: gql`query tagList ($type: String!) { diff --git a/types/test/index.ts b/types/test/index.ts index 9a597ba..3559712 100644 --- a/types/test/index.ts +++ b/types/test/index.ts @@ -9,8 +9,19 @@ import App from './App' const httpLink = new HttpLink({ uri: 'https://dummy.test.com' }) const cache: any = 'dummy cache'; -const apolloClient = new ApolloClient({ link: httpLink, cache, connectToDevTools: true }) -const apolloProvider = new VueApollo({ defaultClient: apolloClient }) +const apolloClient = new ApolloClient({ + link: httpLink, + cache, + connectToDevTools: true +}) +const apolloProvider = new VueApollo({ + defaultClient: apolloClient, + defaultOptions: { + $query: { + fetchPolicy: 'cache-and-network' + } + } +}) Vue.use(VueApollo) diff --git a/types/vue-apollo.d.ts b/types/vue-apollo.d.ts index f21f8fb..07519c6 100644 --- a/types/vue-apollo.d.ts +++ b/types/vue-apollo.d.ts @@ -5,12 +5,26 @@ import { SubscriptionOptions, ObservableQuery } from 'apollo-client' import { DataProxy } from 'apollo-cache'; import { subscribe } from 'graphql/subscription/subscribe'; import { ApolloProvider, VueApolloComponent } from './apollo-provider' -import { VueApolloQueryOptions, VueApolloMutationOptions, VueApolloSubscriptionOptions, ApolloVueThisType, VueApolloOptions } from './options' +import { + VueApolloQueryOptions, + VueApolloMutationOptions, + VueApolloSubscriptionOptions, + ApolloVueThisType, + VueApolloOptions, + WatchLoading, + ErrorHandler +} from './options' export class VueApollo extends ApolloProvider implements PluginObject<{}>{ [key: string]: any; install: PluginFunction<{}>; - constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions, clients?: { [key: string]: ApolloClient<{}> } }); + constructor (options: { + defaultClient: ApolloClient<{}>, + defaultOptions?: VueApolloOptions<{}>, + clients?: { [key: string]: ApolloClient<{}> }, + watchLoading?: WatchLoading<{}>, + errorHandler?: ErrorHandler<{}> + }); static install(pVue: typeof Vue, options?:{} | undefined): void; } diff --git a/yarn.lock b/yarn.lock index dcb98b7..91da09e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3478,9 +3478,9 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@^2.6.2: - version "2.7.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359" +typescript@^2.9.2: + version "2.9.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c" uglify-es@^3.1.6, uglify-es@^3.3.7: version "3.3.10"