How to correctly type an Apollo Client instance in Flow?

191 views Asked by At

I'm unsure what the correct type of a new ApolloClient is and I can't use any.

Would it be best to create an interface for the ApolloClient instance? If so, what would the interface look like since there are so many different options?

This is what my client looks like:

export const client = new ApolloClient({
  uri: 'http://localhost:4000/graphql',
  cache: new InMemoryCache()
});

I'm getting the following error if I try to export without a type definition:

Picture of Flow Error

1

There are 1 answers

0
Brianzchen On

I'm not familiar with Apollo but generally the type of a class you can write using typeof

export const client: typeof ApolloClient = new ApolloClient({
  uri: 'http://localhost:4000/graphql',
  cache: new InMemoryCache()
});

Assuming that ApolloClient is typed in the lib or flow-typed