From 3c21fe97d5056420b0a5782e0829df3fea39e250 Mon Sep 17 00:00:00 2001 From: admirsaheta Date: Tue, 7 Jan 2025 11:26:06 +0100 Subject: [PATCH 1/4] feat:extend(gql): client-types --- .../src/graphql-client/types.ts | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/api-clients/graphql-client/src/graphql-client/types.ts b/packages/api-clients/graphql-client/src/graphql-client/types.ts index 767f97b987..420adfe121 100644 --- a/packages/api-clients/graphql-client/src/graphql-client/types.ts +++ b/packages/api-clients/graphql-client/src/graphql-client/types.ts @@ -1,5 +1,5 @@ interface CustomRequestInit { - method?: string; + method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; headers?: HeadersInit; body?: string; signal?: AbortSignal; @@ -10,7 +10,7 @@ export type CustomFetchApi = ( init?: CustomRequestInit, ) => Promise; -type OperationVariables = Record; +type OperationVariables> = TVariables; export type DataChunk = Buffer | Uint8Array; @@ -21,11 +21,28 @@ export type {HeadersObject as Headers}; export interface ResponseErrors { networkStatusCode?: number; message?: string; - graphQLErrors?: any[]; + graphQLErrors?: Array<{ + message: string; + extensions?: GQLExtensions; + }>; response?: Response; } -export type GQLExtensions = Record; +export interface GQLExtensions { + cost?: { + requestedQueryCost: number; + actualQueryCost: number; + throttleStatus: { + maximumAvailable: number; + currentlyAvailable: number; + restoreRate: number; + }; + code?: string; + maxCost?: number; + documentation?: string; + [key: string]: unknown; + }; +} export interface FetchResponseBody { data?: TData; @@ -37,6 +54,12 @@ export interface ClientResponse extends FetchResponseBody { errors?: ResponseErrors; } +export type SuccessClientResponse = Omit< + ClientResponse, + 'errors' +>; +export type ErrorClientResponse = Omit; + export interface ClientStreamResponse extends ClientResponse { hasNext: boolean; @@ -76,11 +99,11 @@ export type Logger = ( ) => void; export interface ClientOptions { - headers: HeadersObject; + readonly headers: HeadersObject; url: string; customFetchApi?: CustomFetchApi; retries?: number; - logger?: Logger; + readonly logger?: Logger; } export interface ClientConfig { @@ -90,11 +113,11 @@ export interface ClientConfig { } export interface RequestOptions { - variables?: OperationVariables; - url?: string; - headers?: HeadersObject; - retries?: number; - signal?: AbortSignal; + readonly variables?: OperationVariables; + readonly url?: string; + readonly headers?: HeadersObject; + readonly retries?: number; + readonly signal?: AbortSignal; } export type RequestParams = [operation: string, options?: RequestOptions]; From d5e2f308145c966cba644ef05ba1b585ead6a5fd Mon Sep 17 00:00:00 2001 From: admirsaheta Date: Tue, 7 Jan 2025 11:29:55 +0100 Subject: [PATCH 2/4] feat(gql):client-types changeset --- .changeset/big-scissors-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/big-scissors-raise.md diff --git a/.changeset/big-scissors-raise.md b/.changeset/big-scissors-raise.md new file mode 100644 index 0000000000..20a858f243 --- /dev/null +++ b/.changeset/big-scissors-raise.md @@ -0,0 +1,5 @@ +--- +'@shopify/graphql-client': minor +--- + +Extends GraphQL Client Types for better DevX From 21e6d45c772dd9853c5c77828676e28e47637b65 Mon Sep 17 00:00:00 2001 From: admirsaheta Date: Tue, 7 Jan 2025 11:39:45 +0100 Subject: [PATCH 3/4] fix:options-type --- .../api-clients/graphql-client/src/graphql-client/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api-clients/graphql-client/src/graphql-client/types.ts b/packages/api-clients/graphql-client/src/graphql-client/types.ts index 420adfe121..5affeb1e23 100644 --- a/packages/api-clients/graphql-client/src/graphql-client/types.ts +++ b/packages/api-clients/graphql-client/src/graphql-client/types.ts @@ -99,11 +99,11 @@ export type Logger = ( ) => void; export interface ClientOptions { - readonly headers: HeadersObject; + headers: HeadersObject; url: string; customFetchApi?: CustomFetchApi; retries?: number; - readonly logger?: Logger; + logger?: Logger; } export interface ClientConfig { From 6ed14f8b16e7219f794e4a09e871a07e158eaee2 Mon Sep 17 00:00:00 2001 From: admirsaheta Date: Tue, 7 Jan 2025 11:51:01 +0100 Subject: [PATCH 4/4] fix:eslint-suggestion --- .../api-clients/graphql-client/src/graphql-client/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api-clients/graphql-client/src/graphql-client/types.ts b/packages/api-clients/graphql-client/src/graphql-client/types.ts index 5affeb1e23..0134919810 100644 --- a/packages/api-clients/graphql-client/src/graphql-client/types.ts +++ b/packages/api-clients/graphql-client/src/graphql-client/types.ts @@ -21,10 +21,10 @@ export type {HeadersObject as Headers}; export interface ResponseErrors { networkStatusCode?: number; message?: string; - graphQLErrors?: Array<{ + graphQLErrors?: { message: string; extensions?: GQLExtensions; - }>; + }[]; response?: Response; }