@vrplatform/graphql 1.0.0

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 (75) hide show
  1. package/LICENSE +3 -0
  2. package/build/main/constants.d.ts +2 -0
  3. package/build/main/constants.js +5 -0
  4. package/build/main/create-client-v2.d.ts +11 -0
  5. package/build/main/create-client-v2.js +79 -0
  6. package/build/main/create-client.d.ts +11 -0
  7. package/build/main/create-client.js +122 -0
  8. package/build/main/dotenv.d.ts +1 -0
  9. package/build/main/dotenv.js +6 -0
  10. package/build/main/gqty/index.d.ts +1 -0
  11. package/build/main/gqty/index.js +17 -0
  12. package/build/main/gqty/schema.generated.d.ts +117383 -0
  13. package/build/main/gqty/schema.generated.js +47182 -0
  14. package/build/main/index.d.ts +4 -0
  15. package/build/main/index.js +24 -0
  16. package/build/main/src/constants.d.ts +2 -0
  17. package/build/main/src/constants.js +5 -0
  18. package/build/main/src/create-client.d.ts +7 -0
  19. package/build/main/src/create-client.js +109 -0
  20. package/build/main/src/gqty/index.d.ts +1 -0
  21. package/build/main/src/gqty/index.js +17 -0
  22. package/build/main/src/gqty/schema.generated.d.ts +147429 -0
  23. package/build/main/src/gqty/schema.generated.js +47182 -0
  24. package/build/main/src/index.d.ts +14 -0
  25. package/build/main/src/index.js +93 -0
  26. package/build/main/src/index.spec.d.ts +1 -0
  27. package/build/main/src/index.spec.js +12 -0
  28. package/build/main/src/types.d.ts +16 -0
  29. package/build/main/src/types.js +2 -0
  30. package/build/main/tsconfig.main.tsbuildinfo +1 -0
  31. package/build/main/types.d.ts +18 -0
  32. package/build/main/types.js +2 -0
  33. package/build/main/wrap.d.ts +10 -0
  34. package/build/main/wrap.js +70 -0
  35. package/build/module/constants.d.ts +2 -0
  36. package/build/module/constants.js +2 -0
  37. package/build/module/create-client-v2.d.ts +11 -0
  38. package/build/module/create-client-v2.js +72 -0
  39. package/build/module/create-client.d.ts +11 -0
  40. package/build/module/create-client.js +116 -0
  41. package/build/module/dotenv.d.ts +1 -0
  42. package/build/module/dotenv.js +3 -0
  43. package/build/module/gqty/index.d.ts +1 -0
  44. package/build/module/gqty/index.js +1 -0
  45. package/build/module/gqty/schema.generated.d.ts +117383 -0
  46. package/build/module/gqty/schema.generated.js +47179 -0
  47. package/build/module/index.d.ts +4 -0
  48. package/build/module/index.js +4 -0
  49. package/build/module/src/constants.d.ts +2 -0
  50. package/build/module/src/constants.js +2 -0
  51. package/build/module/src/create-client.d.ts +7 -0
  52. package/build/module/src/create-client.js +103 -0
  53. package/build/module/src/gqty/index.d.ts +1 -0
  54. package/build/module/src/gqty/index.js +1 -0
  55. package/build/module/src/gqty/schema.generated.d.ts +147429 -0
  56. package/build/module/src/gqty/schema.generated.js +47179 -0
  57. package/build/module/src/index.d.ts +14 -0
  58. package/build/module/src/index.js +73 -0
  59. package/build/module/src/index.spec.d.ts +1 -0
  60. package/build/module/src/index.spec.js +10 -0
  61. package/build/module/src/types.d.ts +16 -0
  62. package/build/module/src/types.js +1 -0
  63. package/build/module/tsconfig.esm.tsbuildinfo +1 -0
  64. package/build/module/types.d.ts +18 -0
  65. package/build/module/types.js +1 -0
  66. package/build/module/wrap.d.ts +10 -0
  67. package/build/module/wrap.js +67 -0
  68. package/package.json +66 -0
  69. package/src/constants.ts +2 -0
  70. package/src/create-client.ts +121 -0
  71. package/src/gqty/index.ts +1 -0
  72. package/src/gqty/schema.generated.d.ts +117383 -0
  73. package/src/gqty/schema.generated.js +47255 -0
  74. package/src/index.ts +93 -0
  75. package/src/types.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ RESTRICTED
2
+
3
+ THE CODE IS NOT MEANT TO BE SHARED WITH ANYONE OUTSIDE THE MAINTAINERS, AS SET IN THE REPOSITORIES GITHUB ACCESS SETTINGS.
@@ -0,0 +1,2 @@
1
+ export declare const hasuraGraphqlUri = "https://finalytic.hasura.app/v1/graphql";
2
+ export declare const hasuraQueryTypeHeader = "x-hasura-query-type";
@@ -0,0 +1,5 @@
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';
@@ -0,0 +1,11 @@
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
+ };
@@ -0,0 +1,79 @@
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;
@@ -0,0 +1,11 @@
1
+ import { type GQtyClient } from 'gqty';
2
+ import { type GeneratedSchema } from './gqty';
3
+ 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>;
11
+ };
@@ -0,0 +1,122 @@
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.useHasuraClient = useHasuraClient;
7
+ const subscriptions_1 = require("@gqty/subscriptions");
8
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
+ const gqty_1 = require("gqty");
10
+ const constants_1 = require("./constants");
11
+ const gqty_2 = require("./gqty");
12
+ const wrap_1 = require("./wrap");
13
+ function useHasuraClient(args) {
14
+ const $headers = args && 'headers' in args ? args.headers : undefined;
15
+ const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || cross_fetch_1.default;
16
+ const uri = args?.uri || constants_1.hasuraGraphqlUri;
17
+ const getHeaders = async (base) => {
18
+ const headers = ($headers && typeof $headers === 'function'
19
+ ? await $headers()
20
+ : $headers) || {};
21
+ if (base)
22
+ for (const key in base)
23
+ headers[key] = base[key];
24
+ if (args && 'secret' in args && args.secret) {
25
+ headers['x-hasura-admin-secret'] = args.secret;
26
+ }
27
+ else if (args && 'accessToken' in args && args.accessToken) {
28
+ headers.authorization = args.accessToken.startsWith('Bearer ')
29
+ ? args.accessToken
30
+ : `Bearer ${args.accessToken}`;
31
+ }
32
+ if (args?.auditUserId)
33
+ headers['x-hasura-audit-user-id'] = args.auditUserId;
34
+ return headers;
35
+ };
36
+ const queryFetcher = async ({ query, variables, operationName }, fetchOptions) => {
37
+ const headers = await getHeaders();
38
+ if (fetchOptions?.headers) {
39
+ for (const key in fetchOptions.headers) {
40
+ headers[key] = fetchOptions.headers[key];
41
+ }
42
+ }
43
+ // Modify "https://finalytic.hasura.app/v1/graphql" if needed
44
+ const response = await (0, cross_fetch_1.default)('https://finalytic.hasura.app/v1/graphql', {
45
+ method: 'POST',
46
+ headers: {
47
+ 'Content-Type': 'application/json',
48
+ },
49
+ body: JSON.stringify({
50
+ query,
51
+ variables,
52
+ operationName,
53
+ }),
54
+ mode: 'cors',
55
+ ...fetchOptions,
56
+ });
57
+ const json = await response.json();
58
+ return await (0, gqty_1.defaultResponseHandler)(json);
59
+ };
60
+ const subscriptionsClient = args?.subscriptions === true
61
+ ? (0, subscriptions_1.createSubscriptionsClient)({
62
+ lazy: true,
63
+ connectionInitPayload: async () => ({
64
+ headers: await getHeaders({
65
+ [constants_1.hasuraQueryTypeHeader]: 'subscription',
66
+ }),
67
+ }),
68
+ wsEndpoint() {
69
+ const wsUrl = new URL(uri);
70
+ wsUrl.protocol = wsUrl.protocol
71
+ .replace('https', 'wss')
72
+ .replace('http', 'ws');
73
+ return wsUrl.href;
74
+ },
75
+ /*url: () => {
76
+ },*/
77
+ })
78
+ : 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
+ const cache = new gqty_1.Cache(undefined, {
94
+ maxAge: 0,
95
+ staleWhileRevalidate: 5 * 60 * 1000,
96
+ normalization: true,
97
+ });
98
+ const client = (0, gqty_1.createClient)({
99
+ schema: gqty_2.generatedSchema,
100
+ scalars: gqty_2.scalarsEnumsHash,
101
+ cache,
102
+ fetchOptions: {
103
+ fetcher: queryFetcher,
104
+ subscriber: subscriptionsClient,
105
+ },
106
+ });
107
+ /*const client: GQtyClient<GeneratedSchema> = createClient<GeneratedSchema>({
108
+ schema: generatedSchema,
109
+ scalarsEnumsHash,
110
+ queryFetcher,
111
+ subscriptionsClient,
112
+ normalization: args?.normalization === true,
113
+ defaults: {
114
+ resolved: {
115
+ noCache: args?.cache !== true,
116
+ retry: false,
117
+ },
118
+ },
119
+ ...args,
120
+ });*/
121
+ return (0, wrap_1.wrapGraphQLClient)(client, subscriptionsClient, args?.onError, args?.retries);
122
+ }
@@ -0,0 +1 @@
1
+ export declare const env: import("dotenv").DotenvParseOutput;
@@ -0,0 +1,6 @@
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 || {};
@@ -0,0 +1 @@
1
+ export * from './schema.generated';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./schema.generated"), exports);