PageSourceSearch

https://www.americaneagle.ae/scripts/graphql/load-queries.js

js americaneagle.ae collected 2026-10-02 13:25:50 UTC 2,166 bytes, 69 lines download raw bytes

1import { getBrandConfigs } from '../configs.js';
2
3function isBrandQueryEnabled(path, brandConfigs) {
4  if (brandConfigs?.noconfig) return true;
5
6  if (path === 'commerce' && brandConfigs?.graphql?.commerce) return true;
7  if (path === 'product-list' && brandConfigs?.graphql?.product) return true;
8
9  return false;
10}
11
12/**
13 * Load brand graphql queries based on based on path
14 * @param {DOM} path
15 */
16export async function loadQueries(path) {
17  const { brandPath } = window.axp;
18
19  const cache = loadQueries.cache || (loadQueries.cache = new Map());
20  const cacheKey = `${brandPath}${path}`;
21
22  if (cache.has(cacheKey)) {
23    return Promise.resolve(cache.get(cacheKey));
24  }
25
26  let queries = {};
27  const brandConfigs = await getBrandConfigs();
28  try {
29    // load brand specific graphql file
30    const brandQueriesPath = `/scripts/graphql/${brandPath}${path}.graphql.js`;
31    const defaultQueriesPath = `/scripts/graphql/${path}.graphql.js`;
32    let resultBrandQueries = { default: {} };
33    let resultCoreQueries = { default: {} };
34
35    if (isBrandQueryEnabled(path, brandConfigs)) {
36      [resultCoreQueries, resultBrandQueries] = await Promise.all([
37        import(defaultQueriesPath).catch((e) => {
38          console.error(`Default GraphQL file not found: ${defaultQueriesPath}`, e);
39          return { default: {} };
40        }),
41        import(brandQueriesPath).catch((e) => {
42          console.error(`Default GraphQL file not found: ${brandQueriesPath}`, e);
43          return { default: {} };
44        }),
45      ]);
46    } else {
47      [resultCoreQueries] = await Promise.all([
48        import(defaultQueriesPath).catch((e) => {
49          console.error(`Default GraphQL file not found: ${defaultQueriesPath}`, e);
50          return { default: {} };
51        }),
52      ]);
53    }
54
55    // Process results
56    const brandQueries = resultBrandQueries?.default || {};
57    const coreQueries = resultCoreQueries?.default || {};
58
59    // merge brand and core queries
60    queries = { ...coreQueries, ...brandQueries };
61  } catch (e) {
62    console.error('Error loading GraphQL queries:', e);
63  }
64
65  cache.set(cacheKey, queries);
66  return queries;
67}
68
69export default loadQueries;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.