Skip to content

Commit

Permalink
Stop killing vite
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Oct 31, 2023
1 parent 6a7f17e commit d0f98f8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions frontend/src/lib/gql/gql-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,22 @@ class GqlClient {
context: {fetch, ...context}
});

return derived(resultStore, (result) => {
this.throwAnyUnexpectedErrors(result);
return result;
});
if (browser) {
return derived(resultStore, (result) => {
this.throwAnyUnexpectedErrors(result);
return result;
});
} else {
/**
* We kill vite if we validate each query result and throw in the urql pipeline, but we shouldn't ever need to, because:
* 1) Only the initial result of the query store will ever be fetched server-side
* 2) If we want to await the initial result server-side, then we should be using `awaitedQueryStore`, where we CAN safely validate the result and throw
* 3) If we don't await the initial result server-side then there should never be a result OR an error server-side
*/
return resultStore;
}
}

async awaitedQueryStore<Data = unknown, Variables extends AnyVariables = AnyVariables>(
fetch: Fetch,
query: TypedDocumentNode<Data, Variables>,
Expand All @@ -118,6 +129,8 @@ class GqlClient {
});
});

this.throwAnyUnexpectedErrors(results);

const keys = Object.keys(results.data ?? {}) as Array<keyof typeof results.data>;
const resultData = {} as Record<string, Readable<unknown>>;
for (const key of keys) {
Expand Down

0 comments on commit d0f98f8

Please sign in to comment.