fix: pass headers to apollo

This commit is contained in:
vchikalkin 2024-07-25 17:10:52 +03:00
parent 9447bba00e
commit d76040bb95
3 changed files with 8 additions and 4 deletions

View File

@ -14,6 +14,10 @@ function createApolloClient(headers) {
}
export default function initializeApollo(initialState, headers) {
if (isServer() && !headers) {
throw new Error('initializeApollo: headers must be provided in server side');
}
const _apolloClient = apolloClient ?? createApolloClient(headers);
// If your page has Next.js data fetching methods that use Apollo Client, the initial state

View File

@ -13,9 +13,9 @@ export const eltKaskoRouter = router({
eltKasko: protectedProcedure
.input(EltInputSchema)
.output(EltOutputSchema)
.mutation(async ({ input }) => {
.mutation(async ({ input, ctx }) => {
try {
const apolloClient = initializeApollo();
const apolloClient = initializeApollo(null, ctx.headers);
const store = new RootStore();
store.$calculation.$values.hydrate(input.calculation.values);

View File

@ -13,9 +13,9 @@ export const eltOsagoRouter = router({
eltOsago: protectedProcedure
.input(EltInputSchema)
.output(EltOutputSchema)
.mutation(async ({ input }) => {
.mutation(async ({ input, ctx }) => {
try {
const apolloClient = initializeApollo();
const apolloClient = initializeApollo(null, ctx.headers);
const store = new RootStore();
store.$calculation.$values.hydrate(input.calculation.values);