-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Magento store code not getting set in context.headers.store
- Loading branch information
1 parent
d708e06
commit 9b33eac
Showing
3 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphcommerce/magento-store': patch | ||
--- | ||
|
||
Fix Magento store code not getting set in context.headers.store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/magento-store/plugins/magentoStoreGraphqlConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { setContext, type graphqlConfig as graphqlConfigType } from '@graphcommerce/graphql' | ||
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config' | ||
|
||
export const config: PluginConfig = { | ||
type: 'function', | ||
module: '@graphcommerce/graphql', | ||
} | ||
|
||
export const graphqlConfig: FunctionPlugin<typeof graphqlConfigType> = (prev, conf) => { | ||
const results = prev(conf) | ||
|
||
return { | ||
...results, | ||
links: [ | ||
...results.links, | ||
setContext((_, context) => { | ||
if (!context.headers) context.headers = {} | ||
context.headers.store = conf.storefront.magentoStoreCode | ||
|
||
if (conf.preview) { | ||
// To disable caching from the backend, we provide a bogus cache ID. | ||
context.headers['x-magento-cache-id'] = | ||
`random-cache-id${Math.random().toString(36).slice(2)}` | ||
} | ||
return context | ||
}), | ||
], | ||
} | ||
} |