@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
@@ -0,0 +1,4 @@
1
+ export { type ResolveOptionsWithSession, wrapGraphQLClient } from './wrap';
2
+ export { type HasuraClient, useHasuraClient } from './create-client';
3
+ export * from './gqty';
4
+ export { GQtyClient, LegacySubscriptionsClient as SubscriptionsClient, LegacyResolveOptions as ResolveOptions, GQtyError, } from 'gqty';
@@ -0,0 +1,4 @@
1
+ export { wrapGraphQLClient } from './wrap';
2
+ export { useHasuraClient } from './create-client';
3
+ export * from './gqty';
4
+ export { GQtyError, } from 'gqty';
@@ -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,2 @@
1
+ export const hasuraGraphqlUri = 'https://finalytic.hasura.app/v1/graphql'; // 'https://hasura.vrplatform.app/v1/graphql';
2
+ export const hasuraQueryTypeHeader = 'x-hasura-query-type';
@@ -0,0 +1,7 @@
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
+ };
@@ -0,0 +1,103 @@
1
+ import { createSubscriptionsClient } from '@gqty/subscriptions';
2
+ import fetch from 'cross-fetch';
3
+ import { Cache, createClient } from 'gqty';
4
+ import { hasuraGraphqlUri, hasuraQueryTypeHeader } from './constants';
5
+ import { generatedSchema, scalarsEnumsHash, } from './gqty';
6
+ export function useHasuraClientInner(args) {
7
+ const $headers = args && 'headers' in args ? args.headers : undefined;
8
+ const $fetch = (args && 'fetch' in args ? args.fetch : undefined) || fetch;
9
+ const uri = args?.uri || hasuraGraphqlUri;
10
+ const getHeaders = async (base) => {
11
+ const headers = ($headers && typeof $headers === 'function'
12
+ ? await $headers()
13
+ : $headers) || {};
14
+ if (base)
15
+ for (const key in base)
16
+ headers[key] = base[key];
17
+ if (args && 'secret' in args && args.secret) {
18
+ headers['x-hasura-admin-secret'] = args.secret;
19
+ }
20
+ else if (args && 'accessToken' in args && args.accessToken) {
21
+ headers.authorization = args.accessToken.startsWith('Bearer ')
22
+ ? args.accessToken
23
+ : `Bearer ${args.accessToken}`;
24
+ }
25
+ if (args?.auditUserId)
26
+ headers['x-hasura-audit-user-id'] = args.auditUserId;
27
+ return headers;
28
+ };
29
+ const queryFetcher = async ({ query, variables, operationName }, 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
+ // Modify "https://finalytic.hasura.app/v1/graphql" if needed
37
+ const response = await $fetch('https://finalytic.hasura.app/v1/graphql', {
38
+ ...fetchOptions,
39
+ method: 'POST',
40
+ headers: {
41
+ 'Content-Type': 'application/json',
42
+ ...headers,
43
+ },
44
+ body: JSON.stringify({
45
+ query,
46
+ variables,
47
+ operationName,
48
+ }),
49
+ mode: 'cors',
50
+ });
51
+ const json = await response.json();
52
+ return json; //await defaultResponseHandler(json);
53
+ };
54
+ const subscriptionsClient = args?.subscriptions === true
55
+ ? createSubscriptionsClient({
56
+ lazy: true,
57
+ connectionInitPayload: async () => ({
58
+ headers: await getHeaders({
59
+ [hasuraQueryTypeHeader]: 'subscription',
60
+ }),
61
+ }),
62
+ wsEndpoint() {
63
+ const wsUrl = new URL(uri);
64
+ wsUrl.protocol = wsUrl.protocol
65
+ .replace('https', 'wss')
66
+ .replace('http', 'ws');
67
+ return wsUrl.href;
68
+ },
69
+ /*url: () => {
70
+ },*/
71
+ })
72
+ : undefined;
73
+ const cache = new Cache(undefined, {
74
+ maxAge: 0,
75
+ staleWhileRevalidate: 0,
76
+ normalization: false,
77
+ });
78
+ const client = createClient({
79
+ schema: generatedSchema,
80
+ scalars: scalarsEnumsHash,
81
+ //cache,
82
+ cache,
83
+ fetchOptions: {
84
+ fetcher: queryFetcher,
85
+ subscriber: subscriptionsClient,
86
+ },
87
+ });
88
+ /*const client: GQtyClient<GeneratedSchema> = createClient<GeneratedSchema>({
89
+ schema: generatedSchema,
90
+ scalarsEnumsHash,
91
+ queryFetcher,
92
+ subscriptionsClient,
93
+ normalization: args?.normalization === true,
94
+ defaults: {
95
+ resolved: {
96
+ noCache: args?.cache !== true,
97
+ retry: false,
98
+ },
99
+ },
100
+ ...args,
101
+ });*/
102
+ return { subscriptionsClient, client };
103
+ }
@@ -0,0 +1 @@
1
+ export * from './schema.generated';
@@ -0,0 +1 @@
1
+ export * from './schema.generated';