yarn add mobx mobx-utils mobx-apollo
import { query } from 'mobx-apollo';
type options = {
client: apolloClientInstance, // new ApolloClient()
query: gqlInstance, // gql`..`
onError: Function,
onFetch: Function, // invoked every time new data is fetched
...watchQueryOptions // (see Apollo Client docs)
};
class Store {
@query allPosts = { ...options };
// or without decorators
constructor() {
query(this, 'allPosts', { ...options });
}
}
const store = new Store();
autorun(() => console.log(store.allPosts)); // [{ title: 'Hello World!' }]
See example.