Skip to content

Commit

Permalink
Fix type issues due to exposed SSR type
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jul 6, 2021
1 parent 1bfd974 commit 88638de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/exchanges/ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ it('caches complex GraphQLErrors in query results correctly', () => {
publish(exchange);
next(queryOperation);

const error = ssr.extractData()[queryOperation.key].error;
const error = ssr.extractData()[queryOperation.key]!.error;

expect(error).toHaveProperty('graphQLErrors.0.message', 'Oh no!');
expect(error).toHaveProperty('graphQLErrors.0.path', ['Query']);
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/exchanges/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface SerializedResult {
}

export interface SSRData {
[key: string]: SerializedResult | null;
[key: string]: SerializedResult;
}

export interface SSRExchangeParams {
Expand Down Expand Up @@ -91,7 +91,7 @@ const deserializeResult = (

/** The ssrExchange can be created to capture data during SSR and also to rehydrate it on the client */
export const ssrExchange = (params?: SSRExchangeParams): SSRExchange => {
const data: SSRData = {};
const data: Record<string, SerializedResult | null> = {};

// On the client-side, we delete results from the cache as they're resolved
// this is delayed so that concurrent queries don't delete each other's data
Expand Down Expand Up @@ -170,7 +170,11 @@ export const ssrExchange = (params?: SSRExchangeParams): SSRExchange => {
}
};

ssr.extractData = () => Object.assign({}, data);
ssr.extractData = () => {
const result: SSRData = {};
for (const key in data) if (data[key] != null) result[key] = data[key]!;
return result;
};

if (params && params.initialState) {
ssr.restoreData(params.initialState);
Expand Down

0 comments on commit 88638de

Please sign in to comment.