nextjs-hasura-auth 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/APOLLO.md CHANGED
@@ -1,174 +1,101 @@
1
- # Apollo Client Setup (`APOLLO.md`)
2
-
3
- This document describes the configured Apollo Client instance provided by this package (`lib/apollo.tsx` or similar) for interacting with your Hasura GraphQL API.
4
-
5
- ## Purpose
6
-
7
- The Apollo Client setup provides a unified interface for sending GraphQL queries, mutations, and subscriptions to Hasura, automatically handling authentication based on the provided JWT token or Hasura Admin Secret.
8
-
9
- ## Key Features
10
-
11
- * **Direct Connection:** Connects directly to your Hasura GraphQL endpoint (`NEXT_PUBLIC_HASURA_GRAPHQL_URL`) for HTTP requests and WebSocket endpoint (`NEXT_PUBLIC_HASURA_WS_ENDPOINT` derived from the HTTP URL) for subscriptions.
12
- * **Split Link:** Intelligently routes GraphQL operations:
13
- * **HTTP Requests (Queries/Mutations):** Sent via standard HTTP.
14
- * **WebSocket Connections (Subscriptions):** Uses a WebSocket connection (`graphql-ws`). This requires `ws: true` during client creation and only works client-side.
15
- * **Flexible Authentication:**
16
- * **JWT Token Priority:** If a `token` is provided during client creation, it's sent as a `Bearer` token in the `Authorization` header (for both HTTP and WS).
17
- * **Admin Secret Fallback:** If no `token` is provided, but the `HASURA_ADMIN_SECRET` environment variable is set (or a `secret` is passed explicitly), it's sent in the `x-hasura-admin-secret` header (for both HTTP and WS).
18
- * **Public Access:** If neither a token nor a secret is available, requests are sent without authentication headers.
19
- * **Server-Side Rendering (SSR) / Client-Side Rendering (CSR) Compatibility:** The client can be created and used both on the server and the client.
20
- * **Convenient Provider:** The `createClient` function returns an enhanced client instance that includes a `.Provider` component (`ApolloClientWithProvider`) for easily wrapping parts of your React application.
21
- * **Helper Hook:** Provides `useCreateApolloClient` hook for easily creating memoized client instances in React components, especially useful for integrating with authentication state.
22
-
23
- <details>
24
- <summary>Core Exports & Options (`lib/apollo.tsx`)</summary>
25
-
26
- * `createClient(options: ApolloOptions): ApolloClientWithProvider`: Creates a new Apollo Client instance.
27
- * `options.url`: Hasura GraphQL endpoint URL (defaults to `process.env.NEXT_PUBLIC_HASURA_GRAPHQL_URL`).
28
- * `options.ws`: Boolean, enable WebSocket link for subscriptions (defaults to `false`, only works client-side).
29
- * `options.token`: String, JWT token for Bearer authentication.
30
- * `options.secret`: String, Hasura Admin Secret (defaults to `process.env.HASURA_ADMIN_SECRET`).
31
- * `useCreateApolloClient(options: ApolloOptions): ApolloClientWithProvider`: React hook to create a memoized Apollo Client instance. Recreates the client if `options` change.
32
- * `getClient(options?: ApolloOptions): ApolloClient<any>`: Gets or creates a singleton Apollo Client instance. *Note: Using the singleton pattern might be tricky if the authentication token needs to change dynamically. `useCreateApolloClient` is often preferred in React components.*
33
- * `checkConnection(client?): Promise<boolean>`: Sends a simple introspection query to check connectivity to the Hasura endpoint.
34
- * `getJwtSecret(): Uint8Array`: Utility to get the Hasura JWT secret key from `process.env.HASURA_JWT_SECRET` (used internally by other parts of the auth system, not typically needed directly for Apollo client setup).
35
-
36
- </details>
37
-
38
- ## Usage
39
-
40
- ### Client-Side (React Components - Recommended)
41
-
42
- 1. **Ensure `SessionProvider` is set up:** The Apollo client often relies on session data (like a JWT) for authentication. Make sure `next-auth/react`'s `SessionProvider` wraps your application, usually in the root layout.
43
- 2. **Wrap your application/layout with the client's Provider:** Use the `useCreateApolloClient` hook to create a client instance based on the session state and wrap your components using `client.Provider`.
44
-
45
- ```typescript
46
- // Example in app/layout.tsx
47
- 'use client'; // Layout needs to be client-side for providers and hooks
48
-
49
- import { SessionProvider, useSession } from "next-auth/react";
50
- import { useCreateApolloClient } from '@/lib/apollo'; // Adjust path
51
- import { useMemo } from "react";
52
- // Other imports (ThemeProvider, etc.)
53
-
54
- // Wrapper component to manage Apollo client based on session
55
- function ApolloWrapper({ children }: { children: React.ReactNode }) {
56
- const { data: session } = useSession(); // Get session from next-auth
57
-
58
- // Create Apollo Client, passing the Hasura JWT from the session
59
- // The client will be recreated if the session changes
60
- const client = useCreateApolloClient(useMemo(() => ({
61
- // Make sure your next-auth session callback adds the correct
62
- // Hasura-compatible JWT to the session object (e.g., session.accessToken)
63
- token: session?.accessToken, // Pass the Hasura JWT
64
- ws: true // Enable WebSocket support for subscriptions
65
- }), [session]));
66
-
67
- // Use the convenient Provider attached to the client instance
68
- return (
69
- <client.Provider>
70
- {children}
71
- </client.Provider>
72
- );
73
- }
74
-
75
- export default function RootLayout({ children }: { children: React.ReactNode }) {
76
- return (
77
- <html lang="en" suppressHydrationWarning>
78
- <head />
79
- <body>
80
- {/* SessionProvider is required for useSession hook */}
81
- <SessionProvider>
82
- {/* ApolloWrapper provides the Apollo client based on session */}
83
- <ApolloWrapper>
84
- {/* Other providers like ThemeProvider */}
85
- {/* <ThemeProvider ...> */}
86
- {children}
87
- {/* </ThemeProvider> */}
88
- </ApolloWrapper>
89
- </SessionProvider>
90
- </body>
91
- </html>
92
- );
93
- }
94
- ```
95
-
96
- 3. **Use Apollo Hooks in Components:** Import and use hooks like `useQuery`, `useMutation`, or `useSubscription` directly. The client provided by the context will handle authentication automatically based on the token passed during its creation.
97
-
98
- ```typescript
99
- import { useQuery, gql } from '@apollo/client';
100
- // import { Generator } from 'nextjs-hasura-auth'; // Optional: Use with Generator
101
-
102
- function UserProfile() {
103
- // Assume user ID is available, e.g., from session or props
104
- const userId = '...';
105
-
106
- const GET_USER = gql`
107
- query GetUser($userId: uuid!) {
108
- users_by_pk(id: $userId) {
109
- id
110
- name
111
- email
112
- }
113
- }
114
- `;
115
-
116
- // The client from ApolloWrapper's context is used automatically
117
- const { loading, error, data } = useQuery(GET_USER, {
118
- variables: { userId }
119
- });
120
-
121
- // ... render logic ...
122
- }
123
- ```
124
-
125
- ### Server-Side (SSR/SSG/Server Components/API Routes)
126
-
127
- 1. **Create Client Instance:** Use `createClient` directly. You need to decide how to authenticate:
128
- * **Admin Access:** Pass the admin secret (e.g., from environment variables) using the `secret` option if you need privileged access.
129
- * **User Access:** If running in the context of a specific user request, obtain their Hasura JWT (e.g., from session data, request headers) and pass it using the `token` option.
130
-
131
- ```typescript
132
- // Example in an API Route or Server Component
133
- import { createClient } from '@/lib/apollo'; // Adjust path
134
- import { gql } from '@apollo/client';
135
- // import { getToken } from "next-auth/jwt"
136
-
137
- async function getUserDataOnServer(userId: string, request?: Request) {
138
- // Option 1: Use Admin Secret for privileged access
139
- // const client = createClient({
140
- // secret: process.env.HASURA_ADMIN_SECRET // Ensure secret is available server-side
141
- // });
142
-
143
- // Option 2: Use User Token (if available from request/session)
144
- // Example: const sessionToken = await getToken({ req: request, secret: process.env.NEXTAUTH_SECRET });
145
- // const hasuraToken = sessionToken?.accessToken;
146
- const client = createClient({
147
- token: process.env.SOME_SERVICE_ACCOUNT_TOKEN_IF_NEEDED // Or fetch user token if applicable
148
- // url: process.env.NEXT_PUBLIC_HASURA_GRAPHQL_URL // URL can also be passed explicitly
149
- });
150
-
151
- const GET_USER = gql`...`; // Your query
152
-
153
- try {
154
- const { data } = await client.query({
155
- query: GET_USER,
156
- variables: { userId },
157
- // Important for server-side: Avoid using client-side cache
158
- fetchPolicy: 'network-only',
159
- });
160
- return data.users_by_pk;
161
- } catch (error) {
162
- console.error('Error fetching user data:', error);
163
- return null;
164
- }
165
- }
166
- ```
167
-
168
- 2. **Fetch Data:** Use `client.query(...)` or `client.mutate(...)`.
169
-
170
- ## Important Considerations
171
-
172
- * **JWT Token:** Ensure your authentication system (like `next-auth`) generates a Hasura-compatible JWT containing the necessary `https://hasura.io/jwt/claims` and includes it in the session data (e.g., as `session.accessToken`) for the client-side integration to work.
173
- * **Environment Variables:** Securely manage `HASURA_ADMIN_SECRET`, `NEXTAUTH_SECRET`, and potentially `HASURA_JWT_SECRET` using environment variable configuration in your hosting provider (e.g., Vercel). `NEXT_PUBLIC_HASURA_GRAPHQL_URL` needs to be accessible client-side.
174
- * **WebSocket Security:** WebSocket connections initiated from the client include the token/secret directly in the `connectionParams`. Ensure your Hasura endpoint is properly secured (e.g., using HTTPS/WSS).
1
+ # Apollo Client Setup (`lib/apollo.tsx`)
2
+
3
+ This file provides the `useCreateApolloClient` hook, a crucial part of the library for interacting with your Hasura GraphQL backend.
4
+
5
+ ## `useCreateApolloClient` Hook
6
+
7
+ A React hook to create and memoize an Apollo Client instance configured for the Hasura backend.
8
+
9
+ ```tsx
10
+ import { useCreateApolloClient } from 'nextjs-hasura-auth';
11
+
12
+ function MyComponent() {
13
+ // Create client for HTTP only
14
+ const apolloClientHttp = useCreateApolloClient({ token: 'your-auth-token' });
15
+
16
+ // Create client for HTTP and WebSocket (subscriptions)
17
+ const apolloClientWs = useCreateApolloClient({ token: 'your-auth-token', ws: true });
18
+
19
+ // ... use apolloClient
20
+ }
21
+ ```
22
+
23
+ ### Purpose
24
+
25
+ This hook simplifies the setup of an Apollo Client tailored for Hasura environments, handling both HTTP and WebSocket connections, authentication headers, and role management.
26
+
27
+ ### Arguments
28
+
29
+ - `options` (object):
30
+ - `token` (string | undefined): Optional authentication token (JWT) to be included in headers.
31
+ - `ws` (boolean): Optional flag (default: `false`) to enable WebSocket connection for subscriptions.
32
+
33
+ ### Return Value
34
+
35
+ - `ApolloClient<NormalizedCacheObject>`: An initialized and memoized Apollo Client instance.
36
+
37
+ ### Key Features
38
+
39
+ 1. **HTTP Link (`httpLink`)**: Configured for standard GraphQL operations (queries, mutations) using `createHttpLink`.
40
+ 2. **WebSocket Link (`wsLink`)**: Configured for GraphQL subscriptions using `graphql-ws`. Enabled only if `ws: true` is passed in the options. It uses `createClient` from `graphql-ws`.
41
+ 3. **Role Link (`roleLink`)**: **New!** This is an `ApolloLink` middleware using `setContext` that intercepts outgoing **HTTP requests**. It checks the `context` object passed to the Apollo operation (e.g., in `useQuery`, `useMutation`). If a `role` property is found in the operation's context, it adds the `X-Hasura-Role` header to the HTTP request with the specified role.
42
+ * **Important Note:** This dynamic role setting via context currently **only works for HTTP requests** (queries and mutations). It **does not** dynamically set the role for WebSocket connections (subscriptions). For subscriptions, the role is determined by the `connectionParams` when the WebSocket connection is established, which typically uses the `token` provided to `useCreateApolloClient` to infer the role on the backend.
43
+ 4. **Authentication Headers**:
44
+ * For HTTP requests, it automatically includes `Authorization: Bearer <token>` (if provided) and `X-Hasura-Admin-Secret` (if `process.env.HASURA_ADMIN_SECRET` is set). The `roleLink` adds the `X-Hasura-Role` header if a `role` is provided in the operation's context.
45
+ * For WebSocket connections, `connectionParams` are set with `headers` containing `Authorization` and `X-Hasura-Admin-Secret`.
46
+ 5. **Request Splitting**: Uses `split` to direct operations to `httpLink` (via `roleLink` and `authLink`) or `wsLink` based on the operation type. Subscriptions go to `wsLink` (if `ws: true`), others go to `httpLink`.
47
+ 6. **Error Handling (`errorLink`)**: Includes basic error logging for GraphQL and network errors using `onError`.
48
+ 7. **Caching**: Uses `InMemoryCache` for client-side caching.
49
+ 8. **Memoization**: The `useMemo` hook ensures the client instance is created only once per component lifecycle or when the `token` or `ws` options change, preventing unnecessary client recreations.
50
+
51
+ ### How `roleLink` Works
52
+
53
+ The `roleLink` leverages Apollo Link's `setContext` middleware.
54
+
55
+ ```typescript
56
+ // Simplified logic within useCreateApolloClient
57
+ import { setContext } from '@apollo/client/link/context';
58
+
59
+ const roleLink = setContext((_operation, context) => {
60
+ // context here is the *link* context, which includes headers etc.
61
+ // and importantly, the context passed from the hook/operation call.
62
+ const operationContext = context?.graphqlContext || {}; // Access context passed from useQuery/useMutation etc.
63
+ const role = operationContext.role; // Get the role from the operation's context
64
+
65
+ // If a role is provided in the operation's context, add it to the headers
66
+ if (role) {
67
+ return {
68
+ headers: {
69
+ ...context.headers, // Preserve existing headers (like Authorization)
70
+ 'X-Hasura-Role': role,
71
+ },
72
+ };
73
+ }
74
+
75
+ // Otherwise, return the existing headers unchanged
76
+ return {
77
+ headers: context.headers,
78
+ };
79
+ });
80
+
81
+ // This roleLink is then chained before the httpLink:
82
+ // link: from([errorLink, roleLink, authLink, httpLink]) // for HTTP
83
+ ```
84
+
85
+ When you use the data fetching hooks from `lib/client.tsx` (like `useQuery`, `useMutation`) and pass a `role` in the `hookOptions`, that `role` becomes part of the operation's context (`graphqlContext`), which `roleLink` then reads to set the appropriate `X-Hasura-Role` header for that specific HTTP request.
86
+
87
+ ```tsx
88
+ // Example using useQuery with a role
89
+ const { data } = useQuery(GET_POSTS, {
90
+ hookOptions: {
91
+ // These options are passed to Apollo's useQuery
92
+ variables: { limit: 10 },
93
+ // This context object is passed along the link chain
94
+ context: {
95
+ role: 'editor', // roleLink will pick this up
96
+ },
97
+ },
98
+ });
99
+ ```
100
+
101
+ This allows for fine-grained role control on a per-operation basis for queries and mutations. Remember, WebSocket subscriptions rely on the role established during the initial connection based on the token.
package/GENERATOR.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Purpose
4
4
 
5
- This document describes the `Generator` function located in `lib/generator.ts`. Its purpose is to dynamically generate GraphQL query strings, `DocumentNode` objects (compatible with Apollo Client), and corresponding variables based on a provided set of options and a Hasura-like schema (`schema.json`). This simplifies the process of constructing GraphQL operations (queries, mutations, subscriptions) within the application.
5
+ This document describes the `Generator` function located in `lib/generator.ts`. Its purpose is to dynamically generate GraphQL query strings, `DocumentNode` objects (compatible with Apollo Client), and corresponding variables based on a provided set of options and a Hasura-like schema (`public/hasura-schema.json`). This simplifies the process of constructing GraphQL operations (queries, mutations, subscriptions) within the application.
6
6
 
7
7
  ## Usage
8
8
 
@@ -14,11 +14,10 @@ This document describes the `Generator` function located in `lib/generator.ts`.
14
14
  // Assuming 'nextjs-hasura-auth' is your published package name
15
15
  import { Generator, GenerateOptions, GenerateResult } from 'nextjs-hasura-auth';
16
16
  // Assuming schema is correctly loaded (you might need to handle schema loading differently when using the package)
17
- // import schema from './schema.json';
17
+ import schema from './public/hasura-schema.json';
18
18
 
19
19
  // Initialize the generator (Schema needs to be passed)
20
- // const generate = Generator(schema);
21
- // TODO: Document how schema should be provided when using the package
20
+ const generate = Generator(schema);
22
21
 
23
22
  // Define options for your query
24
23
  const options: GenerateOptions = {
@@ -77,7 +76,7 @@ The `generate` function accepts an object with the following properties:
77
76
 
78
77
  ## Examples
79
78
 
80
- *(Note: Variable types like `users_bool_exp`, `[users_order_by!]`, `uuid!`, `users_pk_columns_input!`, `users_set_input!`, `[users_insert_input!]!` are inferred based on schema structure and conventions. Ensure your `schema.json` reflects the actual types used by Hasura.)*
79
+ *(Note: Variable types like `users_bool_exp`, `[users_order_by!]`, `uuid!`, `users_pk_columns_input!`, `users_set_input!`, `[users_insert_input!]!` are inferred based on schema structure and conventions. Ensure your `public/hasura-schema.json` reflects the actual types used by Hasura.)*
81
80
 
82
81
  **Navigation**
83
82
 
package/README.md CHANGED
@@ -4,6 +4,7 @@ This project provides a robust starting point for building applications using Ne
4
4
 
5
5
  [![Generator Documentation](https://img.shields.io/badge/Generator%20Docs-MD-blue)](GENERATOR.md) [![Apollo Client Documentation](https://img.shields.io/badge/Apollo%20Client%20Docs-MD-orange)](APOLLO.md)
6
6
  [![Authentication Helpers Documentation](https://img.shields.io/badge/Auth%20Helpers%20Docs-MD-green)](AUTH.md) [![Hasura Admin Client Documentation](https://img.shields.io/badge/Hasura%20Client%20Docs-MD-purple)](HASURA.md)
7
+ [![Generated Client Documentation](https://img.shields.io/badge/Generated%20Client%20Docs-MD-cyan)](CLIENT.md)
7
8
 
8
9
  See [`GENERATOR.md`](GENERATOR.md) for detailed documentation on the dynamic GraphQL query generator, which simplifies creating queries, mutations, and subscriptions based on your Hasura schema.
9
10
 
@@ -13,6 +14,8 @@ See [`AUTH.md`](AUTH.md) for documentation on WebSocket and request authenticati
13
14
 
14
15
  See [`HASURA.md`](HASURA.md) for details on the Hasura Admin API client used for migrations.
15
16
 
17
+ See [`CLIENT.md`](CLIENT.md) for details on the `Client` class and React hooks that combine the Generator and Apollo Client for easy data operations.
18
+
16
19
  ## ✨ Features Checklist
17
20
 
18
21
  **Implemented:**
@@ -22,16 +25,17 @@ See [`HASURA.md`](HASURA.md) for details on the Hasura Admin API client used for
22
25
  * [x] **Unified Apollo Client:** A configured Apollo Client instance handles both authenticated HTTP requests (via the proxy) and direct, authenticated WebSocket connections for subscriptions.
23
26
  * [x] **Dynamic Query Generator:** A versatile query generator (`lib/generator.ts`) allows dynamic creation of GraphQL operations based on options and schema, suitable for client/server use.
24
27
  * [x] **WebSocket Authentication:** Real-time subscriptions connect directly to Hasura via WebSockets, authenticated using the user's session JWT.
28
+ * [x] **Generated Client Wrapper:** A `Client` class and associated React hooks (`useQuery`, `useSubscription`) that combine the Generator and Apollo Client for simplified data fetching and mutations (`lib/client.tsx`).
25
29
 
26
30
  **Planned / Future Ideas:**
27
31
 
28
- * [ ] **Convenience Hooks:** Create easy-to-use React hooks (`useQuery`, `useSubscription`, potentially a `useCRUD` hook/class) that integrate the `Generator` with Apollo Client for streamlined data fetching in components.
32
+ * [ ] **Advanced Convenience Hooks:** Potentially create a more advanced `useCRUD` hook/class built on top of the existing `Client` or hooks for even more streamlined common CRUD operations in components.
29
33
  * [ ] **Multi-Platform Builds:** Native builders for Android, iOS, MacOS, Windows, Linux, Oculus (e.g., using Tauri, Capacitor, or Electron).
30
34
  * [ ] **Unique Environment Builders:** Specific builds for Chrome Extensions, Firefox Extensions, and VSCode Extensions (including custom UI elements).
31
35
  * [ ] Additional Authentication Providers (OAuth: Google, GitHub, etc.).
32
36
  * [ ] Role-based access control examples.
33
37
  * [ ] Advanced caching strategies.
34
- * [ ] Comprehensive end-to-end testing setup.
38
+ * [ ] Comprehensive end-to-end testing setup for UI and hooks.
35
39
 
36
40
  ## 🚀 Core Concepts
37
41
 
@@ -67,7 +71,7 @@ Interaction with the Hasura GraphQL Engine is handled in two primary ways:
67
71
 
68
72
  ### 4. Dynamic Query Generation (`GENERATOR.md`)
69
73
 
70
- * The core `Generator` function in `lib/generator.ts` allows you to build complex GraphQL operations dynamically based on a simple options object and your `schema.json`.
74
+ * The core `Generator` function in `lib/generator.ts` allows you to build complex GraphQL operations dynamically based on a simple options object and your `public/hasura-schema.json`.
71
75
  * This avoids writing lengthy GraphQL query strings manually.
72
76
  * See [`GENERATOR.md`](GENERATOR.md) for full usage details and examples.
73
77
  * *Convenience hooks (like `useQuery`, `useSubscription`, `useCRUD`) are planned to further simplify using the generator within React components.*
@@ -89,10 +93,10 @@ Interaction with the Hasura GraphQL Engine is handled in two primary ways:
89
93
  │ ├── debug.ts # Debug utility
90
94
  │ └── ...
91
95
  ├── public/ # Static assets
96
+ │ ├── hasura-schema.json # Hasura GraphQL schema (for Generator)
92
97
  ├── styles/ # Global styles
93
98
  ├── .env # Environment variables (Gitignored)
94
99
  ├── GENERATOR.md # Query Generator Documentation
95
- ├── schema.json # Hasura GraphQL schema (for Generator)
96
100
  ├── next.config.js # Next.js configuration
97
101
  ├── package.json # Project dependencies and scripts
98
102
  └── tsconfig.json # TypeScript configuration
@@ -159,7 +163,7 @@ Interaction with the Hasura GraphQL Engine is handled in two primary ways:
159
163
  * Ensure `NEXTAUTH_URL` points to your application's base URL.
160
164
 
161
165
  4. **Update Hasura Schema:**
162
- Make sure the `schema.json` file in the root is up-to-date with your Hasura instance's schema. You might need to fetch this from Hasura if you've made changes.
166
+ Make sure the `public/hasura-schema.json` file in the root is up-to-date with your Hasura instance's schema. You might need to fetch this from Hasura if you've made changes.
163
167
 
164
168
  5. **Run the development server:**
165
169
  ```bash
@@ -1,15 +1,15 @@
1
1
  import { ApolloClient } from '@apollo/client';
2
- /**
3
- * Get JWT secret from environment variables
4
- * @returns {Uint8Array} Secret key for JWT signing
5
- */
6
- export declare const getJwtSecret: () => Uint8Array;
7
- interface ApolloOptions {
2
+ export interface ApolloOptions {
8
3
  url?: string;
9
4
  ws?: boolean;
10
5
  token?: string;
11
6
  secret?: string;
12
7
  }
8
+ export interface ApolloClientWithProvider extends ApolloClient<any> {
9
+ Provider: React.ComponentType<{
10
+ children: React.ReactNode;
11
+ }>;
12
+ }
13
13
  /**
14
14
  * Create Apollo Client
15
15
  *
@@ -19,7 +19,7 @@ interface ApolloOptions {
19
19
  * @param {string} options.secret - Admin secret for Hasura
20
20
  * @returns {ApolloClient} Apollo Client
21
21
  */
22
- export declare function createClient(options?: ApolloOptions): ApolloClient<import("@apollo/client").NormalizedCacheObject>;
22
+ export declare function createApolloClient(options?: ApolloOptions): ApolloClientWithProvider;
23
23
  /**
24
24
  * Get or create Apollo client instance
25
25
  * @param options Client options
@@ -30,14 +30,16 @@ export declare function getClient(options?: {}): ApolloClient<any>;
30
30
  * React hook to get Apollo client instance
31
31
  * @returns Apollo client instance
32
32
  */
33
- export declare function useClient(options: ApolloOptions): ApolloClient<import("@apollo/client").NormalizedCacheObject>;
33
+ export declare function useCreateApolloClient(options: ApolloOptions): ApolloClientWithProvider;
34
+ export declare const CHECK_CONNECTION_SUBSCRIPTION: import("@apollo/client").DocumentNode;
35
+ export declare const CHECK_CONNECTION_QUERY: import("@apollo/client").DocumentNode;
34
36
  /**
35
37
  * Check connection to Hasura GraphQL endpoint
36
38
  * @returns {Promise<boolean>} True if connection is successful
37
39
  */
38
40
  export declare function checkConnection(client?: ApolloClient<any>): Promise<boolean>;
39
41
  declare const _default: {
40
- createClient: typeof createClient;
42
+ createApolloClient: typeof createApolloClient;
41
43
  getClient: typeof getClient;
42
44
  getJwtSecret: () => Uint8Array;
43
45
  checkConnection: typeof checkConnection;