Skip to content

Catch up typings of dollar apollo #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/api/dollar-apollo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 14 additions & 3 deletions types/apollo-provider.d.ts
Original file line number Diff line number Diff line change
@@ -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<V extends Vue = Vue> = VueApolloComponentOption<V> | typeof Vue | AsyncComponent;

export class ApolloProvider {
export class ApolloProvider<TCacheShape=any> {
provide: (key?: string) => this
constructor (options: {
defaultClient: ApolloClient<TCacheShape>,
defaultOptions?: VueApolloOptions<any>,
clients?: { [key: string]: ApolloClient<TCacheShape> },
watchLoading?: WatchLoading<any>,
errorHandler?: ErrorHandler<any>
})
clients: { [key: string]: ApolloClient<TCacheShape> }
defaultClient: ApolloClient<TCacheShape>
prefetchQueries: any
}
1 change: 1 addition & 0 deletions types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface ExtendableVueApolloQueryOptions<V, R> extends _WatchQueryOptions {
export interface VueApolloQueryOptions<V, R> extends ExtendableVueApolloQueryOptions<V, R> {
query: ((this: ApolloVueThisType<V>) => DocumentNode) | DocumentNode;
variables?: VariableFn<V>;
client?: String
}

export interface VueApolloMutationOptions<V, R> extends MutationOptions<R> {
Expand Down
3 changes: 3 additions & 0 deletions types/test/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
},
});
5 changes: 4 additions & 1 deletion types/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const apolloProvider = new VueApollo({
})

Vue.use(VueApollo)

/* eslint no-new: 0 */
new Vue({
el: '#app',
Expand All @@ -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)
9 changes: 1 addition & 8 deletions types/vue-apollo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -55,7 +49,6 @@ export interface DollarApollo<V> {
vm: V;
queries: Record<string, SmartQuery<V>>;
subscriptions: Record<string, SmartSubscription<V>>;
client: ApolloClient<{}>;
readonly provider: ApolloProvider;
readonly loading: boolean;

Expand Down