Skip to main content

GlobalDataResolver

globalDataResolver is designed to handle API calls required during the initial loading of the application. This function is executed by theme engine only once and it gets the applicationID and the fpi instance as arguments- and performs asynchronous calls to fetch essential data. The function calling is managed by the Skyfire Theme Engine; theme developers just need to define the function.

Example:

//helper/lib

export async function globalDataResolver({ fpi,applicationID }) {
return Promise.all([
fpi.configuration.fetchApplication(),
fpi.content.fetchLandingPage(),
fpi.content.fetchAppSeo(),
fpi.content?.fetchTags(),
fpi.auth?.fetchPlatformData({id:applicationID}),
]).catch(console.log);

}
// Export it from index.jsx file

import { globalDataResolver } from "./helper/lib";

return {
globalDataResolver

//other keys....
}

Full argument reference

The example above destructures two keys, but the theme engine passes more. During server-side rendering the engine calls globalDataResolver with one object:

KeyTypeContents
fpiobjectThe Fynd Platform Interface instance
themeIdstringThe identifier of the applied theme
applicationIDstringThe identifier of the sales channel
cookiesobjectthemeCookie, userGroups, userAppLocationDetails, userStatus, and any extra cookies the platform is configured to forward
headersobjectuserData, userStatus, userAgent, storeData, userGroups, experimentalFeatures, and any extra headers the platform is configured to forward
queryobjectisEdit, previewId, navigationPreviewId

Read Request Context for what each value means and which outbound header carries it.

The client call is smaller

The engine calls globalDataResolver in the browser only when the page was not server-rendered. A page that arrives through server-side rendering does not call it again after hydration.

When the browser does call it, the object is much smaller:

{
fpi,
applicationID,
cookies: {
themeCookie,
userAppLocationDetails,
},
}

There is no themeId, no headers, and no query. Guard every read, and never assume a key is present:

export async function globalDataResolver({ fpi, applicationID, headers = {}, query = {} }) {
const { userAgent } = headers; // undefined in the browser
}

Returning cookies

A resolver may return a cookies array. During server-side rendering the engine collects the arrays from both resolvers and sets them on the response.

export async function globalDataResolver({ fpi }) {
await Promise.all([fpi.configuration.fetchApplication()]);

return {
cookies: [{ name: "theme_variant", value: "dark", options: { path: "/" } }],
};
}

A return value is optional. A resolver that returns nothing is valid.


Was this section helpful?