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

Commit

Permalink
fix rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
machard committed Nov 27, 2016
1 parent affad61 commit 3b2e10e
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ export default function graphql(
this.subscribeToQuery(nextProps);

if (this.shouldSkip(this.props) && !this.shouldSkip(nextProps)) {
this.queryObservable.refetch();
this.queryObservable.refetch().then(
(r) => this.next(r),
(e) => this.handleError(e)
);
}
}

Expand Down Expand Up @@ -333,6 +336,29 @@ export default function graphql(
}
}

next(results: any) {
if (this.type === DocumentType.Subscription) {
// Subscriptions don't currently support `currentResult`, so we
// need to do this ourselves
this.lastSubscriptionData = results;

results = { data: results };
}
const clashingKeys = Object.keys(observableQueryFields(results.data));
invariant(clashingKeys.length === 0,
`the result of the '${graphQLDisplayName}' operation contains keys that ` +
`conflict with the return object.` +
clashingKeys.map(k => `'${k}'`).join(', ') + ` not allowed.`
);

this.forceRenderChildren();
};

handleError(error) {
if (error instanceof ApolloError) return next({ error });
throw error;
};

subscribeToQuery(props): boolean {
const opts = calculateOptions(props) as QueryOptions;

Expand All @@ -356,28 +382,6 @@ export default function graphql(
this.createQuery(opts);
}

const next = (results: any) => {
if (this.type === DocumentType.Subscription) {
// Subscriptions don't currently support `currentResult`, so we
// need to do this ourselves
this.lastSubscriptionData = results;

results = { data: results };
}
const clashingKeys = Object.keys(observableQueryFields(results.data));
invariant(clashingKeys.length === 0,
`the result of the '${graphQLDisplayName}' operation contains keys that ` +
`conflict with the return object.` +
clashingKeys.map(k => `'${k}'`).join(', ') + ` not allowed.`
);

this.forceRenderChildren();
};

const handleError = (error) => {
if (error instanceof ApolloError) return next({ error });
throw error;
};
/*
Since `setState()` can throw an error if the child had a render error,
Expand All @@ -386,7 +390,10 @@ export default function graphql(
Instead, we subscribe to the store for network errors and re-render that way
*/
this.querySubscription = this.queryObservable.subscribe({ next, error: handleError });
this.querySubscription = this.queryObservable.subscribe({
next: (r) => this.next(r),
error: (e) => this.handleError(e)
});
}

unsubscribeFromQuery() {
Expand Down

0 comments on commit 3b2e10e

Please sign in to comment.