kodadot/nft-gallery

View on GitHub
utils/queryPathResolver.ts

Summary

Maintainability
A
0 mins
Test Coverage
function resolveQueryPath(
  prefix: string,
  queryName: string,
): Promise<typeof import('*.graphql')> {
  // TODO: find a better way?
  const path = getPath(prefix)
  const MODULES = import.meta.glob('../queries/**/*.graphql')
  return MODULES[`../queries/${path}${queryName}.graphql`]() as Promise<
    typeof import('*.graphql')
  >
  // return import(/* @vite-ignore */ `../queries/${path}${queryName}.graphql`)
}

function getPath(prefix: string) {
  switch (prefix) {
    case 'chain-ahk':
      return 'subsquid/ahk/'
    default:
      return 'subsquid/general/'
  }
}

export default resolveQueryPath