@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
37 lines • 1.41 kB
JavaScript
import { graphqlRequestDoc } from './graphql.js';
import { appDevFqdn, normalizeStoreFqdn } from '../context/fqdn.js';
import { serviceEnvironment } from '../../../private/node/context/service.js';
import Bottleneck from 'bottleneck';
// API Rate limiter
// Jobs are launched every 150ms
// Only 10 requests can be executed concurrently.
const limiter = new Bottleneck({
minTime: 150,
maxConcurrent: 10,
});
/**
* Executes an org-scoped GraphQL query against the App Management API.
* Uses typed documents.
*
* @param options - The options for the request.
* @returns The response of the query of generic type <T>.
*/
export async function appDevRequestDoc(options) {
const api = 'App Dev';
const normalizedShopFqdn = normalizeStoreFqdn(options.shopFqdn);
const fqdn = await appDevFqdn(normalizedShopFqdn);
const url = `https://${fqdn}/app_dev/unstable/graphql.json`;
const addedHeaders = serviceEnvironment() === 'local' ? { 'x-forwarded-host': normalizedShopFqdn } : undefined;
const result = limiter.schedule(() => graphqlRequestDoc({
query: options.query,
api,
url,
token: options.token,
addedHeaders,
variables: options.variables,
unauthorizedHandler: options.unauthorizedHandler,
preferredBehaviour: options.requestOptions?.requestMode,
}));
return result;
}
//# sourceMappingURL=app-dev.js.map