GraphqlClient
Graphql Client class provides functionality specific to GraphQL servers.
See
- ApiClientOptions
- BaseUrl
Extends
ApiClient
Constructors
new 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
Overrides
ApiClient.constructor
Source
graphql-client/src/GraphqlClient.ts:18
Properties
#private
Inherited from
ApiClient.#private
Source
api-client/dist/index.d.mts:208
apiPrefix
Inherited from
ApiClient.apiPrefix
Source
api-client/dist/index.d.mts:216
authentication
ApiClientOptions.authentication
Inherited from
ApiClient.authentication
Source
api-client/dist/index.d.mts:224
baseUrl
BaseUrl
Inherited from
ApiClient.baseUrl
Source
api-client/dist/index.d.mts:212
cache
Inherited from
ApiClient.cache
Source
api-client/dist/index.d.mts:232
customFetch
Inherited from
ApiClient.customFetch
Source
api-client/dist/index.d.mts:220
debug
Inherited from
ApiClient.debug
Source
api-client/dist/index.d.mts:244
defaultLocale
ApiClientOptions.defaultLocale
Inherited from
ApiClient.defaultLocale
Source
api-client/dist/index.d.mts:228
logger
Inherited from
ApiClient.logger
Source
api-client/dist/index.d.mts:240
serializer
Inherited from
ApiClient.serializer
Source
api-client/dist/index.d.mts:236
Methods
addAuthorizationHeader()
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()
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()
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()
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()
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()
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
Source
graphql-client/src/GraphqlClient.ts:42