@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.
- package/LICENSE +3 -0
- package/build/main/constants.d.ts +2 -0
- package/build/main/constants.js +5 -0
- package/build/main/create-client-v2.d.ts +11 -0
- package/build/main/create-client-v2.js +79 -0
- package/build/main/create-client.d.ts +11 -0
- package/build/main/create-client.js +122 -0
- package/build/main/dotenv.d.ts +1 -0
- package/build/main/dotenv.js +6 -0
- package/build/main/gqty/index.d.ts +1 -0
- package/build/main/gqty/index.js +17 -0
- package/build/main/gqty/schema.generated.d.ts +117383 -0
- package/build/main/gqty/schema.generated.js +47182 -0
- package/build/main/index.d.ts +4 -0
- package/build/main/index.js +24 -0
- package/build/main/src/constants.d.ts +2 -0
- package/build/main/src/constants.js +5 -0
- package/build/main/src/create-client.d.ts +7 -0
- package/build/main/src/create-client.js +109 -0
- package/build/main/src/gqty/index.d.ts +1 -0
- package/build/main/src/gqty/index.js +17 -0
- package/build/main/src/gqty/schema.generated.d.ts +147429 -0
- package/build/main/src/gqty/schema.generated.js +47182 -0
- package/build/main/src/index.d.ts +14 -0
- package/build/main/src/index.js +93 -0
- package/build/main/src/index.spec.d.ts +1 -0
- package/build/main/src/index.spec.js +12 -0
- package/build/main/src/types.d.ts +16 -0
- package/build/main/src/types.js +2 -0
- package/build/main/tsconfig.main.tsbuildinfo +1 -0
- package/build/main/types.d.ts +18 -0
- package/build/main/types.js +2 -0
- package/build/main/wrap.d.ts +10 -0
- package/build/main/wrap.js +70 -0
- package/build/module/constants.d.ts +2 -0
- package/build/module/constants.js +2 -0
- package/build/module/create-client-v2.d.ts +11 -0
- package/build/module/create-client-v2.js +72 -0
- package/build/module/create-client.d.ts +11 -0
- package/build/module/create-client.js +116 -0
- package/build/module/dotenv.d.ts +1 -0
- package/build/module/dotenv.js +3 -0
- package/build/module/gqty/index.d.ts +1 -0
- package/build/module/gqty/index.js +1 -0
- package/build/module/gqty/schema.generated.d.ts +117383 -0
- package/build/module/gqty/schema.generated.js +47179 -0
- package/build/module/index.d.ts +4 -0
- package/build/module/index.js +4 -0
- package/build/module/src/constants.d.ts +2 -0
- package/build/module/src/constants.js +2 -0
- package/build/module/src/create-client.d.ts +7 -0
- package/build/module/src/create-client.js +103 -0
- package/build/module/src/gqty/index.d.ts +1 -0
- package/build/module/src/gqty/index.js +1 -0
- package/build/module/src/gqty/schema.generated.d.ts +147429 -0
- package/build/module/src/gqty/schema.generated.js +47179 -0
- package/build/module/src/index.d.ts +14 -0
- package/build/module/src/index.js +73 -0
- package/build/module/src/index.spec.d.ts +1 -0
- package/build/module/src/index.spec.js +10 -0
- package/build/module/src/types.d.ts +16 -0
- package/build/module/src/types.js +1 -0
- package/build/module/tsconfig.esm.tsbuildinfo +1 -0
- package/build/module/types.d.ts +18 -0
- package/build/module/types.js +1 -0
- package/build/module/wrap.d.ts +10 -0
- package/build/module/wrap.js +67 -0
- package/package.json +66 -0
- package/src/constants.ts +2 -0
- package/src/create-client.ts +121 -0
- package/src/gqty/index.ts +1 -0
- package/src/gqty/schema.generated.d.ts +117383 -0
- package/src/gqty/schema.generated.js +47255 -0
- package/src/index.ts +93 -0
- 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,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';
|