@vrplatform/graphql 1.0.4 → 1.0.6

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.
Files changed (55) hide show
  1. package/build/main/create-client.d.ts +3 -8
  2. package/build/main/create-client.js +16 -33
  3. package/build/main/index.d.ts +14 -3
  4. package/build/main/index.js +74 -5
  5. package/build/main/tsconfig.main.tsbuildinfo +1 -1
  6. package/build/main/types.d.ts +0 -2
  7. package/build/module/create-client.d.ts +3 -8
  8. package/build/module/create-client.js +13 -27
  9. package/build/module/index.d.ts +14 -3
  10. package/build/module/index.js +72 -3
  11. package/build/module/tsconfig.esm.tsbuildinfo +1 -1
  12. package/build/module/types.d.ts +0 -2
  13. package/package.json +1 -1
  14. package/src/create-client.ts +3 -5
  15. package/src/index.ts +3 -1
  16. package/build/main/create-client-v2.d.ts +0 -11
  17. package/build/main/create-client-v2.js +0 -79
  18. package/build/main/dotenv.d.ts +0 -1
  19. package/build/main/dotenv.js +0 -6
  20. package/build/main/src/constants.d.ts +0 -2
  21. package/build/main/src/constants.js +0 -5
  22. package/build/main/src/create-client.d.ts +0 -7
  23. package/build/main/src/create-client.js +0 -105
  24. package/build/main/src/gqty/index.d.ts +0 -1
  25. package/build/main/src/gqty/index.js +0 -17
  26. package/build/main/src/gqty/schema.generated.d.ts +0 -147429
  27. package/build/main/src/gqty/schema.generated.js +0 -47182
  28. package/build/main/src/index.d.ts +0 -14
  29. package/build/main/src/index.js +0 -93
  30. package/build/main/src/index.spec.d.ts +0 -1
  31. package/build/main/src/index.spec.js +0 -12
  32. package/build/main/src/types.d.ts +0 -16
  33. package/build/main/src/types.js +0 -2
  34. package/build/main/wrap.d.ts +0 -10
  35. package/build/main/wrap.js +0 -70
  36. package/build/module/create-client-v2.d.ts +0 -11
  37. package/build/module/create-client-v2.js +0 -72
  38. package/build/module/dotenv.d.ts +0 -1
  39. package/build/module/dotenv.js +0 -3
  40. package/build/module/src/constants.d.ts +0 -2
  41. package/build/module/src/constants.js +0 -2
  42. package/build/module/src/create-client.d.ts +0 -7
  43. package/build/module/src/create-client.js +0 -102
  44. package/build/module/src/gqty/index.d.ts +0 -1
  45. package/build/module/src/gqty/index.js +0 -1
  46. package/build/module/src/gqty/schema.generated.d.ts +0 -147429
  47. package/build/module/src/gqty/schema.generated.js +0 -47179
  48. package/build/module/src/index.d.ts +0 -14
  49. package/build/module/src/index.js +0 -73
  50. package/build/module/src/index.spec.d.ts +0 -1
  51. package/build/module/src/index.spec.js +0 -10
  52. package/build/module/src/types.d.ts +0 -16
  53. package/build/module/src/types.js +0 -1
  54. package/build/module/wrap.d.ts +0 -10
  55. package/build/module/wrap.js +0 -67
@@ -1,11 +1,6 @@
1
- import { type GQtyClient } from 'gqty';
2
1
  import { type GeneratedSchema } from './gqty';
3
2
  import type { GqlAuthParam } from './types';
4
- export type HasuraClient = ReturnType<typeof useHasuraClient>;
5
- export declare function useHasuraClient(args?: GqlAuthParam): {
6
- client: GQtyClient<GeneratedSchema>;
7
- subscriptionsClient: import("gqty").LegacySubscriptionsClient;
8
- mutate<T = unknown>(resolved: (sub: import("./gqty").Mutation) => T, options?: import("./wrap").ResolveOptionsWithSession<T>): Promise<T>;
9
- query<T = unknown>(resolved: (sub: import("./gqty").Query) => T, options?: import("./wrap").ResolveOptionsWithSession<T>): Promise<T>;
10
- subscribe<T = unknown>(resolved: (sub: import("./gqty").Subscription) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
3
+ export declare function useHasuraClientInner(args?: Omit<GqlAuthParam, 'retries'>): {
4
+ subscriptionsClient: import("graphql-ws").Client;
5
+ client: import("gqty").GQtyClient<GeneratedSchema>;
11
6
  };
@@ -1,18 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useHasuraClient = useHasuraClient;
7
- const subscriptions_1 = require("@gqty/subscriptions");
8
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
3
+ exports.useHasuraClientInner = useHasuraClientInner;
4
+ // import fetch from 'cross-fetch';
9
5
  const gqty_1 = require("gqty");
6
+ const graphql_ws_1 = require("graphql-ws");
10
7
  const constants_1 = require("./constants");
11
8
  const gqty_2 = require("./gqty");
12
- const wrap_1 = require("./wrap");
13
- function useHasuraClient(args) {
9
+ function useHasuraClientInner(args) {
14
10
  const $headers = args && 'headers' in args ? args.headers : undefined;
15
- const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || cross_fetch_1.default;
11
+ const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || fetch;
16
12
  const uri = args?.uri || constants_1.hasuraGraphqlUri;
17
13
  const getHeaders = async (base) => {
18
14
  const headers = ($headers && typeof $headers === 'function'
@@ -41,10 +37,12 @@ function useHasuraClient(args) {
41
37
  }
42
38
  }
43
39
  // Modify "https://finalytic.hasura.app/v1/graphql" if needed
44
- const response = await (0, cross_fetch_1.default)('https://finalytic.hasura.app/v1/graphql', {
40
+ const response = await $fetch('https://finalytic.hasura.app/v1/graphql', {
41
+ ...fetchOptions,
45
42
  method: 'POST',
46
43
  headers: {
47
44
  'Content-Type': 'application/json',
45
+ ...headers,
48
46
  },
49
47
  body: JSON.stringify({
50
48
  query,
@@ -52,20 +50,18 @@ function useHasuraClient(args) {
52
50
  operationName,
53
51
  }),
54
52
  mode: 'cors',
55
- ...fetchOptions,
56
53
  });
57
- const json = await response.json();
58
- return await (0, gqty_1.defaultResponseHandler)(json);
54
+ return await (0, gqty_1.defaultResponseHandler)(response);
59
55
  };
60
56
  const subscriptionsClient = args?.subscriptions === true
61
- ? (0, subscriptions_1.createSubscriptionsClient)({
57
+ ? (0, graphql_ws_1.createClient)({
62
58
  lazy: true,
63
- connectionInitPayload: async () => ({
59
+ connectionParams: async () => ({
64
60
  headers: await getHeaders({
65
61
  [constants_1.hasuraQueryTypeHeader]: 'subscription',
66
62
  }),
67
63
  }),
68
- wsEndpoint() {
64
+ url() {
69
65
  const wsUrl = new URL(uri);
70
66
  wsUrl.protocol = wsUrl.protocol
71
67
  .replace('https', 'wss')
@@ -76,28 +72,15 @@ function useHasuraClient(args) {
76
72
  },*/
77
73
  })
78
74
  : undefined;
79
- /*const subscriptionsClient = (() => {
80
- if (args?.subscriptions === false) return;
81
- const wsUrl = new URL(uri);
82
- wsUrl.protocol = wsUrl.protocol
83
- .replace('https', 'wss')
84
- .replace('http', 'ws');
85
- const subscriptionsClient: SubscriptionsClient = createSubscriptionsClient({
86
- wsEndpoint: wsUrl.href,
87
- connectionInitPayload: async () => ({
88
- headers: await getHeaders({ [hasuraQueryTypeHeader]: 'subscription' }),
89
- }),
90
- });
91
- return subscriptionsClient;
92
- })();*/
93
75
  const cache = new gqty_1.Cache(undefined, {
94
76
  maxAge: 0,
95
- staleWhileRevalidate: 5 * 60 * 1000,
96
- normalization: true,
77
+ staleWhileRevalidate: 0,
78
+ normalization: false,
97
79
  });
98
80
  const client = (0, gqty_1.createClient)({
99
81
  schema: gqty_2.generatedSchema,
100
82
  scalars: gqty_2.scalarsEnumsHash,
83
+ //cache,
101
84
  cache,
102
85
  fetchOptions: {
103
86
  fetcher: queryFetcher,
@@ -118,5 +101,5 @@ function useHasuraClient(args) {
118
101
  },
119
102
  ...args,
120
103
  });*/
121
- return (0, wrap_1.wrapGraphQLClient)(client, subscriptionsClient, args?.onError, args?.retries);
104
+ return { subscriptionsClient, client };
122
105
  }
@@ -1,4 +1,15 @@
1
- export { type ResolveOptionsWithSession, wrapGraphQLClient } from './wrap';
2
- export { type HasuraClient, useHasuraClient } from './create-client';
1
+ export { useHasuraClientInner } from './create-client';
3
2
  export * from './gqty';
4
- export { GQtyClient, LegacySubscriptionsClient as SubscriptionsClient, LegacyResolveOptions as ResolveOptions, GQtyError, } from 'gqty';
3
+ export { GQtyError } from 'gqty';
4
+ import type { LegacyResolveOptions } from 'gqty';
5
+ import type { Mutation, Query, Subscription } from './gqty';
6
+ import type { GqlAuthParam } from './types';
7
+ export type ResolveOptionsWithSession<T> = LegacyResolveOptions<T>;
8
+ export type HasuraClient = ReturnType<typeof useHasuraClient>;
9
+ export declare function useHasuraClient(args?: GqlAuthParam): {
10
+ client: import("gqty").GQtyClient<import("./gqty").GeneratedSchema>;
11
+ subscriptionsClient: import("graphql-ws").Client;
12
+ mutate<T = unknown>(resolved: (sub: Mutation) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
13
+ query<T = unknown>(resolved: (sub: Query) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
14
+ subscribe<T = unknown>(resolved: (sub: Subscription) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
15
+ };
@@ -14,11 +14,80 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.GQtyError = exports.useHasuraClient = exports.wrapGraphQLClient = void 0;
18
- var wrap_1 = require("./wrap");
19
- Object.defineProperty(exports, "wrapGraphQLClient", { enumerable: true, get: function () { return wrap_1.wrapGraphQLClient; } });
20
- var create_client_1 = require("./create-client");
21
- Object.defineProperty(exports, "useHasuraClient", { enumerable: true, get: function () { return create_client_1.useHasuraClient; } });
17
+ exports.GQtyError = exports.useHasuraClientInner = void 0;
18
+ exports.useHasuraClient = useHasuraClient;
19
+ const create_client_1 = require("./create-client");
20
+ var create_client_2 = require("./create-client");
21
+ Object.defineProperty(exports, "useHasuraClientInner", { enumerable: true, get: function () { return create_client_2.useHasuraClientInner; } });
22
22
  __exportStar(require("./gqty"), exports);
23
23
  var gqty_1 = require("gqty");
24
24
  Object.defineProperty(exports, "GQtyError", { enumerable: true, get: function () { return gqty_1.GQtyError; } });
25
+ function useHasuraClient(args) {
26
+ const { client, subscriptionsClient } = (0, create_client_1.useHasuraClientInner)(args);
27
+ const retries = args.retries || 3;
28
+ return {
29
+ client,
30
+ subscriptionsClient,
31
+ async mutate(resolved, options) {
32
+ if (!options)
33
+ options = {};
34
+ if (options.noCache === undefined)
35
+ options.noCache = true;
36
+ let err;
37
+ for (let tries = 1; tries <= retries; tries++) {
38
+ try {
39
+ const result = await client.resolve(({ mutation }) => resolved(mutation), options);
40
+ return result;
41
+ }
42
+ catch (error) {
43
+ err = error;
44
+ if (error.message !== 'database query error')
45
+ break;
46
+ await new Promise((resolve) => setTimeout(resolve, 1000 * tries + 1000));
47
+ }
48
+ }
49
+ if (args.onError)
50
+ throw args.onError(err) || err;
51
+ throw err;
52
+ },
53
+ async query(resolved, options) {
54
+ let err;
55
+ for (let tries = 1; tries <= retries; tries++) {
56
+ try {
57
+ const result = await client.resolve(({ query }) => resolved(query), options);
58
+ return result;
59
+ }
60
+ catch (error) {
61
+ err = error;
62
+ if (error.message !== 'database query error')
63
+ break;
64
+ await new Promise((resolve) => setTimeout(resolve, 1000 * tries + 1000));
65
+ }
66
+ }
67
+ if (args.onError)
68
+ throw args.onError(err) || err;
69
+ throw err;
70
+ },
71
+ subscribe(resolved, onData, onError) {
72
+ if (!subscriptionsClient)
73
+ throw new Error('Subscriptions not enabled');
74
+ let unsub;
75
+ const stop = async () => {
76
+ if (!unsub)
77
+ return;
78
+ await unsub().catch(() => undefined);
79
+ };
80
+ client.resolved(() => resolved(client.subscription), {
81
+ onSubscription(event) {
82
+ if (event.unsubscribe)
83
+ unsub = event.unsubscribe;
84
+ if (event.type === 'data')
85
+ onData(event.data, stop);
86
+ else if (event.type === 'with-errors' && onError)
87
+ onError(event.error, stop);
88
+ },
89
+ });
90
+ return stop;
91
+ },
92
+ };
93
+ }
@@ -1 +1 @@
1
- {"root":["../../src/constants.ts","../../src/create-client.ts","../../src/index.spec.ts","../../src/index.ts","../../src/types.ts","../../src/gqty/index.ts","../../src/gqty/schema.generated.d.ts","../../src/gqty/schema.generated.js"],"version":"5.6.3"}
1
+ {"root":["../../src/constants.ts","../../src/create-client.ts","../../src/index.ts","../../src/types.ts","../../src/gqty/index.ts","../../src/gqty/schema.generated.d.ts","../../src/gqty/schema.generated.js"],"version":"5.6.3"}
@@ -8,10 +8,8 @@ export type GqlAuthParam = {
8
8
  [s: string]: string;
9
9
  } | (() => Headers) | (() => Promise<Headers>);
10
10
  fetch?: any;
11
- normalization?: boolean;
12
11
  subscriptions?: boolean;
13
12
  uri?: string;
14
- cache?: boolean;
15
13
  onError?: (err: Error) => any;
16
14
  retries?: number;
17
15
  auditUserId?: string;
@@ -1,11 +1,6 @@
1
- import { type GQtyClient } from 'gqty';
2
1
  import { type GeneratedSchema } from './gqty';
3
2
  import type { GqlAuthParam } from './types';
4
- export type HasuraClient = ReturnType<typeof useHasuraClient>;
5
- export declare function useHasuraClient(args?: GqlAuthParam): {
6
- client: GQtyClient<GeneratedSchema>;
7
- subscriptionsClient: import("gqty").LegacySubscriptionsClient;
8
- mutate<T = unknown>(resolved: (sub: import("./gqty").Mutation) => T, options?: import("./wrap").ResolveOptionsWithSession<T>): Promise<T>;
9
- query<T = unknown>(resolved: (sub: import("./gqty").Query) => T, options?: import("./wrap").ResolveOptionsWithSession<T>): Promise<T>;
10
- subscribe<T = unknown>(resolved: (sub: import("./gqty").Subscription) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
3
+ export declare function useHasuraClientInner(args?: Omit<GqlAuthParam, 'retries'>): {
4
+ subscriptionsClient: import("graphql-ws").Client;
5
+ client: import("gqty").GQtyClient<GeneratedSchema>;
11
6
  };
@@ -1,10 +1,9 @@
1
- import { createSubscriptionsClient } from '@gqty/subscriptions';
2
- import fetch from 'cross-fetch';
1
+ // import fetch from 'cross-fetch';
3
2
  import { Cache, createClient, defaultResponseHandler, } from 'gqty';
3
+ import { createClient as createSubscriptionsClient } from 'graphql-ws';
4
4
  import { hasuraGraphqlUri, hasuraQueryTypeHeader } from './constants';
5
5
  import { generatedSchema, scalarsEnumsHash, } from './gqty';
6
- import { wrapGraphQLClient } from './wrap';
7
- export function useHasuraClient(args) {
6
+ export function useHasuraClientInner(args) {
8
7
  const $headers = args && 'headers' in args ? args.headers : undefined;
9
8
  const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || fetch;
10
9
  const uri = args?.uri || hasuraGraphqlUri;
@@ -35,10 +34,12 @@ export function useHasuraClient(args) {
35
34
  }
36
35
  }
37
36
  // Modify "https://finalytic.hasura.app/v1/graphql" if needed
38
- const response = await fetch('https://finalytic.hasura.app/v1/graphql', {
37
+ const response = await $fetch('https://finalytic.hasura.app/v1/graphql', {
38
+ ...fetchOptions,
39
39
  method: 'POST',
40
40
  headers: {
41
41
  'Content-Type': 'application/json',
42
+ ...headers,
42
43
  },
43
44
  body: JSON.stringify({
44
45
  query,
@@ -46,20 +47,18 @@ export function useHasuraClient(args) {
46
47
  operationName,
47
48
  }),
48
49
  mode: 'cors',
49
- ...fetchOptions,
50
50
  });
51
- const json = await response.json();
52
- return await defaultResponseHandler(json);
51
+ return await defaultResponseHandler(response);
53
52
  };
54
53
  const subscriptionsClient = args?.subscriptions === true
55
54
  ? createSubscriptionsClient({
56
55
  lazy: true,
57
- connectionInitPayload: async () => ({
56
+ connectionParams: async () => ({
58
57
  headers: await getHeaders({
59
58
  [hasuraQueryTypeHeader]: 'subscription',
60
59
  }),
61
60
  }),
62
- wsEndpoint() {
61
+ url() {
63
62
  const wsUrl = new URL(uri);
64
63
  wsUrl.protocol = wsUrl.protocol
65
64
  .replace('https', 'wss')
@@ -70,28 +69,15 @@ export function useHasuraClient(args) {
70
69
  },*/
71
70
  })
72
71
  : undefined;
73
- /*const subscriptionsClient = (() => {
74
- if (args?.subscriptions === false) return;
75
- const wsUrl = new URL(uri);
76
- wsUrl.protocol = wsUrl.protocol
77
- .replace('https', 'wss')
78
- .replace('http', 'ws');
79
- const subscriptionsClient: SubscriptionsClient = createSubscriptionsClient({
80
- wsEndpoint: wsUrl.href,
81
- connectionInitPayload: async () => ({
82
- headers: await getHeaders({ [hasuraQueryTypeHeader]: 'subscription' }),
83
- }),
84
- });
85
- return subscriptionsClient;
86
- })();*/
87
72
  const cache = new Cache(undefined, {
88
73
  maxAge: 0,
89
- staleWhileRevalidate: 5 * 60 * 1000,
90
- normalization: true,
74
+ staleWhileRevalidate: 0,
75
+ normalization: false,
91
76
  });
92
77
  const client = createClient({
93
78
  schema: generatedSchema,
94
79
  scalars: scalarsEnumsHash,
80
+ //cache,
95
81
  cache,
96
82
  fetchOptions: {
97
83
  fetcher: queryFetcher,
@@ -112,5 +98,5 @@ export function useHasuraClient(args) {
112
98
  },
113
99
  ...args,
114
100
  });*/
115
- return wrapGraphQLClient(client, subscriptionsClient, args?.onError, args?.retries);
101
+ return { subscriptionsClient, client };
116
102
  }
@@ -1,4 +1,15 @@
1
- export { type ResolveOptionsWithSession, wrapGraphQLClient } from './wrap';
2
- export { type HasuraClient, useHasuraClient } from './create-client';
1
+ export { useHasuraClientInner } from './create-client';
3
2
  export * from './gqty';
4
- export { GQtyClient, LegacySubscriptionsClient as SubscriptionsClient, LegacyResolveOptions as ResolveOptions, GQtyError, } from 'gqty';
3
+ export { GQtyError } from 'gqty';
4
+ import type { LegacyResolveOptions } from 'gqty';
5
+ import type { Mutation, Query, Subscription } from './gqty';
6
+ import type { GqlAuthParam } from './types';
7
+ export type ResolveOptionsWithSession<T> = LegacyResolveOptions<T>;
8
+ export type HasuraClient = ReturnType<typeof useHasuraClient>;
9
+ export declare function useHasuraClient(args?: GqlAuthParam): {
10
+ client: import("gqty").GQtyClient<import("./gqty").GeneratedSchema>;
11
+ subscriptionsClient: import("graphql-ws").Client;
12
+ mutate<T = unknown>(resolved: (sub: Mutation) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
13
+ query<T = unknown>(resolved: (sub: Query) => T, options?: ResolveOptionsWithSession<T>): Promise<T>;
14
+ subscribe<T = unknown>(resolved: (sub: Subscription) => T, onData: (data: T, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
15
+ };
@@ -1,4 +1,73 @@
1
- export { wrapGraphQLClient } from './wrap';
2
- export { useHasuraClient } from './create-client';
1
+ import { useHasuraClientInner } from './create-client';
2
+ export { useHasuraClientInner } from './create-client';
3
3
  export * from './gqty';
4
- export { GQtyError, } from 'gqty';
4
+ export { GQtyError } from 'gqty';
5
+ export function useHasuraClient(args) {
6
+ const { client, subscriptionsClient } = useHasuraClientInner(args);
7
+ const retries = args.retries || 3;
8
+ return {
9
+ client,
10
+ subscriptionsClient,
11
+ async mutate(resolved, options) {
12
+ if (!options)
13
+ options = {};
14
+ if (options.noCache === undefined)
15
+ options.noCache = true;
16
+ let err;
17
+ for (let tries = 1; tries <= retries; tries++) {
18
+ try {
19
+ const result = await client.resolve(({ mutation }) => resolved(mutation), options);
20
+ return result;
21
+ }
22
+ catch (error) {
23
+ err = error;
24
+ if (error.message !== 'database query error')
25
+ break;
26
+ await new Promise((resolve) => setTimeout(resolve, 1_000 * tries + 1_000));
27
+ }
28
+ }
29
+ if (args.onError)
30
+ throw args.onError(err) || err;
31
+ throw err;
32
+ },
33
+ async query(resolved, options) {
34
+ let err;
35
+ for (let tries = 1; tries <= retries; tries++) {
36
+ try {
37
+ const result = await client.resolve(({ query }) => resolved(query), options);
38
+ return result;
39
+ }
40
+ catch (error) {
41
+ err = error;
42
+ if (error.message !== 'database query error')
43
+ break;
44
+ await new Promise((resolve) => setTimeout(resolve, 1_000 * tries + 1_000));
45
+ }
46
+ }
47
+ if (args.onError)
48
+ throw args.onError(err) || err;
49
+ throw err;
50
+ },
51
+ subscribe(resolved, onData, onError) {
52
+ if (!subscriptionsClient)
53
+ throw new Error('Subscriptions not enabled');
54
+ let unsub;
55
+ const stop = async () => {
56
+ if (!unsub)
57
+ return;
58
+ await unsub().catch(() => undefined);
59
+ };
60
+ client.resolved(() => resolved(client.subscription), {
61
+ onSubscription(event) {
62
+ if (event.unsubscribe)
63
+ unsub = event.unsubscribe;
64
+ if (event.type === 'data')
65
+ onData(event.data, stop);
66
+ else if (event.type === 'with-errors' && onError)
67
+ onError(event.error, stop);
68
+ },
69
+ });
70
+ return stop;
71
+ },
72
+ };
73
+ }
@@ -1 +1 @@
1
- {"root":["../../src/constants.ts","../../src/create-client.ts","../../src/index.spec.ts","../../src/index.ts","../../src/types.ts","../../src/gqty/index.ts","../../src/gqty/schema.generated.d.ts","../../src/gqty/schema.generated.js"],"version":"5.6.3"}
1
+ {"root":["../../src/constants.ts","../../src/create-client.ts","../../src/index.ts","../../src/types.ts","../../src/gqty/index.ts","../../src/gqty/schema.generated.d.ts","../../src/gqty/schema.generated.js"],"version":"5.6.3"}
@@ -8,10 +8,8 @@ export type GqlAuthParam = {
8
8
  [s: string]: string;
9
9
  } | (() => Headers) | (() => Promise<Headers>);
10
10
  fetch?: any;
11
- normalization?: boolean;
12
11
  subscriptions?: boolean;
13
12
  uri?: string;
14
- cache?: boolean;
15
13
  onError?: (err: Error) => any;
16
14
  retries?: number;
17
15
  auditUserId?: string;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "!**/*.spec.*",
11
11
  "LICENSE"
12
12
  ],
13
- "version": "1.0.4",
13
+ "version": "1.0.6",
14
14
  "description": "Finalytic graphql",
15
15
  "main": "build/main/index.js",
16
16
  "module": "build/module/index.js",
@@ -1,4 +1,3 @@
1
- import { createSubscriptionsClient } from '@gqty/subscriptions';
2
1
  // import fetch from 'cross-fetch';
3
2
  import {
4
3
  Cache,
@@ -6,6 +5,7 @@ import {
6
5
  createClient,
7
6
  defaultResponseHandler,
8
7
  } from 'gqty';
8
+ import { createClient as createSubscriptionsClient } from 'graphql-ws';
9
9
  import { hasuraGraphqlUri, hasuraQueryTypeHeader } from './constants';
10
10
  import {
11
11
  type GeneratedSchema,
@@ -14,8 +14,6 @@ import {
14
14
  } from './gqty';
15
15
  import type { GqlAuthParam, Headers } from './types';
16
16
 
17
- export type HasuraClient = ReturnType<typeof useHasuraClientInner>;
18
-
19
17
  export function useHasuraClientInner(args?: Omit<GqlAuthParam, 'retries'>) {
20
18
  const $headers = args && 'headers' in args ? args.headers : undefined;
21
19
  const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || fetch;
@@ -72,12 +70,12 @@ export function useHasuraClientInner(args?: Omit<GqlAuthParam, 'retries'>) {
72
70
  args?.subscriptions === true
73
71
  ? createSubscriptionsClient({
74
72
  lazy: true,
75
- connectionInitPayload: async () => ({
73
+ connectionParams: async () => ({
76
74
  headers: await getHeaders({
77
75
  [hasuraQueryTypeHeader]: 'subscription',
78
76
  }),
79
77
  }),
80
- wsEndpoint() {
78
+ url() {
81
79
  const wsUrl = new URL(uri);
82
80
  wsUrl.protocol = wsUrl.protocol
83
81
  .replace('https', 'wss')
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useHasuraClientInner } from './create-client';
2
2
 
3
- export { type HasuraClient, useHasuraClientInner } from './create-client';
3
+ export { useHasuraClientInner } from './create-client';
4
4
  export * from './gqty';
5
5
  export { GQtyError } from 'gqty';
6
6
 
@@ -10,6 +10,8 @@ import type { GqlAuthParam } from './types';
10
10
 
11
11
  export type ResolveOptionsWithSession<T> = LegacyResolveOptions<T>;
12
12
 
13
+ export type HasuraClient = ReturnType<typeof useHasuraClient>;
14
+
13
15
  export function useHasuraClient(args?: GqlAuthParam) {
14
16
  const { client, subscriptionsClient } = useHasuraClientInner(args);
15
17
  const retries = args.retries || 3;
@@ -1,11 +0,0 @@
1
- import { type GQtyClient, type SubscriptionsClient } from 'gqty';
2
- import { type GeneratedSchema } from './gqty';
3
- import type { GqlAuthParam } from './types';
4
- export type GqlClientV2 = ReturnType<typeof createClientV2>;
5
- export declare function createClientV2(graphqlUri: string, args?: GqlAuthParam): {
6
- client: GQtyClient<GeneratedSchema>;
7
- subscriptionsClient: SubscriptionsClient;
8
- mutate<T = unknown>(resolved: (sub: import("./gqty").Mutation) => T, options?: import("./wrap").ResolveOptionsWithSession<T>): Promise<T>;
9
- query<T_1 = unknown>(resolved: (sub: import("./gqty").Query) => T_1, options?: import("./wrap").ResolveOptionsWithSession<T_1>): Promise<T_1>;
10
- subscribe<T_2 = unknown>(resolved: (sub: import("./gqty").Subscription) => T_2, onData: (data: T_2, unsubscribeFn: () => Promise<void>) => void, onError?: (err: Error, unsubscribeFn: () => Promise<void>) => void): () => Promise<void>;
11
- };
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createClientV2 = void 0;
7
- const subscriptions_1 = require("@gqty/subscriptions");
8
- const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
- const gqty_1 = require("gqty");
10
- const gqty_2 = require("./gqty");
11
- const wrap_1 = require("./wrap");
12
- function createClientV2(graphqlUri, args) {
13
- const $headers = args && 'headers' in args ? args.headers : undefined;
14
- const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || cross_fetch_1.default;
15
- const getHeaders = $headers && typeof $headers === 'function'
16
- ? () => Promise.resolve($headers())
17
- : async () => {
18
- const headers = $headers || {};
19
- if (args && 'secret' in args) {
20
- headers['x-hasura-admin-secret'] = args.secret;
21
- }
22
- else if (args && 'accessToken' in args && args.accessToken) {
23
- headers.authorization = args.accessToken.startsWith('Bearer ')
24
- ? args.accessToken
25
- : `Bearer ${args.accessToken}`;
26
- }
27
- return headers;
28
- };
29
- const queryFetcher = async (query, variables, fetchOptions) => {
30
- const headers = await getHeaders();
31
- if (fetchOptions?.headers) {
32
- for (const key in fetchOptions.headers) {
33
- headers[key] = fetchOptions.headers[key];
34
- }
35
- }
36
- const response = await $fetch(graphqlUri, {
37
- method: 'POST',
38
- headers: {
39
- 'Content-Type': 'application/json',
40
- ...headers,
41
- },
42
- body: JSON.stringify({
43
- query,
44
- variables,
45
- }),
46
- });
47
- const json = await response.json();
48
- return json;
49
- };
50
- const subscriptionsClient = (() => {
51
- if (args?.subscriptions === false)
52
- return;
53
- const wsUrl = new URL(graphqlUri);
54
- wsUrl.protocol = wsUrl.protocol
55
- .replace('https', 'wss')
56
- .replace('http', 'ws');
57
- const subscriptionsClient = (0, subscriptions_1.createSubscriptionsClient)({
58
- wsEndpoint: wsUrl.href,
59
- connectionInitPayload: async () => ({ headers: await getHeaders() }),
60
- });
61
- return subscriptionsClient;
62
- })();
63
- const client = (0, gqty_1.createClient)({
64
- schema: gqty_2.generatedSchema,
65
- scalarsEnumsHash: gqty_2.scalarsEnumsHash,
66
- queryFetcher,
67
- subscriptionsClient,
68
- normalization: args?.normalization !== false,
69
- defaults: {
70
- resolved: {
71
- noCache: args?.cache ? false : true,
72
- retry: false,
73
- },
74
- },
75
- ...args,
76
- });
77
- return (0, wrap_1.wrapGraphQLClient)(client, subscriptionsClient, args?.onError);
78
- }
79
- exports.createClientV2 = createClientV2;
@@ -1 +0,0 @@
1
- export declare const env: import("dotenv").DotenvParseOutput;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.env = void 0;
4
- const node_path_1 = require("node:path");
5
- const dotenv_1 = require("dotenv");
6
- exports.env = (0, dotenv_1.config)({ path: (0, node_path_1.join)(__dirname, '.env') }).parsed || {};
@@ -1,2 +0,0 @@
1
- export declare const hasuraGraphqlUri = "https://finalytic.hasura.app/v1/graphql";
2
- export declare const hasuraQueryTypeHeader = "x-hasura-query-type";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasuraQueryTypeHeader = exports.hasuraGraphqlUri = void 0;
4
- exports.hasuraGraphqlUri = 'https://finalytic.hasura.app/v1/graphql'; // 'https://hasura.vrplatform.app/v1/graphql';
5
- exports.hasuraQueryTypeHeader = 'x-hasura-query-type';
@@ -1,7 +0,0 @@
1
- import { type GeneratedSchema } from './gqty';
2
- import type { GqlAuthParam } from './types';
3
- export type HasuraClient = ReturnType<typeof useHasuraClientInner>;
4
- export declare function useHasuraClientInner(args?: Omit<GqlAuthParam, 'retries'>): {
5
- subscriptionsClient: import("gqty").LegacySubscriptionsClient;
6
- client: import("gqty").GQtyClient<GeneratedSchema>;
7
- };