/
options.d.ts
85 lines (69 loc) 路 2.9 KB
/
options.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {
WatchQueryOptions,
OperationVariables,
SubscriptionOptions,
SubscribeToMoreOptions,
ApolloQueryResult,
ApolloError
} from '@apollo/client/core'
import { DocumentNode } from 'graphql'
// import { DeepApplyThisType } from './utils'
/* Component options */
export interface AllVueApolloComponentSpecialOptions {
$skip: boolean
$skipAllQueries: boolean
$skipAllSubscriptions: boolean
$deep: boolean
$client: string
$loadingKey: string
$watchLoading: WatchLoading
$error: ErrorHandler
$query: Partial<VueApolloQueryDefinition>
$subscribe: VueApolloSubscriptionProperty
}
export type VueApolloComponentSpecialOptions =
Partial<AllVueApolloComponentSpecialOptions>
interface PrivateVueApolloComponentOptions extends VueApolloComponentSpecialOptions {
[key: string] : VueApolloQueryProperty |
VueApolloComponentSpecialOptions[keyof VueApolloComponentSpecialOptions]
}
// DeepApplyThisType is buggy: https://github.com/microsoft/TypeScript/issues/33392
// export type VueApolloComponentOptions<Instance> = DeepApplyThisType<PrivateVueApolloComponentOptions, Instance>
export type VueApolloComponentOptions<Instance> = PrivateVueApolloComponentOptions & ThisType<Instance>
/* Special component options */
export type WatchLoading = (isLoading: boolean, countModifier: number) => void
export type ErrorHandler = (error: ApolloError) => void
/* Query */
type QueryVariables<Variables = OperationVariables> = (() => Variables) | Variables
export type VueApolloQueryProperty =
DocumentNode |
VueApolloQueryDefinition |
(() => VueApolloQueryDefinition | null)
// exclude query prop because it causes type incorrectly error
type WatchQueryOptionsWithoutQuery = Omit<WatchQueryOptions, 'query'>
export interface VueApolloQueryDefinition<Result = any, Variables = OperationVariables> extends WatchQueryOptionsWithoutQuery {
query: DocumentNode | (() => DocumentNode | null)
variables?: QueryVariables<Variables>
update?: (data: Result) => any
result?: (result: ApolloQueryResult<Result>, key: string) => void
error?: ErrorHandler
manual?: boolean
loadingKey?: string
watchLoading?: WatchLoading
skip?: (() => boolean) | boolean
prefetch?: ((context: any) => any) | boolean
client?: string
deep?: boolean
subscribeToMore?: VueApolloSubscribeToMoreOptions<Result, Variables> | VueApolloSubscribeToMoreOptions<Result, Variables>[]
}
/* Subscriptions */
export interface VueApolloSubscribeToMoreOptions<Result = any, Variables = OperationVariables> extends Omit<SubscribeToMoreOptions<Result, Variables>, 'variables'> {
variables?: QueryVariables<Variables>
}
export interface VueApolloSubscriptionDefinition<Variables = OperationVariables> extends Omit<SubscriptionOptions<Variables>, 'variables'> {
variables?: QueryVariables<Variables>
client?: string
}
export type VueApolloSubscriptionProperty =
VueApolloSubscriptionDefinition |
{ [key: string]: VueApolloSubscriptionDefinition }