@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
85 lines (84 loc) • 3.18 kB
TypeScript
import { GraphQLResponseOptions, GraphQLVariables } from './graphql.js';
import { AdminSession } from '../session.js';
import { RequestModeInput } from '../http.js';
import { Variables } from 'graphql-request';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
/**
* Executes a GraphQL query against the Admin API.
*
* @param query - GraphQL query to execute.
* @param session - Shopify admin session including token and Store FQDN.
* @param variables - GraphQL variables to pass to the query.
* @returns The response of the query of generic type <T>.
*/
export declare function adminRequest<T>(query: string, session: AdminSession, variables?: GraphQLVariables): Promise<T>;
export interface AdminRequestOptions<TResult, TVariables extends Variables> {
/** GraphQL query to execute. */
query: TypedDocumentNode<TResult, TVariables>;
/** Shopify admin session including token and Store FQDN. */
session: AdminSession;
/** GraphQL variables to pass to the query. */
variables?: TVariables;
/** API version. */
version?: string;
/** Control how API responses will be handled. */
responseOptions?: GraphQLResponseOptions<TResult>;
/** Custom request behaviour for retries and timeouts. */
requestBehaviour?: RequestModeInput;
}
/**
* Executes a GraphQL query against the Admin API. Uses typed documents.
*
* @param options - Admin request options.
* @returns The response of the query of generic type <TResult>.
*/
export declare function adminRequestDoc<TResult, TVariables extends Variables>(options: AdminRequestOptions<TResult, TVariables>): Promise<TResult>;
/**
* GraphQL query to retrieve all supported API versions.
*
* @param session - Shopify admin session including token and Store FQDN.
* @returns - An array of supported API versions.
*/
export declare function supportedApiVersions(session: AdminSession): Promise<string[]>;
/**
* Returns the Admin API URL for the given store and version.
*
* @param store - Store FQDN.
* @param version - API version.
* @param session - User session.
* @returns - Admin API URL.
*/
export declare function adminUrl(store: string, version: string | undefined, session?: AdminSession): string;
/**
* Executes a REST request against the Admin API.
*
* @param method - Request's HTTP method.
* @param path - Path of the REST resource.
* @param session - Shopify Admin session including token and Store FQDN.
* @param requestBody - Request body of including REST resource specific parameters.
* @param searchParams - Search params, appended to the URL.
* @param apiVersion - Admin API version.
* @returns - The {@link RestResponse}.
*/
export declare function restRequest<T>(method: string, path: string, session: AdminSession, requestBody?: T, searchParams?: {
[name: string]: string;
}, apiVersion?: string): Promise<RestResponse>;
/**
* Respose of a REST request.
*/
export interface RestResponse {
/**
* REST JSON respose.
*/
json: any;
/**
* HTTP response status.
*/
status: number;
/**
* HTTP response headers.
*/
headers: {
[key: string]: string[];
};
}