mobx-apollo
Installation
yarn add mobx mobx-apollo
Usage
; type config = client: apolloClientInstance // new ApolloClient() query: gqlInstance // gql`..` onError?: Function onFetch?: Function // invoked every time new data is fetched ...ApolloWatchQueryOptions // (see Apollo Client docs); const store = { thisallPosts = ; // or lazy load it ; }; ; // [{ title: 'Hello World!' }] type response = error: ApolloError // (see Apollo Client docs) loading: boolean data: queryAlias: Array<Object> ref: ApolloObservableQuery // (see Apollo Client docs);
Example
; // create-react-app example// yarn add apollo-client-preset graphql graphql-tag isomorphic-fetch mobx mobx-apollo mobx-react ;;;;;; globalfetch = fetch; // schema built with Graphcool// type Post implements Node {// createdAt: DateTime!// id: ID! @isUnique// updatedAt: DateTime!// title: String!// } // queries and mutationsconst allPostsQuery = gql` { allPosts(orderBy: createdAt_DESC) { id title } }`; const createPostMutation = gql` mutation createPost($title: String!) { createPost(title: $title) { id title } }`; const uri = 'https://api.graph.cool/simple/v1/<project>'; const client = link: uri cache: ; // building a mobx storeconst postsStore = { ; } client ;; // our main componentconst Example = ; // typically you would have multiple mobx stores hereconst stores = postsStore ; const ExampleWithState = <Provider ...stores> <Example /> </Provider>; ;