Skip to main content

Class: GraphQLClient

Defined in: client/GraphQLClient.ts:185

A GraphQL client for the Propeller eCommerce Platform.

Features:

  • Per-operation imports — services bring their own GraphQL documents.
  • Secure proxy mode to keep API keys server-side.
  • API key routing for order-editor mutations in direct mode.
  • Configurable access token provider for SSR / custom storage.
  • TypeScript support with full type safety.

SECURITY: Use 'proxy' mode in production to keep API keys server-side.

Constructors​

Constructor​

new GraphQLClient(config): GraphQLClient

Defined in: client/GraphQLClient.ts:195

Parameters​

config​

GraphQLClientConfig

Client configuration

Returns​

GraphQLClient

Methods​

clearAccessToken()​

clearAccessToken(): void

Defined in: client/GraphQLClient.ts:570

Clear access token (logout).

Returns​

void


execute()​

execute<T>(operation): Promise<GraphQLResponse<T>>

Defined in: client/GraphQLClient.ts:367

Execute a GraphQL operation.

Returns the raw GraphQLResponse (with data and/or errors). This is the low-level entry point; it does not throw on GraphQL errors so callers who want to inspect partial responses can do so. The higher-level query() / mutate() helpers and the runOperation helper used by services throw GraphQLOperationError when errors is non-empty.

A query whose connection drops (fetch failed) is sent once more, within the same timeout, before the error is thrown. Mutations are never resent.

Type Parameters​

T​

T = any

Parameters​

operation​

GraphQLOperation

Returns​

Promise<GraphQLResponse<T>>


getAccessToken()​

getAccessToken(): Promise<string | undefined>

Defined in: client/GraphQLClient.ts:580

Get current access token using the configured provider. Returns undefined if no provider yields a token.

Returns​

Promise<string | undefined>


getConfig()​

getConfig(): Omit<GraphQLClientConfig, "apiKey" | "orderEditorApiKey">

Defined in: client/GraphQLClient.ts:532

Get current client configuration (without sensitive data).

Returns​

Omit<GraphQLClientConfig, "apiKey" | "orderEditorApiKey">


getDefaultLanguage()​

getDefaultLanguage(): string | undefined

Defined in: client/GraphQLClient.ts:287

Configured default language tag (ISO 639-1), or undefined if not set.

Returns​

string | undefined


getFragment()​

getFragment(name): string | undefined

Defined in: client/GraphQLClient.ts:257

Look up a registered fragment by name.

Parameters​

name​

string

Returns​

string | undefined


getFragmentNames()​

getFragmentNames(): string[]

Defined in: client/GraphQLClient.ts:272

Names of all registered fragments.

Returns​

string[]


getMutation()​

getMutation(name): string | undefined

Defined in: client/GraphQLClient.ts:267

Look up a registered mutation by name.

Parameters​

name​

string

Returns​

string | undefined


getMutationNames()​

getMutationNames(): string[]

Defined in: client/GraphQLClient.ts:282

Names of all registered mutations.

Returns​

string[]


getQuery()​

getQuery(name): string | undefined

Defined in: client/GraphQLClient.ts:262

Look up a registered query by name.

Parameters​

name​

string

Returns​

string | undefined


getQueryNames()​

getQueryNames(): string[]

Defined in: client/GraphQLClient.ts:277

Names of all registered queries.

Returns​

string[]


getSecurityMode()​

getSecurityMode(): "proxy" | "direct"

Defined in: client/GraphQLClient.ts:538

Get current security mode.

Returns​

"proxy" | "direct"


isAuthenticated()​

isAuthenticated(): Promise<boolean>

Defined in: client/GraphQLClient.ts:586

True iff the access-token resolver yields a non-empty token.

Returns​

Promise<boolean>


isSecureMode()​

isSecureMode(): boolean

Defined in: client/GraphQLClient.ts:543

True iff the client is in secure proxy mode.

Returns​

boolean


mutate()​

mutate<T>(mutation, variables?, operationName?): Promise<T>

Defined in: client/GraphQLClient.ts:461

Execute a GraphQL mutation, throwing on errors and returning data directly.

Type Parameters​

T​

T = any

Parameters​

mutation​

string

variables?​

Record<string, any>

operationName?​

string

Returns​

Promise<T>


mutateByName()​

mutateByName<T>(mutationName, variables?): Promise<T>

Defined in: client/GraphQLClient.ts:504

Execute a registered mutation by name. Only resolves mutations registered via registerMutation() — see queryByName.

Type Parameters​

T​

T = any

Parameters​

mutationName​

string

variables?​

Record<string, any>

Returns​

Promise<T>


query()​

query<T>(query, variables?, operationName?): Promise<T>

Defined in: client/GraphQLClient.ts:440

Execute a GraphQL query, throwing on errors and returning data directly.

Type Parameters​

T​

T = any

Parameters​

query​

string

variables?​

Record<string, any>

operationName?​

string

Returns​

Promise<T>


queryByName()​

queryByName<T>(queryName, variables?): Promise<T>

Defined in: client/GraphQLClient.ts:485

Execute a registered query by name. Only resolves queries registered via registerQuery() — bundled service operations are no longer preloaded into the client and should be invoked through the service factories (productService(client).getProduct(...)).

Type Parameters​

T​

T = any

Parameters​

queryName​

string

variables?​

Record<string, any>

Returns​

Promise<T>


registerFragment()​

registerFragment(name, definition): void

Defined in: client/GraphQLClient.ts:242

Register a GraphQL fragment by name. Fragments are inlined at build time into service operations; this registration is used by ad-hoc callers who compose documents themselves via execute().

Parameters​

name​

string

definition​

string

Returns​

void


registerMutation()​

registerMutation(name, definition): void

Defined in: client/GraphQLClient.ts:252

Register a custom mutation string under a name for use with mutateByName.

Parameters​

name​

string

definition​

string

Returns​

void


registerQuery()​

registerQuery(name, definition): void

Defined in: client/GraphQLClient.ts:247

Register a custom query string under a name for use with queryByName.

Parameters​

name​

string

definition​

string

Returns​

void


setAccessToken()​

setAccessToken(token): void

Defined in: client/GraphQLClient.ts:554

Set access token for authentication.

Writes to localStorage['access_token'] in the browser. Only meaningful when using the default getAccessToken resolver — if a custom resolver is configured, this method does not affect what that resolver returns.

Parameters​

token​

string

Returns​

void


updateConfig()​

updateConfig(newConfig): void

Defined in: client/GraphQLClient.ts:522

Update client configuration.

Parameters​

newConfig​

Partial<GraphQLClientConfig>

Returns​

void