@@ -18,6 +18,8 @@ import {RequestModeInput, shopifyFetch} from '../http.js'
1818import { PublicApiVersions } from '../../../cli/api/graphql/admin/generated/public_api_versions.js'
1919import { normalizeStoreFqdn } from '../context/fqdn.js'
2020import { themeKitAccessDomain } from '../../../private/node/constants.js'
21+ import { serviceEnvironment } from '../../../private/node/context/service.js'
22+ import { DevServerCore } from '../vendor/dev_server/index.js'
2123import { ClientError , Variables } from 'graphql-request'
2224import { TypedDocumentNode } from '@graphql-typed-document-node/core'
2325
@@ -34,9 +36,15 @@ const LatestApiVersionByFQDN = new Map<string, string>()
3436export async function adminRequest < T > ( query : string , session : AdminSession , variables ?: GraphQLVariables ) : Promise < T > {
3537 const api = 'Admin'
3638 const version = await fetchLatestSupportedApiVersion ( session )
37- const store = await normalizeStoreFqdn ( session . storeFqdn )
38- const url = adminUrl ( store , version , session )
39+ let storeDomain = await normalizeStoreFqdn ( session . storeFqdn )
3940 const addedHeaders = themeAccessHeaders ( session )
41+
42+ if ( serviceEnvironment ( ) === 'local' ) {
43+ addedHeaders [ 'x-forwarded-host' ] = storeDomain
44+ storeDomain = new DevServerCore ( ) . host ( 'app' )
45+ }
46+
47+ const url = adminUrl ( storeDomain , version , session )
4048 return graphqlRequest ( { query, api, addedHeaders, url, token : session . token , variables} )
4149}
4250
@@ -70,10 +78,16 @@ export async function adminRequestDoc<TResult, TVariables extends Variables>(
7078 if ( ! apiVersion ) {
7179 apiVersion = await fetchLatestSupportedApiVersion ( session )
7280 }
73- const store = await normalizeStoreFqdn ( session . storeFqdn )
81+ let storeDomain = await normalizeStoreFqdn ( session . storeFqdn )
7482 const addedHeaders = themeAccessHeaders ( session )
83+
84+ if ( serviceEnvironment ( ) === 'local' ) {
85+ addedHeaders [ 'x-forwarded-host' ] = storeDomain
86+ storeDomain = new DevServerCore ( ) . host ( 'app' )
87+ }
88+
7589 const opts = {
76- url : adminUrl ( store , apiVersion , session ) ,
90+ url : adminUrl ( storeDomain , apiVersion , session ) ,
7791 api : 'Admin' ,
7892 token : session . token ,
7993 addedHeaders,
0 commit comments