Skip to content

Instantly share code, notes, and snippets.

@hwillson
hwillson / apollo-client-250-code-split-stats.js
Last active February 16, 2019 21:48
Apollo Client - 2.5.0 Announcement Post - Code Splitting - Stats
import React from 'react';
import { ApolloConsumer, Query } from 'react-apollo';
import gql from 'graphql-tag';
const GET_MESSAGE_COUNT = gql`
{
messageCount @client {
total
}
}
@hwillson
hwillson / apollo-client-250-code-split-4.js
Created February 16, 2019 21:36
Apollo Client - 2.5.0 Announcement Post - Code Splitting 4
import Loadable from 'react-loadable';
import Loading from './components/Loading';
export const Stats = Loadable({
loader: () => import('./components/stats/Stats'),
loading: Loading,
});
@hwillson
hwillson / apollo-client-250-code-split-3.js
Created February 16, 2019 21:27
Apollo Client - 2.5.0 Announcement Post - Code Splitting 3
import React from 'react';
import { ApolloConsumer, Query } from 'react-apollo';
import gql from 'graphql-tag';
const GET_MESSAGE_COUNT = gql`
{
messageCount @client {
total
}
}
@hwillson
hwillson / apollo-client-250-code-split-2.js
Created February 16, 2019 21:18
Apollo Client - 2.5.0 Announcement Post - Code Splitting 2
import React from 'react';
import { Route } from 'react-router-dom';
import Header from '../components/Header';
import { Home, Messages, Stats } from '../lazy'
const App = () => (
<div className="app">
<Header />
<Route exact path="/" component={Home} />
@hwillson
hwillson / apollo-client-250-code-split-1.js
Created February 16, 2019 21:17
Apollo Client - 2.5.0 Announcement Post - Code Splitting 1
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import { ApolloProvider } from 'react-apollo';
import App from './components/App';
@hwillson
hwillson / apollo-client-250-client-always.js
Last active February 19, 2019 21:10
Apollo Client - 2.5.0 Announcement Post - @client(always: true)
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import gql from 'graphql-tag';
const client = new ApolloClient({
cache: new InMemoryCache(),
resolvers: {
User: {
isLoggedIn() {
return !!localStorage.getItem('token');
@hwillson
hwillson / apollo-client-250-client-export.js
Last active February 16, 2019 21:17
Apollo Client - 2.5.0 Announcement Post - @client @export
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import gql from 'graphql-tag';
const query = gql`
query currentAuthorPosts($authorId: Int!) {
currentAuthorId @client @export(as: "authorId")
posts(authorId: $authorId) {
title
@hwillson
hwillson / apollo-client-250-1.js
Created February 15, 2019 20:08
Apollo Client - 2.5.0 Announcement Post - 1
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import gql from 'graphql-tag';
const GET_CART_ITEMS = gql`
query GetCartItems {
cartItems @client
}
`;
@hwillson
hwillson / README.md
Created February 21, 2018 19:29
MT home icon changes