Skip to content

Commit 0b2e8df

Browse files
committed
Updated Apollo to version 2.0.0
1 parent f054285 commit 0b2e8df

30 files changed

+136
-128
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"graphql"
3131
],
3232
"dependencies": {
33+
"apollo-cache-inmemory": "^1.0.0",
34+
"apollo-client": "^2.0.1",
35+
"apollo-link-http": "^1.0.0",
3336
"apollo-server-express": "^1.1.2",
3437
"babel-runtime": "^6.26.0",
3538
"body-parser": "^1.17.2",
@@ -41,6 +44,7 @@
4144
"express-session": "^1.15.5",
4245
"firebase": "^4.3.1",
4346
"graphql": "^0.10.5",
47+
"graphql-tag": "^2.5.0",
4448
"graphql-tools": "^1.2.1",
4549
"isomorphic-fetch": "^2.2.1",
4650
"lru-cache": "^4.1.1",
@@ -49,7 +53,7 @@
4953
"passport-local": "^1.0.0",
5054
"prop-types": "^15.5.10",
5155
"react": "^16.0.0",
52-
"react-apollo": "^1.4.15",
56+
"react-apollo": "^2.0.0",
5357
"react-dom": "^16.0.0",
5458
"react-redux": "^5.0.6",
5559
"react-render-html": "^0.5.1",

src/components/container/NewsFeedWithApolloRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
import NewsFeed from '../presentational/NewsFeed';
55
import LoadingSpinner from '../presentational/LoadingSpinner';
66

7-
export default ({ data: { loading, error, feed }, options }) => {
7+
export default ({ data: { loading, error, feed }, data, options }) => {
88
if (error) return <tr><td>Error loading news items.</td></tr>;
99
if (feed && feed.length) return <NewsFeed newsItems={feed} {...options} />;
1010
return <LoadingSpinner />;

src/components/presentational/Comment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { gql } from 'react-apollo';
3+
import gql from 'graphql-tag';
44
import Link from 'next/link';
55
import renderHTML from 'react-render-html';
66

src/components/presentational/Comments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { gql } from 'react-apollo';
3+
import gql from 'graphql-tag';
44

55
import Comment from './Comment';
66

src/components/presentational/NewsDetail.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { gql, graphql } from 'react-apollo';
2+
import gql from 'graphql-tag';
33
import Link from 'next/link';
44
import PropTypes from 'prop-types';
55
import url from 'url';

src/components/presentational/NewsFeed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { gql } from 'react-apollo';
3+
import gql from 'graphql-tag';
44

55
import NewsTitle from '../container/NewsTitleWithData';
66
import NewsDetail from '../container/NewsDetailWithData';

src/components/presentational/NewsTitle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { gql } from 'react-apollo';
2+
import gql from 'graphql-tag';
33
import Link from 'next/link';
44
import PropTypes from 'prop-types';
55
import url from 'url';

src/data/mutations/hideNewsItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from 'react-apollo';
1+
import gql from 'graphql-tag';
22

33
export default gql`
44
mutation HideNewsItem($id: Int!) {

src/data/mutations/submitNewsItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from 'react-apollo';
1+
import gql from 'graphql-tag';
22
import NewsFeed from '../../components/presentational/NewsFeed';
33

44
export default gql`

src/data/mutations/upvoteNewsItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from 'react-apollo';
1+
import gql from 'graphql-tag';
22

33
export default gql`
44
mutation UpvoteNewsItem($id: Int!) {

src/data/queries/meQuery.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
gql,
3-
} from 'react-apollo';
1+
import gql from 'graphql-tag';
42

53
export default gql`
64
query User {

src/helpers/initApollo.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ApolloClient, createNetworkInterface } from 'react-apollo';
1+
import { ApolloClient } from 'apollo-client';
2+
import { createHttpLink } from 'apollo-link-http';
3+
import { InMemoryCache } from 'apollo-cache-inmemory';
4+
25
import fetch from 'isomorphic-fetch';
36
import debug from 'debug';
47

@@ -18,19 +21,17 @@ if (!process.browser) {
1821

1922
function create(initialState, { getToken }) {
2023
return new ApolloClient({
21-
initialState,
2224
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
23-
networkInterface: createNetworkInterface({
24-
uri: GRAPHQL_URL, // Server URL (must be absolute)
25-
opts: {
26-
// Additional fetch() options like `credentials` or `headers`
27-
credentials: 'same-origin',
28-
headers: {
29-
// HTTP Header: Cookie: <cookiename>=<cookievalue>
30-
Cookie: `${'connect.sid'}=${getToken()['connect.sid']}`,
31-
},
25+
link: createHttpLink({
26+
uri: GRAPHQL_URL,
27+
credentials: 'same-origin',
28+
headers: {
29+
// HTTP Header: Cookie: <cookiename>=<cookievalue>
30+
Cookie: `${'connect.sid'}=${getToken()['connect.sid']}`,
3231
},
3332
}),
33+
cache: new InMemoryCache().restore(initialState || {}),
34+
connectToDevTools: process.browser,
3435
});
3536
}
3637

src/helpers/withData.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2+
import { ApolloProvider, getDataFromTree } from 'react-apollo';
23
import cookie from 'cookie';
34
import PropTypes from 'prop-types';
4-
import { ApolloProvider, getDataFromTree } from 'react-apollo';
55
import debug from 'debug';
66

77
import initApollo from './initApollo';
@@ -28,7 +28,7 @@ export default (ComposedComponent) => {
2828
}
2929

3030
static async getInitialProps(context) {
31-
let serverState = {};
31+
let serverState = { apollo: {} };
3232

3333
// Setup a server-side one-time-use apollo client for initial props and
3434
// rendering (on server)
@@ -64,20 +64,17 @@ export default (ComposedComponent) => {
6464

6565
await getDataFromTree(app);
6666

67-
// Extract query data from the Apollo's store
68-
const state = apollo.getInitialState();
69-
7067
serverState = {
7168
apollo: { // Make sure to only include Apollo's data state
72-
data: state.data,
69+
data: apollo.cache.extract(), // Extract query data from the Apollo's store
7370
},
7471
};
7572
}
7673

7774
return {
7875
serverState,
7976
...composedInitialProps,
80-
}
77+
};
8178
}
8279

8380
constructor(props) {
@@ -86,7 +83,7 @@ export default (ComposedComponent) => {
8683
// render within `getInitialProps()` above (since the entire prop tree
8784
// will be initialized there), meaning the below will only ever be
8885
// executed on the client.
89-
this.apollo = initApollo(this.props.serverState, {
86+
this.apollo = initApollo(this.props.serverState.apollo.data, {
9087
getToken: () => parseCookies(), // ['connect.sid'],
9188
});
9289
}
@@ -96,7 +93,7 @@ export default (ComposedComponent) => {
9693
<ApolloProvider client={this.apollo}>
9794
<ComposedComponent {...this.props} />
9895
</ApolloProvider>
99-
)
96+
);
10097
}
101-
}
102-
}
98+
};
99+
};

src/layouts/Blank.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ const Blank = props => (
1414
</div>
1515
);
1616
Blank.propTypes = {
17-
children: PropTypes.oneOfType([
18-
PropTypes.element,
19-
PropTypes.arrayOf(PropTypes.element),
20-
PropTypes.string,
21-
]).isRequired,
17+
children: PropTypes.node.isRequired,
2218
};
2319

2420
export default Blank;

src/layouts/Main.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import Head from 'next/head';
4-
import {
5-
graphql,
6-
} from 'react-apollo';
4+
import { graphql } from 'react-apollo';
75

86
import Header from '../components/presentational/Header';
97
import Footer from '../components/presentational/Footer';
@@ -43,10 +41,7 @@ Main.defaultProps = {
4341
me: null,
4442
};
4543
Main.propTypes = {
46-
children: PropTypes.oneOfType([
47-
PropTypes.element,
48-
PropTypes.arrayOf(PropTypes.element),
49-
]).isRequired,
44+
children: PropTypes.node.isRequired,
5045
isNavVisible: PropTypes.bool,
5146
isUserVisible: PropTypes.bool,
5247
isFooterVisible: PropTypes.bool,

src/layouts/Notice.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ const Notice = props => (
3030
</center>
3131
);
3232
Notice.propTypes = {
33-
children: PropTypes.oneOfType([
34-
PropTypes.element,
35-
PropTypes.arrayOf(PropTypes.element),
36-
]).isRequired,
33+
children: PropTypes.node.isRequired,
3734
};
3835

3936
export default Notice;

src/pages/ask.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { graphql, gql } from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
34
import PropTypes from 'prop-types';
45

56
import Main from '../layouts/Main';

src/pages/best.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { graphql, gql } from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
34

45
import Main from '../layouts/Main';
56
import NewsFeed from '../components/presentational/NewsFeed';

src/pages/favorites.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
2-
import {
3-
graphql,
4-
gql,
5-
} from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
64

75
import Main from '../layouts/Main';
86
import NewsFeed from '../components/presentational/NewsFeed';

src/pages/forgot.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import Link from 'next/link';
33
import Router from 'next/router';
4-
import { gql, graphql } from 'react-apollo';
4+
import { graphql } from 'react-apollo';
5+
import gql from 'graphql-tag';
56
import PropTypes from 'prop-types';
67

78
import Blank from '../layouts/Blank';

src/pages/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { graphql, gql } from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
34
import PropTypes from 'prop-types';
45

56
import Main from '../layouts/Main';

src/pages/item.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { graphql, gql } from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
34

45
import Main from '../layouts/Main';
56
import NewsItem from '../components/container/NewsItemWithApolloRenderer';

src/pages/jobs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { graphql, gql } from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
34
import PropTypes from 'prop-types';
45

56
import Main from '../layouts/Main';

src/pages/newest.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
2-
import {
3-
graphql,
4-
gql,
5-
} from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
64

75
import Main from '../layouts/Main';
86
import NewsFeed from '../components/presentational/NewsFeed';

src/pages/reply.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
2-
import {
3-
graphql,
4-
gql,
5-
} from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
64

75
import Main from '../layouts/Main';
86
import Comment from '../components/presentational/Comment';

src/pages/show.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Link from 'next/link';
3-
import { graphql, gql } from 'react-apollo';
3+
import { graphql } from 'react-apollo';
4+
import gql from 'graphql-tag';
45
import PropTypes from 'prop-types';
56

67
import Main from '../layouts/Main';

src/pages/shownew.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import Link from 'next/link';
3-
import { graphql, gql } from 'react-apollo';
3+
import { graphql } from 'react-apollo';
4+
import gql from 'graphql-tag';
45
import PropTypes from 'prop-types';
56

67
import Main from '../layouts/Main';

src/pages/upvoted.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
2-
import {
3-
graphql,
4-
gql,
5-
} from 'react-apollo';
2+
import { graphql } from 'react-apollo';
3+
import gql from 'graphql-tag';
64

75
import Main from '../layouts/Main';
86
import NewsFeed from '../components/presentational/NewsFeed';

src/pages/user.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import Link from 'next/link';
3-
import {
4-
graphql,
5-
gql,
6-
} from 'react-apollo';
3+
import { graphql } from 'react-apollo';
4+
import gql from 'graphql-tag';
75
import PropTypes from 'prop-types';
86
import renderHTML from 'react-render-html';
97

0 commit comments

Comments
 (0)