Skip to content

GraphqlClient

Graphql Client class provides functionality specific to GraphQL servers.

See

  • ApiClientOptions
  • BaseUrl

Extends

  • ApiClient

Constructors

new GraphqlClient()

new GraphqlClient(baseUrl, options?): GraphqlClient

Creates a new instance of the GraphqlClient.

Parameters

baseUrl: string

The base URL of the API. BaseUrl

options?: ApiClientOptions

(Optional) Additional options for configuring the API client. ApiClientOptions

Returns

GraphqlClient

Overrides

ApiClient.constructor

Source

graphql-client/src/GraphqlClient.ts:18

Properties

#private

private #private: any;

Inherited from

ApiClient.#private

Source

api-client/dist/index.d.mts:208


apiPrefix

apiPrefix: undefined | string;

ApiClientOptions.apiPrefix

Inherited from

ApiClient.apiPrefix

Source

api-client/dist/index.d.mts:216


authentication

authentication: undefined | Authentication;

ApiClientOptions.authentication

Inherited from

ApiClient.authentication

Source

api-client/dist/index.d.mts:224


baseUrl

baseUrl: string;

BaseUrl

Inherited from

ApiClient.baseUrl

Source

api-client/dist/index.d.mts:212


cache

cache: undefined | Cache;

ApiClientOptions.cache

Inherited from

ApiClient.cache

Source

api-client/dist/index.d.mts:232


customFetch

customFetch: undefined | (input, init?) => Promise<Response>;

ApiClientOptions.customFetch

Inherited from

ApiClient.customFetch

Source

api-client/dist/index.d.mts:220


debug

debug: undefined | boolean;

ApiClientOptions.debug

Inherited from

ApiClient.debug

Source

api-client/dist/index.d.mts:244


defaultLocale

defaultLocale: undefined | string;

ApiClientOptions.defaultLocale

Inherited from

ApiClient.defaultLocale

Source

api-client/dist/index.d.mts:228


logger

logger: undefined | object;

ApiClientOptions.logger

Inherited from

ApiClient.logger

Source

api-client/dist/index.d.mts:240


serializer

serializer: undefined | Serializer;

ApiClientOptions.serializer

Inherited from

ApiClient.serializer

Source

api-client/dist/index.d.mts:236

Methods

addAuthorizationHeader()

addAuthorizationHeader(options): Promise<RequestInit>

Adds an authorization header to the provided RequestInit options if authentication of type “Basic” is configured. If the authentication type is “OAuth”, it will fetch a new access token or use the stored access token if it exists and is still valid. if the authentication type is “Custom”, it will use the provided value.

Parameters

options: undefined | RequestInit

The RequestInit options to which the authorization header should be added.

Returns

Promise<RequestInit>

The updated RequestInit options with the authorization header, if applicable.

Inherited from

ApiClient.addAuthorizationHeader

Source

api-client/dist/index.d.mts:274


fetch()

fetch(input, init?): Promise<FetchReturn>

Uses customFetch if it is set, otherwise uses the default fetch

Parameters

input: RequestInfo | URL

RequestInfo

init?: RequestInit

RequestInit

Returns

Promise<FetchReturn>

a response wrapped in a promise

Inherited from

ApiClient.fetch

Source

api-client/dist/index.d.mts:257


getAccessToken()

protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>

Fetch the OAuth token from the BaseUrl

Parameters

__namedParameters: OAuthCredentials

Returns

Promise<OAuthTokenResponse>

Inherited from

ApiClient.getAccessToken

Params

params - The credentials for getting an OAuth token. OAuthCredentials

Source

api-client/dist/index.d.mts:262


getCachedResponse()

getCachedResponse<T>(cacheKey): Promise<null | NonNullable<Awaited<T>>>

Retrieves a cached response from the cache.

Type parameters

T

Parameters

cacheKey: string

The cache key to use for retrieving the cached response.

Returns

Promise<null | NonNullable<Awaited<T>>>

A promise wrapping the cached response as a generic type.

Inherited from

ApiClient.getCachedResponse

Source

api-client/dist/index.d.mts:286


log()

log(level, message): void

Calls the appropriate logger method based on level

Parameters

level: LogLevels

level based on npm log levels

message: string

the message to log

Returns

void

Inherited from

ApiClient.log

Source

api-client/dist/index.d.mts:280


query()

query<T>(query): Promise<T>

Retrieves data of a specific shape from GraphQL.

Type parameters

T

Parameters

query: string

a string containing the desired GraphQL Query.

Returns

Promise<T>

A Promise that resolves to the requested JSON data.

Example

const query = await graphqlClient.query(
`query GetArticles {
nodeArticles(first: 10) {
nodes {
title
}
}
}`,
);

Source

graphql-client/src/GraphqlClient.ts:42