Skip to content

GraphqlClient

Defined in: graphql-client/src/GraphqlClient.ts:12

Graphql Client class provides functionality specific to GraphQL servers.

  • ApiClientOptions
  • BaseUrl
  • ApiClient
new GraphqlClient(baseUrl, options?): GraphqlClient;

Defined in: graphql-client/src/GraphqlClient.ts:18

Creates a new instance of the GraphqlClient.

string

The base URL of the API. BaseUrl

ApiClientOptions

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

GraphqlClient

ApiClient.constructor
apiPrefix: string | undefined;

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

ApiClientOptions.apiPrefix

ApiClient.apiPrefix

authentication: Authentication | undefined;

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

ApiClientOptions.authentication

ApiClient.authentication

baseUrl: string;

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

BaseUrl

ApiClient.baseUrl

cache: Cache | undefined;

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

ApiClientOptions.cache

ApiClient.cache

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

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

ApiClientOptions.customFetch

ApiClient.customFetch

debug: boolean | undefined;

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

ApiClientOptions.debug

ApiClient.debug

defaultLocale: string | undefined;

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

ApiClientOptions.defaultLocale

ApiClient.defaultLocale

logger:
| {
debug?: LogMethod;
error?: LogMethod;
http?: LogMethod;
info?: LogMethod;
silly?: LogMethod;
verbose?: LogMethod;
warn?: LogMethod;
}
| undefined;

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

ApiClientOptions.logger

ApiClient.logger

serializer: Serializer | undefined;

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

ApiClientOptions.serializer

ApiClient.serializer
addAuthorizationHeader(options): Promise<RequestInit>;

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

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.

RequestInit | undefined

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

Promise<RequestInit>

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

ApiClient.addAuthorizationHeader

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

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

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

RequestInfo | URL

RequestInfo

RequestInit

RequestInit

Promise<FetchReturn>

a response wrapped in a promise

ApiClient.fetch

protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>;

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

Fetch the OAuth token from the BaseUrl

OAuthCredentials

Promise<OAuthTokenResponse>

params - The credentials for getting an OAuth token. OAuthCredentials

ApiClient.getAccessToken

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

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

Retrieves a cached response from the cache.

T

string

The cache key to use for retrieving the cached response.

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

A promise wrapping the cached response as a generic type.

ApiClient.getCachedResponse

log(level, message): void;

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

Calls the appropriate logger method based on level

LogLevels

level based on npm log levels

string

the message to log

void

ApiClient.log

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

Defined in: graphql-client/src/GraphqlClient.ts:42

Retrieves data of a specific shape from GraphQL.

T

string

a string containing the desired GraphQL Query.

Promise<T>

A Promise that resolves to the requested JSON data.

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