Skip to content

Commit 1ca08f3

Browse files
committed
Type loadingKey query option as being a key of the component
1 parent 0d68177 commit 1ca08f3

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/decorator/SmartQuery.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ describe('@SmartQuery() decorator', () => {
7676
variables() {
7777
return this.vars;
7878
},
79+
loadingKey: 'loading',
7980
}),
8081
)
8182
todos!: Todo[];
8283

84+
loading: number = 0;
85+
8386
get vars(): QueryVariables {
8487
return {
8588
limit: 10,

src/query.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ type OverrideAllThis<O, T> = {
1010
[key in keyof O]: OverrideThis<O[key], T>;
1111
};
1212

13-
type VueApolloQueryDefinitionWithoutVariablesAndSubscribeToMore<TResult = any, TVariables = any> = Omit<
14-
VueApolloQueryDefinition<TResult, TVariables>,
15-
'subscribeToMore' | 'variables'
16-
>;
17-
1813
type SubscribeToMoreOptionsPatched<TComponent, TResult, TVariables> = OverrideAllThis<
1914
Omit<VueApolloSubscribeToMoreOptions<TResult, TVariables>, 'updateQuery' | 'variables'>,
2015
TComponent
@@ -34,12 +29,16 @@ type UpdateQueryFn<TComponent = any, TResult = any, TSubscriptionVariables = any
3429
},
3530
) => TResult;
3631

37-
export interface VueApolloQueryDefinitionPatched<TComponent = any, TResult = any, TVariables = any>
38-
extends OverrideAllThis<VueApolloQueryDefinitionWithoutVariablesAndSubscribeToMore<TResult, TVariables>, TComponent> {
32+
export interface VueApolloQueryDefinitionPatched<TComponent extends Vue = Vue, TResult = any, TVariables = any>
33+
extends OverrideAllThis<
34+
Omit<VueApolloQueryDefinition<TResult, TVariables>, 'subscribeToMore' | 'variables' | 'loadingKey'>,
35+
TComponent
36+
> {
3937
variables?: ((this: TComponent) => TVariables) | TVariables;
4038
subscribeToMore?:
4139
| SubscribeToMoreOptionsPatched<TComponent, TResult, TVariables>
4240
| Array<SubscribeToMoreOptionsPatched<TComponent, TResult, TVariables>>;
41+
loadingKey?: keyof TComponent;
4342
}
4443

4544
export type VueApolloSmartQueryErrorHandler<
@@ -68,12 +67,12 @@ export type VueApolloSmartQueryOptionsFunction<TResult, TVariables, TError = Apo
6867
TComponent extends Vue = TApp
6968
>(
7069
options?: Partial<Omit<VueApolloSmartQueryOptions<TResult, TVariables, TError, TComponent>, 'query'>>,
71-
) => VueApolloSmartQueryOptions<TResult, TVariables>;
70+
) => VueApolloSmartQueryOptions<TResult, TVariables, TError, TComponent>;
7271

7372
export function createSmartQueryOptionsFunction<TResult, TVariables, TError = ApolloError, TApp extends Vue = Vue>(
7473
query: DocumentNode,
7574
onError?: ApolloOperationErrorHandlerFunction<TError, TApp>,
76-
): VueApolloSmartQueryOptionsFunction<TResult, TVariables, TError, TApp> {
75+
): VueApolloSmartQueryOptionsFunction<TResult, TVariables> {
7776
return (options = {}) => {
7877
const defaultErrorHandlerFn: VueApolloSmartQueryErrorHandler<TResult, TVariables, TError, TApp> = (
7978
error: TError,

0 commit comments

Comments
 (0)