Skip to content

Commit a322c4e

Browse files
committed
fix: fix language & preview in GraphQL SSR
1 parent 178525a commit a322c4e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/smooth/src/server/apollo.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {
88
import { ValidateLink } from './links/validate'
99
import { createAPIClient } from '../api'
1010

11-
export function getContext({ req, config }) {
12-
const lang = req.headers['x-smooth-lang'] || null
13-
const preview = Boolean(req.headers['x-smooth-preview'])
14-
const id = req.headers['x-smooth-preview-id'] || null
11+
export function getContext({ req, config, operationContext }) {
12+
const headers = operationContext ? operationContext.headers : req.headers
13+
const lang = headers['x-smooth-lang'] || null
14+
const preview = Boolean(headers['x-smooth-preview'])
15+
const id = headers['x-smooth-preview-id'] || null
1516
return {
1617
api: createAPIClient({ config, lang }),
1718
lang,

packages/smooth/src/server/ssr.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ export default function ssrMiddleware({
9595
const apolloClient = createApolloClient({
9696
schema,
9797
fragmentTypes,
98-
context: getContext({ req, config }),
98+
context: operation =>
99+
getContext({ req, config, operationContext: operation.getContext() }),
99100
})
100101

101102
let jsx = (

0 commit comments

Comments
 (0)