Skip to content

Commit 0373c41

Browse files
committed
fix: check client type at runtime instead of in flow
1 parent 9aa112a commit 0373c41

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

flow-typed/npm/apollo-client_v2.x.x.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
// flow-typed signature: ae6dd2fff7718a6434052f6830bf129b
22
// flow-typed version: 2cbae06e0e/apollo-client_v2.x.x/flow_>=v0.57.x
33

4-
import type {DocumentNode, ExecutionResult, GraphQLError} from 'graphql';
5-
64
declare module "apollo-client" {
5+
/**
6+
* Types From graphql
7+
* graphql types are maintained in the graphql-js repo
8+
*/
9+
declare type DocumentNode = any;
10+
declare type ExecutionResult<T> = {
11+
data?: T,
12+
extensions?: { [string]: any },
13+
errors?: any[]
14+
};
15+
declare type GraphQLError = any;
16+
/** End From graphql */
17+
718
declare type OperationVariables = { [key: string]: any };
819

920
declare export function print(ast: any): string;
@@ -62,7 +73,6 @@ declare module "apollo-client" {
6273
mutationStore: MutationStore;
6374
queryStore: QueryStore;
6475
dataStore: DataStore<TStore>;
65-
queries: Map<string, {document: DocumentNode, observableQuery: ObservableQuery<any>}>;
6676

6777
constructor({
6878
link: ApolloLink,

src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import type {ApolloClient} from 'apollo-client'
3+
import {ApolloClient} from 'apollo-client'
44
import getSchemaTypes from './getSchemaTypes'
55
import type {Types} from './getSchemaTypes'
66
import doesQueryContain from './doesQueryContain'
@@ -21,11 +21,15 @@ function every<T>(array: $ReadOnlyArray<T>, predicate: (elem: T) => boolean): bo
2121
}
2222

2323
export default async function refetch(
24-
client: ApolloClient<any>,
24+
client: mixed,
2525
typenameOrTerms: string | $ReadOnlyArray<Term>,
2626
ids?: ?any,
2727
idField?: string
2828
): Promise<any> {
29+
if (!(client instanceof ApolloClient)) throw new Error(
30+
`client must be an ApolloClient, instead got: ${String(client)}`
31+
)
32+
2933
const types: Types = await getSchemaTypes(client)
3034

3135
let terms

0 commit comments

Comments
 (0)