feat(ts): improve types
This commit is contained in:
+1
-1
@@ -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"
|
||||
}
|
||||
|
||||
Vendored
+18
-9
@@ -21,20 +21,26 @@ interface ApolloVueSubscribeToMoreOptions<V> {
|
||||
onError?: (error: Error) => void;
|
||||
}
|
||||
|
||||
export type WatchLoading<V> = (isLoading: boolean, countModifier: number) => void
|
||||
export type ErrorHandler<V> = (this: ApolloVueThisType<V>, error: any) => void
|
||||
|
||||
type _WatchQueryOptions = Omit<WatchQueryOptions, 'query'>; // exclude query prop because it causes type incorrectly error
|
||||
export interface VueApolloQueryOptions<V, R> extends _WatchQueryOptions {
|
||||
query: ((this: ApolloVueThisType<V>) => DocumentNode) | DocumentNode;
|
||||
variables?: VariableFn<V>;
|
||||
|
||||
interface ExtendableVueApolloQueryOptions<V, R> extends _WatchQueryOptions {
|
||||
update?: (this: ApolloVueThisType<V>, data: R) => any;
|
||||
result?: (this: ApolloVueThisType<V>, data: R, loader: any, netWorkStatus: NetworkStatus) => void;
|
||||
error?: (this: ApolloVueThisType<V>, error: any) => void;
|
||||
error?: ErrorHandler<V>;
|
||||
loadingKey?: string;
|
||||
watchLoading?: (isLoading: boolean, countModifier: number) => void;
|
||||
watchLoading?: WatchLoading<V>;
|
||||
skip?: (this: ApolloVueThisType<V>) => boolean | boolean;
|
||||
manual?: boolean;
|
||||
subscribeToMore?: ApolloVueSubscribeToMoreOptions<V> | ApolloVueSubscribeToMoreOptions<V>[];
|
||||
prefetch?: (context: any) => boolean | boolean;
|
||||
}
|
||||
export interface VueApolloQueryOptions<V, R> extends ExtendableVueApolloQueryOptions<V, R> {
|
||||
query: ((this: ApolloVueThisType<V>) => DocumentNode) | DocumentNode;
|
||||
variables?: VariableFn<V>;
|
||||
}
|
||||
|
||||
export interface VueApolloMutationOptions<V, R> extends MutationOptions<R> {
|
||||
mutation: DocumentNode;
|
||||
@@ -51,16 +57,19 @@ export interface VueApolloSubscriptionOptions<V, R> extends SubscriptionOptions
|
||||
type QueryComponentProperty<V> = ((this: ApolloVueThisType<V>) => VueApolloQueryOptions<V, any>) | VueApolloQueryOptions<V, any>
|
||||
type SubscribeComponentProperty<V> = VueApolloSubscriptionOptions<V, any> | { [key: string]: VueApolloSubscriptionOptions<V, any> }
|
||||
|
||||
export type VueApolloOptions = {
|
||||
export type VueApolloOptions<V> = {
|
||||
$skip?: boolean,
|
||||
$skipAllQueries?: boolean,
|
||||
$skipAllSubscriptions?: boolean,
|
||||
$deep?: boolean,
|
||||
$client?: string,
|
||||
$loadingKey?: string,
|
||||
$error?: Function
|
||||
$watchLoading?: WatchLoading<V>,
|
||||
$error?: ErrorHandler<V>,
|
||||
$query?: ExtendableVueApolloQueryOptions<V, any>
|
||||
}
|
||||
|
||||
export interface VueApolloComponentOption<V> extends VueApolloOptions {
|
||||
[key: string]: QueryComponentProperty<V> | SubscribeComponentProperty<V> | string | boolean | Function | undefined;
|
||||
export interface VueApolloComponentOption<V> extends VueApolloOptions<V> {
|
||||
[key: string]: QueryComponentProperty<V> | SubscribeComponentProperty<V> | ExtendableVueApolloQueryOptions<V, any> | string | boolean | Function | undefined;
|
||||
$subscribe?: SubscribeComponentProperty<V>;
|
||||
}
|
||||
|
||||
+4
-1
@@ -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!) {
|
||||
|
||||
+13
-2
@@ -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)
|
||||
|
||||
|
||||
Vendored
+16
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user