UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

72 lines (71 loc) 2.56 kB
import { ConfSchema, TimeInterval } from '../../../private/node/conf-store.js'; import { LocalStorage } from '../local-storage.js'; import { RequestModeInput } from '../http.js'; import { rawRequest, RequestDocument, Variables } from 'graphql-request'; import { TypedDocumentNode } from '@graphql-typed-document-node/core'; export type Exact<T extends { [key: string]: unknown; }> = { [K in keyof T]: T[K]; }; export interface GraphQLVariables { [key: string]: any; } export type GraphQLResponse<T> = Awaited<ReturnType<typeof rawRequest<T>>>; export interface CacheOptions { cacheTTL: TimeInterval; cacheExtraKey?: string; cacheStore?: LocalStorage<ConfSchema>; } interface RefreshedTokenOnAuthorizedResponse { token?: string; } export type RefreshTokenOnAuthorizedResponse = Promise<RefreshedTokenOnAuthorizedResponse>; export interface UnauthorizedHandler { type: 'token_refresh'; handler: () => RefreshTokenOnAuthorizedResponse; } interface GraphQLRequestBaseOptions<TResult> { api: string; url: string; token?: string; addedHeaders?: { [header: string]: string; }; responseOptions?: GraphQLResponseOptions<TResult>; cacheOptions?: CacheOptions; preferredBehaviour?: RequestModeInput; } export type GraphQLRequestOptions<T> = GraphQLRequestBaseOptions<T> & { query: RequestDocument; variables?: Variables; unauthorizedHandler?: UnauthorizedHandler; requestBehaviour?: RequestModeInput; }; export type GraphQLRequestDocOptions<TResult, TVariables> = GraphQLRequestBaseOptions<TResult> & { query: TypedDocumentNode<TResult, TVariables> | TypedDocumentNode<TResult, Exact<{ [key: string]: never; }>>; variables?: TVariables; unauthorizedHandler?: UnauthorizedHandler; requestBehaviour?: RequestModeInput; }; export interface GraphQLResponseOptions<T> { handleErrors?: boolean; onResponse?: (response: GraphQLResponse<T>) => void; } /** * Executes a GraphQL query to an endpoint. * * @param options - GraphQL request options. * @returns The response of the query of generic type <T>. */ export declare function graphqlRequest<T>(options: GraphQLRequestOptions<T>): Promise<T>; /** * Executes a GraphQL query to an endpoint. Uses typed documents. * * @param options - GraphQL request options. * @returns The response of the query of generic type <TResult>. */ export declare function graphqlRequestDoc<TResult, TVariables extends Variables>(options: GraphQLRequestDocOptions<TResult, TVariables>): Promise<TResult>; export {};