UNPKG

@nhost/graphql-js

Version:

Nhost GraphQL client

114 lines (113 loc) 4.14 kB
import { NhostGraphqlConstructorParams, NhostGraphqlRequestConfig, NhostGraphqlRequestResponse, RemoveIndex, RequestDocument, RequestOptions, Variables } from './types'; import { TypedDocumentNode } from '@graphql-typed-document-node/core'; /** * @alias GraphQL */ export declare class NhostGraphqlClient { readonly _url: string; private accessToken; private adminSecret?; private headers; constructor(params: NhostGraphqlConstructorParams); private isAccessTokenValidOrNull; private awaitForValidAccessTokenOrNull; /** * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react). * * @example * ```ts * const CUSTOMERS = gql` * query { * customers { * id * name * } * } * ` * const { data, error } = await nhost.graphql.request(CUSTOMERS) * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/request */ request<T = any, V = Variables>(document: RequestDocument | TypedDocumentNode<T, V>, ...variablesAndRequestHeaders: V extends Record<any, never> ? [variables?: V, config?: NhostGraphqlRequestConfig] : keyof RemoveIndex<V> extends never ? [variables?: V, config?: NhostGraphqlRequestConfig] : [variables: V, config?: NhostGraphqlRequestConfig]): Promise<NhostGraphqlRequestResponse<T>>; request<T = any, V extends Variables = Variables>(options: RequestOptions<V, T>): Promise<NhostGraphqlRequestResponse<T>>; /** * Use `nhost.graphql.httpUrl` to get the GraphQL HTTP URL. * @example * ```ts * const url = nhost.graphql.httpUrl; * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/get-http-url */ get httpUrl(): string; /** * Use `nhost.graphql.wsUrl` to get the GraphQL WebSocket URL. * @example * ```ts * const url = nhost.graphql.wsUrl; * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/get-ws-url */ get wsUrl(): string; /** * Use `nhost.graphql.url` to get the GraphQL URL. * @deprecated Use `nhost.graphql.httpUrl` and `nhost.graphql.wsUrl` instead. */ get url(): string; /** * Use `nhost.graphql.getUrl()` to get the GraphQL URL. * @deprecated Use `nhost.graphql.httpUrl` and `nhost.graphql.wsUrl` instead. */ getUrl(): string; /** * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically. * * @example * ```ts * nhost.graphql.setAccessToken('some-access-token') * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/set-access-token */ setAccessToken(accessToken: string | undefined): void; /** * Use `nhost.graphql.getHeaders` to get the global headers sent with all graphql requests * * @example * ```ts * nhost.graphql.getHeaders() * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/get-headers */ getHeaders(): Record<string, string>; /** * Use `nhost.graphql.setHeaders` to set global headers to be sent in all subsequent graphql requests * * @example * ```ts * nhost.graphql.setHeaders({ * 'x-hasura-role': 'admin' * }) * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/set-headers */ setHeaders(headers?: Record<string, string>): void; /** * Use `nhost.graphql.unsetHeaders` to remove global headers sent with all requests, except for the role header to preserve * the role set by 'setRole' method. * * @example * ```ts * nhost.graphql.unsetHeaders() * ``` * * @docs https://docs.nhost.io/reference/javascript/graphql/unset-headers */ unsetHeaders(): void; private generateAccessTokenHeaders; } //# sourceMappingURL=client.d.ts.map