@fxhash/gql-client 0.0.1 → 0.0.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/dist/index.d.ts +20 -19
- package/dist/index.js +49 -44
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
import { Client, ClientOptions } from
|
2
|
-
export { Client } from '@urql/core';
|
1
|
+
import { Client, Client as Client$1, ClientOptions } from "@urql/core";
|
3
2
|
|
3
|
+
//#region src/index.d.ts
|
4
4
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
5
5
|
type CreateHasuraClientOptions = Optional<ClientOptions, "exchanges" | "url"> & {
|
6
|
-
|
6
|
+
hasuraAdminSecret?: string;
|
7
7
|
};
|
8
8
|
/**
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
declare function createGqlClient(options: CreateHasuraClientOptions): Client;
|
9
|
+
* Instanciates a new graphql client (using `@urql/core`), configuring a http
|
10
|
+
* header for authenticating the client against hasura if provided.
|
11
|
+
* @param hasuraAdminSecret The admin secret for hasura
|
12
|
+
* @returns @urql/core client
|
13
|
+
*/
|
14
|
+
declare function createGqlClient(options: CreateHasuraClientOptions): Client$1;
|
15
15
|
/**
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
declare const gqlClient: Client;
|
24
|
-
|
25
|
-
export {
|
16
|
+
* Default hasura client instanciated with "best option" as a default. If
|
17
|
+
* `process.env.HASURA_ADMIN_SECRET` is defined, a header will be added with
|
18
|
+
* the hasura admin secret.
|
19
|
+
*
|
20
|
+
* @remark The function createHasuraClient() should be used if the default
|
21
|
+
* client instanciated is not suited.
|
22
|
+
*/
|
23
|
+
declare const gqlClient: Client$1;
|
24
|
+
//#endregion
|
25
|
+
export { Client, CreateHasuraClientOptions, createGqlClient, gqlClient as default, gqlClient };
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
@@ -1,51 +1,56 @@
|
|
1
|
-
// src/index.ts
|
2
1
|
import { config } from "@fxhash/config";
|
3
2
|
import { Client, fetchExchange } from "@urql/core";
|
4
3
|
import deepmerge from "deepmerge";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
|
5
|
+
//#region src/index.ts
|
6
|
+
const defaultClientOptions = {
|
7
|
+
url: config.apis.hasuraGql,
|
8
|
+
exchanges: [fetchExchange],
|
9
|
+
fetchOptions: {
|
10
|
+
headers: {},
|
11
|
+
credentials: "include"
|
12
|
+
}
|
12
13
|
};
|
14
|
+
/**
|
15
|
+
* Instanciates a new graphql client (using `@urql/core`), configuring a http
|
16
|
+
* header for authenticating the client against hasura if provided.
|
17
|
+
* @param hasuraAdminSecret The admin secret for hasura
|
18
|
+
* @returns @urql/core client
|
19
|
+
*/
|
13
20
|
function createGqlClient(options) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
_options.fetchOptions = addHasuraAdminSecretHeaders({
|
36
|
-
...defaultClientOptions.fetchOptions,
|
37
|
-
..._fetchOptions
|
38
|
-
});
|
39
|
-
}
|
40
|
-
return new Client(_options);
|
21
|
+
const addHasuraAdminSecretHeaders = (reqInit) => {
|
22
|
+
if (options.hasuraAdminSecret) {
|
23
|
+
if (!reqInit.headers) reqInit.headers = {};
|
24
|
+
reqInit.headers["x-hasura-admin-secret"] = options.hasuraAdminSecret;
|
25
|
+
}
|
26
|
+
return reqInit;
|
27
|
+
};
|
28
|
+
const _fetchOptions = options.fetchOptions;
|
29
|
+
delete options.fetchOptions;
|
30
|
+
const _options = deepmerge(defaultClientOptions, options);
|
31
|
+
if (typeof _fetchOptions === "function") _options.fetchOptions = () => {
|
32
|
+
return addHasuraAdminSecretHeaders({
|
33
|
+
...defaultClientOptions.fetchOptions,
|
34
|
+
..._fetchOptions()
|
35
|
+
});
|
36
|
+
};
|
37
|
+
else _options.fetchOptions = addHasuraAdminSecretHeaders({
|
38
|
+
...defaultClientOptions.fetchOptions,
|
39
|
+
..._fetchOptions
|
40
|
+
});
|
41
|
+
return new Client(_options);
|
41
42
|
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
};
|
43
|
+
/**
|
44
|
+
* Default hasura client instanciated with "best option" as a default. If
|
45
|
+
* `process.env.HASURA_ADMIN_SECRET` is defined, a header will be added with
|
46
|
+
* the hasura admin secret.
|
47
|
+
*
|
48
|
+
* @remark The function createHasuraClient() should be used if the default
|
49
|
+
* client instanciated is not suited.
|
50
|
+
*/
|
51
|
+
const gqlClient = createGqlClient({ hasuraAdminSecret: process.env.HASURA_ADMIN_SECRET });
|
52
|
+
var src_default = gqlClient;
|
53
|
+
|
54
|
+
//#endregion
|
55
|
+
export { createGqlClient, src_default as default, gqlClient };
|
51
56
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { config } from \"@fxhash/config\"\nimport { Client, ClientOptions, fetchExchange } from \"@urql/core\"\nimport deepmerge from \"deepmerge\"\n\nconst defaultClientOptions: ClientOptions = {\n url: config.apis.hasuraGql,\n exchanges: [fetchExchange],\n fetchOptions: {\n headers: {},\n credentials: \"include\",\n },\n}\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type CreateHasuraClientOptions = Optional<\n ClientOptions,\n \"exchanges\" | \"url\"\n> & {\n hasuraAdminSecret?: string\n}\n\n/**\n * Instanciates a new graphql client (using `@urql/core`), configuring a http\n * header for authenticating the client against hasura if provided.\n * @param hasuraAdminSecret The admin secret for hasura\n * @returns @urql/core client\n */\nexport function createGqlClient(options: CreateHasuraClientOptions) {\n const addHasuraAdminSecretHeaders = (reqInit: RequestInit) => {\n if (options.hasuraAdminSecret) {\n if (!reqInit.headers) {\n reqInit.headers = {}\n }\n ;(reqInit as any).headers[\"x-hasura-admin-secret\"] =\n options.hasuraAdminSecret\n }\n return reqInit\n }\n\n const _fetchOptions = options.fetchOptions\n delete options.fetchOptions\n const _options = deepmerge(defaultClientOptions, options)\n\n if (typeof _fetchOptions === \"function\") {\n _options.fetchOptions = () => {\n return addHasuraAdminSecretHeaders({\n ...defaultClientOptions.fetchOptions,\n ..._fetchOptions(),\n })\n }\n } else {\n _options.fetchOptions = addHasuraAdminSecretHeaders({\n ...defaultClientOptions.fetchOptions,\n ..._fetchOptions,\n })\n }\n\n return new Client(_options)\n}\n\n/**\n * Default hasura client instanciated with \"best option\" as a default. If\n * `process.env.HASURA_ADMIN_SECRET` is defined, a header will be added with\n * the hasura admin secret.\n *\n * @remark The function createHasuraClient() should be used if the default\n * client instanciated is not suited.\n */\nexport const gqlClient = createGqlClient({\n hasuraAdminSecret: process.env.HASURA_ADMIN_SECRET,\n})\nexport default gqlClient\n\n/**\n * Export utility types from `@urql/core`\n */\nexport {
|
1
|
+
{"version":3,"file":"index.js","names":["defaultClientOptions: ClientOptions","options: CreateHasuraClientOptions","reqInit: RequestInit","gqlClient: Client"],"sources":["../src/index.ts"],"sourcesContent":["import { config } from \"@fxhash/config\"\nimport { Client, type ClientOptions, fetchExchange } from \"@urql/core\"\nimport deepmerge from \"deepmerge\"\n\nconst defaultClientOptions: ClientOptions = {\n url: config.apis.hasuraGql,\n exchanges: [fetchExchange],\n fetchOptions: {\n headers: {},\n credentials: \"include\",\n },\n}\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>\n\nexport type CreateHasuraClientOptions = Optional<\n ClientOptions,\n \"exchanges\" | \"url\"\n> & {\n hasuraAdminSecret?: string\n}\n\n/**\n * Instanciates a new graphql client (using `@urql/core`), configuring a http\n * header for authenticating the client against hasura if provided.\n * @param hasuraAdminSecret The admin secret for hasura\n * @returns @urql/core client\n */\nexport function createGqlClient(options: CreateHasuraClientOptions): Client {\n const addHasuraAdminSecretHeaders = (reqInit: RequestInit) => {\n if (options.hasuraAdminSecret) {\n if (!reqInit.headers) {\n reqInit.headers = {}\n }\n ;(reqInit as any).headers[\"x-hasura-admin-secret\"] =\n options.hasuraAdminSecret\n }\n return reqInit\n }\n\n const _fetchOptions = options.fetchOptions\n delete options.fetchOptions\n const _options = deepmerge(defaultClientOptions, options)\n\n if (typeof _fetchOptions === \"function\") {\n _options.fetchOptions = () => {\n return addHasuraAdminSecretHeaders({\n ...defaultClientOptions.fetchOptions,\n ..._fetchOptions(),\n })\n }\n } else {\n _options.fetchOptions = addHasuraAdminSecretHeaders({\n ...defaultClientOptions.fetchOptions,\n ..._fetchOptions,\n })\n }\n\n return new Client(_options)\n}\n\n/**\n * Default hasura client instanciated with \"best option\" as a default. If\n * `process.env.HASURA_ADMIN_SECRET` is defined, a header will be added with\n * the hasura admin secret.\n *\n * @remark The function createHasuraClient() should be used if the default\n * client instanciated is not suited.\n */\nexport const gqlClient: Client = createGqlClient({\n hasuraAdminSecret: process.env.HASURA_ADMIN_SECRET,\n})\nexport default gqlClient\n\n/**\n * Export utility types from `@urql/core`\n */\nexport type { Client } from \"@urql/core\"\n"],"mappings":";;;;;AAIA,MAAMA,uBAAsC;CAC1C,KAAK,OAAO,KAAK;CACjB,WAAW,CAAC,aAAc;CAC1B,cAAc;EACZ,SAAS,CAAE;EACX,aAAa;CACd;AACF;;;;;;;AAiBD,SAAgB,gBAAgBC,SAA4C;CAC1E,MAAM,8BAA8B,CAACC,YAAyB;AAC5D,MAAI,QAAQ,mBAAmB;AAC7B,QAAK,QAAQ,QACX,SAAQ,UAAU,CAAE;AAErB,GAAC,QAAgB,QAAQ,2BACxB,QAAQ;EACX;AACD,SAAO;CACR;CAED,MAAM,gBAAgB,QAAQ;AAC9B,QAAO,QAAQ;CACf,MAAM,WAAW,UAAU,sBAAsB,QAAQ;AAEzD,YAAW,kBAAkB,WAC3B,UAAS,eAAe,MAAM;AAC5B,SAAO,4BAA4B;GACjC,GAAG,qBAAqB;GACxB,GAAG,eAAe;EACnB,EAAC;CACH;KAED,UAAS,eAAe,4BAA4B;EAClD,GAAG,qBAAqB;EACxB,GAAG;CACJ,EAAC;AAGJ,QAAO,IAAI,OAAO;AACnB;;;;;;;;;AAUD,MAAaC,YAAoB,gBAAgB,EAC/C,mBAAmB,QAAQ,IAAI,oBAChC,EAAC;AACF,kBAAe"}
|
package/package.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fxhash/gql-client",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"author": "fxhash",
|
5
5
|
"dependencies": {
|
6
6
|
"@urql/core": "4.1.4",
|
7
7
|
"deepmerge": "4.3.1",
|
8
8
|
"graphql": "16.10.0",
|
9
|
-
"@fxhash/config": "0.0.
|
9
|
+
"@fxhash/config": "0.0.12"
|
10
10
|
},
|
11
11
|
"devDependencies": {
|
12
12
|
"@types/node": "20.11.30",
|
13
|
-
"
|
13
|
+
"tsdown": "0.12.2",
|
14
14
|
"typescript": "5.8.2",
|
15
|
-
"@fxhash/tsconfig": "0.0.
|
15
|
+
"@fxhash/tsconfig": "0.0.3"
|
16
16
|
},
|
17
17
|
"exports": {
|
18
18
|
".": {
|
@@ -28,9 +28,10 @@
|
|
28
28
|
"access": "public"
|
29
29
|
},
|
30
30
|
"repository": "fxhash/fxhash-package",
|
31
|
+
"sideEffects": false,
|
31
32
|
"type": "module",
|
32
33
|
"scripts": {
|
33
|
-
"build": "
|
34
|
-
"dev": "
|
34
|
+
"build": "tsdown && tsc --noEmit",
|
35
|
+
"dev": "tsdown --watch"
|
35
36
|
}
|
36
37
|
}
|