Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 0540e54

Browse files
committed
Use getApolloState instead relying on reduxRootKey
1 parent 01425b3 commit 0540e54

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
"peerDependencies": {
5050
"react": "0.14.x || 15.* || ^15.0.0",
5151
"redux": "^2.0.0 || ^3.0.0",
52-
"apollo-client": "^0.4.12"
52+
"apollo-client": "^0.4.19"
5353
},
5454
"devDependencies": {
55-
"apollo-client": "0.4.13",
55+
"apollo-client": "0.4.19",
5656
"babel-jest": "^14.1.0",
5757
"babel-preset-react-native": "^1.9.0",
5858
"browserify": "^13.0.0",

src/graphql.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export default function graphql(
213213
// if this query is in the store, don't block execution
214214
try {
215215
readQueryFromStore({
216-
store: client.store.getState()[client.reduxRootKey].data,
216+
store: client.queryManager.getApolloState().data,
217217
query: opts.query,
218218
variables: opts.variables,
219219
fragmentMap: createFragmentMap(opts.fragments),
@@ -331,7 +331,6 @@ export default function graphql(
331331
return;
332332
}
333333

334-
const { reduxRootKey } = this.client;
335334
const queryOptions = this.calculateOptions(this.props);
336335
const fragments = calculateFragments(queryOptions.fragments);
337336
const { variables, forceFetch, skip } = queryOptions as QueryOptions;
@@ -363,7 +362,7 @@ export default function graphql(
363362
if (!forceFetch) {
364363
try {
365364
const result = readQueryFromStore({
366-
store: this.store.getState()[reduxRootKey].data,
365+
store: this.client.queryManager.getApolloState().data,
367366
query: document,
368367
variables,
369368
fragmentMap: createFragmentMap(fragments),
@@ -445,7 +444,6 @@ export default function graphql(
445444
}
446445

447446
handleQueryData(observableQuery: ObservableQuery, { variables }: WatchQueryOptions): void {
448-
const { reduxRootKey } = this.client;
449447
// bind each handle to updating and rerendering when data
450448
// has been recieved
451449
let refetch,
@@ -457,7 +455,8 @@ export default function graphql(
457455

458456
const next = ({ data = oldData, loading, error }: any) => {
459457
const { queryId } = observableQuery;
460-
let initialVariables = this.store.getState()[reduxRootKey].queries[queryId].variables;
458+
459+
let initialVariables = this.client.queryManager.getApolloState().queries[queryId].variables;
461460

462461
const resultKeyConflict: boolean = (
463462
'errors' in data ||

src/server.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ export function renderToStringWithData(component) {
106106
return getDataFromTree(component)
107107
.then(({ client }) => {
108108
let markup = ReactDOM.renderToString(component);
109-
let initialState = client.store.getState();
110-
const key = client.reduxRootKey;
111-
// XXX apollo client requires a lot in the store
112-
// can we make this samller?
113-
for (let queryId in initialState[key].queries) {
109+
let apolloState = client.queryManager.getApolloState();
110+
111+
for (let queryId in apolloState.queries) {
114112
let fieldsToNotShip = ['minimizedQuery', 'minimizedQueryString'];
115-
for (let field of fieldsToNotShip) delete initialState[key].queries[queryId][field];
113+
for (let field of fieldsToNotShip) delete apolloState.queries[queryId][field];
116114
}
117-
return { markup, initialState };
115+
116+
// it's OK, because apolloState is nested somewhere in globalState
117+
return { markup, initialState: client.store.getState() };
118118
});
119119
}

0 commit comments

Comments
 (0)