@settlemint/sdk-thegraph 2.3.2-pref75df5f → 2.3.2-preff27199
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/README.md +1 -1
- package/dist/browser/thegraph.d.ts +88 -0
- package/dist/browser/thegraph.js +105 -0
- package/dist/browser/thegraph.js.map +1 -0
- package/dist/thegraph.cjs +121 -55
- package/dist/thegraph.cjs.map +1 -1
- package/dist/thegraph.d.cts +24 -19
- package/dist/thegraph.d.ts +24 -19
- package/dist/thegraph.js +105 -0
- package/dist/thegraph.js.map +1 -0
- package/package.json +6 -6
- package/dist/thegraph.mjs +0 -42
- package/dist/thegraph.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -111,7 +111,7 @@ const { client, graphql } = createTheGraphClient<{
|
|
|
111
111
|
};
|
|
112
112
|
}>({
|
|
113
113
|
instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
114
|
-
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
114
|
+
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
115
115
|
subgraphName: 'kits'
|
|
116
116
|
}, {
|
|
117
117
|
fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
|
|
2
|
+
import { GraphQLClient } from "graphql-request";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
|
|
5
|
+
//#region src/thegraph.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type definition for GraphQL client configuration options
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Type definition for GraphQL client configuration options
|
|
11
|
+
*/
|
|
12
|
+
type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
13
|
+
/**
|
|
14
|
+
* Schema for validating client options for the TheGraph client.
|
|
15
|
+
*/
|
|
16
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
17
|
+
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
|
|
18
|
+
accessToken: z.ZodString;
|
|
19
|
+
subgraphName: z.ZodString;
|
|
20
|
+
cache: z.ZodOptional<z.ZodEnum<{
|
|
21
|
+
default: "default";
|
|
22
|
+
"force-cache": "force-cache";
|
|
23
|
+
"no-cache": "no-cache";
|
|
24
|
+
"no-store": "no-store";
|
|
25
|
+
"only-if-cached": "only-if-cached";
|
|
26
|
+
reload: "reload";
|
|
27
|
+
}>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
/**
|
|
30
|
+
* Type definition for client options derived from the ClientOptionsSchema
|
|
31
|
+
*/
|
|
32
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
35
|
+
*
|
|
36
|
+
* @param options - Configuration options for the client including instance URLs,
|
|
37
|
+
* access token and subgraph name
|
|
38
|
+
* @param clientOptions - Optional GraphQL client configuration options
|
|
39
|
+
* @returns An object containing:
|
|
40
|
+
* - client: The configured GraphQL client instance
|
|
41
|
+
* - graphql: The initialized gql.tada function for type-safe queries
|
|
42
|
+
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
|
|
43
|
+
* @example
|
|
44
|
+
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
45
|
+
* import type { introspection } from '@schemas/the-graph-env-kits';
|
|
46
|
+
* import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';
|
|
47
|
+
*
|
|
48
|
+
* const logger = createLogger();
|
|
49
|
+
*
|
|
50
|
+
* const { client, graphql } = createTheGraphClient<{
|
|
51
|
+
* introspection: introspection;
|
|
52
|
+
* disableMasking: true;
|
|
53
|
+
* scalars: {
|
|
54
|
+
* Bytes: string;
|
|
55
|
+
* Int8: string;
|
|
56
|
+
* BigInt: string;
|
|
57
|
+
* BigDecimal: string;
|
|
58
|
+
* Timestamp: string;
|
|
59
|
+
* };
|
|
60
|
+
* }>({
|
|
61
|
+
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
62
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
63
|
+
* subgraphName: 'kits'
|
|
64
|
+
* }, {
|
|
65
|
+
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // Making GraphQL queries
|
|
69
|
+
* const query = graphql(`
|
|
70
|
+
* query SearchAssets {
|
|
71
|
+
* assets {
|
|
72
|
+
* id
|
|
73
|
+
* name
|
|
74
|
+
* symbol
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* `);
|
|
78
|
+
*
|
|
79
|
+
* const result = await client.request(query);
|
|
80
|
+
*/
|
|
81
|
+
declare function createTheGraphClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
|
|
82
|
+
client: GraphQLClient;
|
|
83
|
+
graphql: initGraphQLTada<Setup>;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { ClientOptions, ClientOptionsSchema, FragmentOf, RequestConfig, ResultOf, VariablesOf, createTheGraphClient, readFragment };
|
|
88
|
+
//# sourceMappingURL=thegraph.d.ts.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
2
|
+
import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
|
+
import { initGraphQLTada, readFragment } from "gql.tada";
|
|
4
|
+
import { GraphQLClient } from "graphql-request";
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
|
+
|
|
7
|
+
//#region src/thegraph.ts
|
|
8
|
+
/**
|
|
9
|
+
* Schema for validating client options for the TheGraph client.
|
|
10
|
+
*/
|
|
11
|
+
const ClientOptionsSchema = z.object({
|
|
12
|
+
instances: z.array(UrlOrPathSchema),
|
|
13
|
+
accessToken: ApplicationAccessTokenSchema,
|
|
14
|
+
subgraphName: z.string(),
|
|
15
|
+
cache: z.enum([
|
|
16
|
+
"default",
|
|
17
|
+
"force-cache",
|
|
18
|
+
"no-cache",
|
|
19
|
+
"no-store",
|
|
20
|
+
"only-if-cached",
|
|
21
|
+
"reload"
|
|
22
|
+
]).optional()
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Constructs the full URL for TheGraph GraphQL API based on the provided options
|
|
26
|
+
*
|
|
27
|
+
* @param options - The client options for configuring TheGraph client
|
|
28
|
+
* @returns The complete GraphQL API URL as a string
|
|
29
|
+
* @throws Will throw an error if no matching instance is found for the specified subgraph
|
|
30
|
+
*/
|
|
31
|
+
function getFullUrl(options) {
|
|
32
|
+
const instance = options.instances.find((instance$1) => instance$1.endsWith(`/${options.subgraphName}`));
|
|
33
|
+
if (!instance) {
|
|
34
|
+
throw new Error(`Instance for subgraph ${options.subgraphName} not found`);
|
|
35
|
+
}
|
|
36
|
+
return new URL(instance).toString();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
40
|
+
*
|
|
41
|
+
* @param options - Configuration options for the client including instance URLs,
|
|
42
|
+
* access token and subgraph name
|
|
43
|
+
* @param clientOptions - Optional GraphQL client configuration options
|
|
44
|
+
* @returns An object containing:
|
|
45
|
+
* - client: The configured GraphQL client instance
|
|
46
|
+
* - graphql: The initialized gql.tada function for type-safe queries
|
|
47
|
+
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
|
|
48
|
+
* @example
|
|
49
|
+
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
50
|
+
* import type { introspection } from '@schemas/the-graph-env-kits';
|
|
51
|
+
* import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';
|
|
52
|
+
*
|
|
53
|
+
* const logger = createLogger();
|
|
54
|
+
*
|
|
55
|
+
* const { client, graphql } = createTheGraphClient<{
|
|
56
|
+
* introspection: introspection;
|
|
57
|
+
* disableMasking: true;
|
|
58
|
+
* scalars: {
|
|
59
|
+
* Bytes: string;
|
|
60
|
+
* Int8: string;
|
|
61
|
+
* BigInt: string;
|
|
62
|
+
* BigDecimal: string;
|
|
63
|
+
* Timestamp: string;
|
|
64
|
+
* };
|
|
65
|
+
* }>({
|
|
66
|
+
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
67
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
68
|
+
* subgraphName: 'kits'
|
|
69
|
+
* }, {
|
|
70
|
+
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Making GraphQL queries
|
|
74
|
+
* const query = graphql(`
|
|
75
|
+
* query SearchAssets {
|
|
76
|
+
* assets {
|
|
77
|
+
* id
|
|
78
|
+
* name
|
|
79
|
+
* symbol
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* `);
|
|
83
|
+
*
|
|
84
|
+
* const result = await client.request(query);
|
|
85
|
+
*/
|
|
86
|
+
function createTheGraphClient(options, clientOptions) {
|
|
87
|
+
ensureServer();
|
|
88
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
89
|
+
const graphql = initGraphQLTada();
|
|
90
|
+
const fullUrl = getFullUrl(validatedOptions);
|
|
91
|
+
return {
|
|
92
|
+
client: new GraphQLClient(fullUrl, {
|
|
93
|
+
...clientOptions,
|
|
94
|
+
headers: {
|
|
95
|
+
...clientOptions?.headers ?? {},
|
|
96
|
+
"x-auth-token": validatedOptions.accessToken
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
graphql
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ClientOptionsSchema, createTheGraphClient, readFragment };
|
|
105
|
+
//# sourceMappingURL=thegraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thegraph.js","names":["options: ClientOptions","instance","clientOptions?: RequestConfig"],"sources":["../../src/thegraph.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod/v4\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * subgraphName: 'kits'\n * }, {\n * fetch: requestLogger(logger, \"the-graph-kits\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query SearchAssets {\n * assets {\n * id\n * name\n * symbol\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createTheGraphClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: {\n ...(clientOptions?.headers ?? {}),\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;AAcA,MAAa,sBAAsB,EAAE,OAAO;CAC1C,WAAW,EAAE,MAAM,gBAAgB;CACnC,aAAa;CACb,cAAc,EAAE,QAAQ;CACxB,OAAO,EAAE,KAAK;EAAC;EAAW;EAAe;EAAY;EAAY;EAAkB;CAAS,EAAC,CAAC,UAAU;AACzG,EAAC;;;;;;;;AAcF,SAAS,WAAWA,SAAgC;CAClD,MAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,eAAa,WAAS,UAAU,GAAG,QAAQ,aAAa,EAAE,CAAC;AACpG,MAAK,UAAU;AACb,QAAM,IAAI,OAAO,wBAAwB,QAAQ,aAAa;CAC/D;AACD,QAAO,IAAI,IAAI,UAAU,UAAU;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgB,qBACdD,SACAE,eAIA;AACA,eAAc;CACd,MAAM,mBAAmB,SAAS,qBAAqB,QAAQ;CAC/D,MAAM,UAAU,iBAAwB;CACxC,MAAM,UAAU,WAAW,iBAAiB;AAE5C,QAAO;EACL,QAAQ,IAAI,cAAc,SAAS;GACjC,GAAG;GACH,SAAS;IACP,GAAI,eAAe,WAAW,CAAE;IAChC,gBAAgB,iBAAiB;GAClC;EACF;EACD;CACD;AACF"}
|
package/dist/thegraph.cjs
CHANGED
|
@@ -1,69 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
8
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
17
|
};
|
|
18
|
-
var
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
//#endregion
|
|
24
|
+
const __settlemint_sdk_utils_runtime = __toESM(require("@settlemint/sdk-utils/runtime"));
|
|
25
|
+
const __settlemint_sdk_utils_validation = __toESM(require("@settlemint/sdk-utils/validation"));
|
|
26
|
+
const gql_tada = __toESM(require("gql.tada"));
|
|
27
|
+
const graphql_request = __toESM(require("graphql-request"));
|
|
28
|
+
const zod_v4 = __toESM(require("zod/v4"));
|
|
29
|
+
|
|
30
|
+
//#region src/thegraph.ts
|
|
31
|
+
/**
|
|
32
|
+
* Schema for validating client options for the TheGraph client.
|
|
33
|
+
*/
|
|
34
|
+
const ClientOptionsSchema = zod_v4.z.object({
|
|
35
|
+
instances: zod_v4.z.array(__settlemint_sdk_utils_validation.UrlOrPathSchema),
|
|
36
|
+
accessToken: __settlemint_sdk_utils_validation.ApplicationAccessTokenSchema,
|
|
37
|
+
subgraphName: zod_v4.z.string(),
|
|
38
|
+
cache: zod_v4.z.enum([
|
|
39
|
+
"default",
|
|
40
|
+
"force-cache",
|
|
41
|
+
"no-cache",
|
|
42
|
+
"no-store",
|
|
43
|
+
"only-if-cached",
|
|
44
|
+
"reload"
|
|
45
|
+
]).optional()
|
|
39
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* Constructs the full URL for TheGraph GraphQL API based on the provided options
|
|
49
|
+
*
|
|
50
|
+
* @param options - The client options for configuring TheGraph client
|
|
51
|
+
* @returns The complete GraphQL API URL as a string
|
|
52
|
+
* @throws Will throw an error if no matching instance is found for the specified subgraph
|
|
53
|
+
*/
|
|
40
54
|
function getFullUrl(options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
const instance = options.instances.find((instance$1) => instance$1.endsWith(`/${options.subgraphName}`));
|
|
56
|
+
if (!instance) {
|
|
57
|
+
throw new Error(`Instance for subgraph ${options.subgraphName} not found`);
|
|
58
|
+
}
|
|
59
|
+
return new URL(instance).toString();
|
|
46
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
63
|
+
*
|
|
64
|
+
* @param options - Configuration options for the client including instance URLs,
|
|
65
|
+
* access token and subgraph name
|
|
66
|
+
* @param clientOptions - Optional GraphQL client configuration options
|
|
67
|
+
* @returns An object containing:
|
|
68
|
+
* - client: The configured GraphQL client instance
|
|
69
|
+
* - graphql: The initialized gql.tada function for type-safe queries
|
|
70
|
+
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
|
|
71
|
+
* @example
|
|
72
|
+
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
73
|
+
* import type { introspection } from '@schemas/the-graph-env-kits';
|
|
74
|
+
* import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';
|
|
75
|
+
*
|
|
76
|
+
* const logger = createLogger();
|
|
77
|
+
*
|
|
78
|
+
* const { client, graphql } = createTheGraphClient<{
|
|
79
|
+
* introspection: introspection;
|
|
80
|
+
* disableMasking: true;
|
|
81
|
+
* scalars: {
|
|
82
|
+
* Bytes: string;
|
|
83
|
+
* Int8: string;
|
|
84
|
+
* BigInt: string;
|
|
85
|
+
* BigDecimal: string;
|
|
86
|
+
* Timestamp: string;
|
|
87
|
+
* };
|
|
88
|
+
* }>({
|
|
89
|
+
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
90
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
91
|
+
* subgraphName: 'kits'
|
|
92
|
+
* }, {
|
|
93
|
+
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Making GraphQL queries
|
|
97
|
+
* const query = graphql(`
|
|
98
|
+
* query SearchAssets {
|
|
99
|
+
* assets {
|
|
100
|
+
* id
|
|
101
|
+
* name
|
|
102
|
+
* symbol
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
* `);
|
|
106
|
+
*
|
|
107
|
+
* const result = await client.request(query);
|
|
108
|
+
*/
|
|
47
109
|
function createTheGraphClient(options, clientOptions) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
110
|
+
(0, __settlemint_sdk_utils_runtime.ensureServer)();
|
|
111
|
+
const validatedOptions = (0, __settlemint_sdk_utils_validation.validate)(ClientOptionsSchema, options);
|
|
112
|
+
const graphql = (0, gql_tada.initGraphQLTada)();
|
|
113
|
+
const fullUrl = getFullUrl(validatedOptions);
|
|
114
|
+
return {
|
|
115
|
+
client: new graphql_request.GraphQLClient(fullUrl, {
|
|
116
|
+
...clientOptions,
|
|
117
|
+
headers: {
|
|
118
|
+
...clientOptions?.headers ?? {},
|
|
119
|
+
"x-auth-token": validatedOptions.accessToken
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
graphql
|
|
123
|
+
};
|
|
62
124
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
exports.ClientOptionsSchema = ClientOptionsSchema;
|
|
128
|
+
exports.createTheGraphClient = createTheGraphClient;
|
|
129
|
+
Object.defineProperty(exports, 'readFragment', {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () {
|
|
132
|
+
return gql_tada.readFragment;
|
|
133
|
+
}
|
|
68
134
|
});
|
|
69
135
|
//# sourceMappingURL=thegraph.cjs.map
|
package/dist/thegraph.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod/v4\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
1
|
+
{"version":3,"file":"thegraph.cjs","names":["UrlOrPathSchema","ApplicationAccessTokenSchema","options: ClientOptions","instance","clientOptions?: RequestConfig","GraphQLClient"],"sources":["../src/thegraph.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod/v4\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * subgraphName: 'kits'\n * }, {\n * fetch: requestLogger(logger, \"the-graph-kits\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query SearchAssets {\n * assets {\n * id\n * name\n * symbol\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createTheGraphClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: {\n ...(clientOptions?.headers ?? {}),\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAa,sBAAsB,SAAE,OAAO;CAC1C,WAAW,SAAE,MAAMA,kDAAgB;CACnC,aAAaC;CACb,cAAc,SAAE,QAAQ;CACxB,OAAO,SAAE,KAAK;EAAC;EAAW;EAAe;EAAY;EAAY;EAAkB;CAAS,EAAC,CAAC,UAAU;AACzG,EAAC;;;;;;;;AAcF,SAAS,WAAWC,SAAgC;CAClD,MAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,eAAa,WAAS,UAAU,GAAG,QAAQ,aAAa,EAAE,CAAC;AACpG,MAAK,UAAU;AACb,QAAM,IAAI,OAAO,wBAAwB,QAAQ,aAAa;CAC/D;AACD,QAAO,IAAI,IAAI,UAAU,UAAU;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgB,qBACdD,SACAE,eAIA;AACA,mDAAc;CACd,MAAM,mBAAmB,gDAAS,qBAAqB,QAAQ;CAC/D,MAAM,UAAU,+BAAwB;CACxC,MAAM,UAAU,WAAW,iBAAiB;AAE5C,QAAO;EACL,QAAQ,IAAIC,8BAAc,SAAS;GACjC,GAAG;GACH,SAAS;IACP,GAAI,eAAe,WAAW,CAAE;IAChC,gBAAgB,iBAAiB;GAClC;EACF;EACD;CACD;AACF"}
|
package/dist/thegraph.d.cts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { AbstractSetupSchema, initGraphQLTada } from
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { z } from 'zod/v4';
|
|
1
|
+
import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
|
|
2
|
+
import { GraphQLClient } from "graphql-request";
|
|
3
|
+
import { z } from "zod/v4";
|
|
5
4
|
|
|
5
|
+
//#region src/thegraph.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type definition for GraphQL client configuration options
|
|
8
|
+
*/
|
|
6
9
|
/**
|
|
7
10
|
* Type definition for GraphQL client configuration options
|
|
8
11
|
*/
|
|
@@ -11,17 +14,17 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
|
11
14
|
* Schema for validating client options for the TheGraph client.
|
|
12
15
|
*/
|
|
13
16
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
|
|
18
|
+
accessToken: z.ZodString;
|
|
19
|
+
subgraphName: z.ZodString;
|
|
20
|
+
cache: z.ZodOptional<z.ZodEnum<{
|
|
21
|
+
default: "default";
|
|
22
|
+
"force-cache": "force-cache";
|
|
23
|
+
"no-cache": "no-cache";
|
|
24
|
+
"no-store": "no-store";
|
|
25
|
+
"only-if-cached": "only-if-cached";
|
|
26
|
+
reload: "reload";
|
|
27
|
+
}>>;
|
|
25
28
|
}, z.core.$strip>;
|
|
26
29
|
/**
|
|
27
30
|
* Type definition for client options derived from the ClientOptionsSchema
|
|
@@ -56,7 +59,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
56
59
|
* };
|
|
57
60
|
* }>({
|
|
58
61
|
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
59
|
-
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
62
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
60
63
|
* subgraphName: 'kits'
|
|
61
64
|
* }, {
|
|
62
65
|
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
@@ -76,8 +79,10 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
76
79
|
* const result = await client.request(query);
|
|
77
80
|
*/
|
|
78
81
|
declare function createTheGraphClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
client: GraphQLClient;
|
|
83
|
+
graphql: initGraphQLTada<Setup>;
|
|
81
84
|
};
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
//#endregion
|
|
87
|
+
export { ClientOptions, ClientOptionsSchema, FragmentOf, RequestConfig, ResultOf, VariablesOf, createTheGraphClient, readFragment };
|
|
88
|
+
//# sourceMappingURL=thegraph.d.cts.map
|
package/dist/thegraph.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { AbstractSetupSchema, initGraphQLTada } from
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { z } from 'zod/v4';
|
|
1
|
+
import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
|
|
2
|
+
import { GraphQLClient } from "graphql-request";
|
|
3
|
+
import { z } from "zod/v4";
|
|
5
4
|
|
|
5
|
+
//#region src/thegraph.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Type definition for GraphQL client configuration options
|
|
8
|
+
*/
|
|
6
9
|
/**
|
|
7
10
|
* Type definition for GraphQL client configuration options
|
|
8
11
|
*/
|
|
@@ -11,17 +14,17 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
|
11
14
|
* Schema for validating client options for the TheGraph client.
|
|
12
15
|
*/
|
|
13
16
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
|
|
18
|
+
accessToken: z.ZodString;
|
|
19
|
+
subgraphName: z.ZodString;
|
|
20
|
+
cache: z.ZodOptional<z.ZodEnum<{
|
|
21
|
+
default: "default";
|
|
22
|
+
"force-cache": "force-cache";
|
|
23
|
+
"no-cache": "no-cache";
|
|
24
|
+
"no-store": "no-store";
|
|
25
|
+
"only-if-cached": "only-if-cached";
|
|
26
|
+
reload: "reload";
|
|
27
|
+
}>>;
|
|
25
28
|
}, z.core.$strip>;
|
|
26
29
|
/**
|
|
27
30
|
* Type definition for client options derived from the ClientOptionsSchema
|
|
@@ -56,7 +59,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
56
59
|
* };
|
|
57
60
|
* }>({
|
|
58
61
|
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
59
|
-
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN
|
|
62
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
60
63
|
* subgraphName: 'kits'
|
|
61
64
|
* }, {
|
|
62
65
|
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
@@ -76,8 +79,10 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
76
79
|
* const result = await client.request(query);
|
|
77
80
|
*/
|
|
78
81
|
declare function createTheGraphClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
client: GraphQLClient;
|
|
83
|
+
graphql: initGraphQLTada<Setup>;
|
|
81
84
|
};
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
//#endregion
|
|
87
|
+
export { ClientOptions, ClientOptionsSchema, FragmentOf, RequestConfig, ResultOf, VariablesOf, createTheGraphClient, readFragment };
|
|
88
|
+
//# sourceMappingURL=thegraph.d.ts.map
|
package/dist/thegraph.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
2
|
+
import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
|
+
import { initGraphQLTada, readFragment } from "gql.tada";
|
|
4
|
+
import { GraphQLClient } from "graphql-request";
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
|
+
|
|
7
|
+
//#region src/thegraph.ts
|
|
8
|
+
/**
|
|
9
|
+
* Schema for validating client options for the TheGraph client.
|
|
10
|
+
*/
|
|
11
|
+
const ClientOptionsSchema = z.object({
|
|
12
|
+
instances: z.array(UrlOrPathSchema),
|
|
13
|
+
accessToken: ApplicationAccessTokenSchema,
|
|
14
|
+
subgraphName: z.string(),
|
|
15
|
+
cache: z.enum([
|
|
16
|
+
"default",
|
|
17
|
+
"force-cache",
|
|
18
|
+
"no-cache",
|
|
19
|
+
"no-store",
|
|
20
|
+
"only-if-cached",
|
|
21
|
+
"reload"
|
|
22
|
+
]).optional()
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Constructs the full URL for TheGraph GraphQL API based on the provided options
|
|
26
|
+
*
|
|
27
|
+
* @param options - The client options for configuring TheGraph client
|
|
28
|
+
* @returns The complete GraphQL API URL as a string
|
|
29
|
+
* @throws Will throw an error if no matching instance is found for the specified subgraph
|
|
30
|
+
*/
|
|
31
|
+
function getFullUrl(options) {
|
|
32
|
+
const instance = options.instances.find((instance$1) => instance$1.endsWith(`/${options.subgraphName}`));
|
|
33
|
+
if (!instance) {
|
|
34
|
+
throw new Error(`Instance for subgraph ${options.subgraphName} not found`);
|
|
35
|
+
}
|
|
36
|
+
return new URL(instance).toString();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
40
|
+
*
|
|
41
|
+
* @param options - Configuration options for the client including instance URLs,
|
|
42
|
+
* access token and subgraph name
|
|
43
|
+
* @param clientOptions - Optional GraphQL client configuration options
|
|
44
|
+
* @returns An object containing:
|
|
45
|
+
* - client: The configured GraphQL client instance
|
|
46
|
+
* - graphql: The initialized gql.tada function for type-safe queries
|
|
47
|
+
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
|
|
48
|
+
* @example
|
|
49
|
+
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
50
|
+
* import type { introspection } from '@schemas/the-graph-env-kits';
|
|
51
|
+
* import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';
|
|
52
|
+
*
|
|
53
|
+
* const logger = createLogger();
|
|
54
|
+
*
|
|
55
|
+
* const { client, graphql } = createTheGraphClient<{
|
|
56
|
+
* introspection: introspection;
|
|
57
|
+
* disableMasking: true;
|
|
58
|
+
* scalars: {
|
|
59
|
+
* Bytes: string;
|
|
60
|
+
* Int8: string;
|
|
61
|
+
* BigInt: string;
|
|
62
|
+
* BigDecimal: string;
|
|
63
|
+
* Timestamp: string;
|
|
64
|
+
* };
|
|
65
|
+
* }>({
|
|
66
|
+
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
67
|
+
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
|
|
68
|
+
* subgraphName: 'kits'
|
|
69
|
+
* }, {
|
|
70
|
+
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Making GraphQL queries
|
|
74
|
+
* const query = graphql(`
|
|
75
|
+
* query SearchAssets {
|
|
76
|
+
* assets {
|
|
77
|
+
* id
|
|
78
|
+
* name
|
|
79
|
+
* symbol
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* `);
|
|
83
|
+
*
|
|
84
|
+
* const result = await client.request(query);
|
|
85
|
+
*/
|
|
86
|
+
function createTheGraphClient(options, clientOptions) {
|
|
87
|
+
ensureServer();
|
|
88
|
+
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
89
|
+
const graphql = initGraphQLTada();
|
|
90
|
+
const fullUrl = getFullUrl(validatedOptions);
|
|
91
|
+
return {
|
|
92
|
+
client: new GraphQLClient(fullUrl, {
|
|
93
|
+
...clientOptions,
|
|
94
|
+
headers: {
|
|
95
|
+
...clientOptions?.headers ?? {},
|
|
96
|
+
"x-auth-token": validatedOptions.accessToken
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
graphql
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ClientOptionsSchema, createTheGraphClient, readFragment };
|
|
105
|
+
//# sourceMappingURL=thegraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thegraph.js","names":["options: ClientOptions","instance","clientOptions?: RequestConfig"],"sources":["../src/thegraph.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod/v4\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * subgraphName: 'kits'\n * }, {\n * fetch: requestLogger(logger, \"the-graph-kits\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query SearchAssets {\n * assets {\n * id\n * name\n * symbol\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createTheGraphClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: {\n ...(clientOptions?.headers ?? {}),\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;AAcA,MAAa,sBAAsB,EAAE,OAAO;CAC1C,WAAW,EAAE,MAAM,gBAAgB;CACnC,aAAa;CACb,cAAc,EAAE,QAAQ;CACxB,OAAO,EAAE,KAAK;EAAC;EAAW;EAAe;EAAY;EAAY;EAAkB;CAAS,EAAC,CAAC,UAAU;AACzG,EAAC;;;;;;;;AAcF,SAAS,WAAWA,SAAgC;CAClD,MAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,eAAa,WAAS,UAAU,GAAG,QAAQ,aAAa,EAAE,CAAC;AACpG,MAAK,UAAU;AACb,QAAM,IAAI,OAAO,wBAAwB,QAAQ,aAAa;CAC/D;AACD,QAAO,IAAI,IAAI,UAAU,UAAU;AACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDD,SAAgB,qBACdD,SACAE,eAIA;AACA,eAAc;CACd,MAAM,mBAAmB,SAAS,qBAAqB,QAAQ;CAC/D,MAAM,UAAU,iBAAwB;CACxC,MAAM,UAAU,WAAW,iBAAiB;AAE5C,QAAO;EACL,QAAQ,IAAI,cAAc,SAAS;GACjC,GAAG;GACH,SAAS;IACP,GAAI,eAAe,WAAW,CAAE;IAChC,gBAAgB,iBAAiB;GAClC;EACF;EACD;CACD;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-thegraph",
|
|
3
3
|
"description": "TheGraph integration module for SettleMint SDK, enabling querying and indexing of blockchain data through subgraphs",
|
|
4
|
-
"version": "2.3.2-
|
|
4
|
+
"version": "2.3.2-preff27199",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": ["dist"],
|
|
24
24
|
"main": "./dist/thegraph.cjs",
|
|
25
|
-
"module": "./dist/thegraph.
|
|
25
|
+
"module": "./dist/thegraph.js",
|
|
26
26
|
"types": "./dist/thegraph.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
"./package.json": "./package.json",
|
|
29
29
|
".": {
|
|
30
30
|
"import": {
|
|
31
31
|
"types": "./dist/thegraph.d.ts",
|
|
32
|
-
"default": "./dist/thegraph.
|
|
32
|
+
"default": "./dist/thegraph.js"
|
|
33
33
|
},
|
|
34
34
|
"require": {
|
|
35
35
|
"types": "./dist/thegraph.d.cts",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"dev": "
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"dev": "tsdown --watch",
|
|
43
43
|
"publint": "publint run --strict",
|
|
44
44
|
"attw": "attw --pack .",
|
|
45
45
|
"test": "bun test",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"gql.tada": "^1",
|
|
55
|
-
"@settlemint/sdk-utils": "2.3.2-
|
|
55
|
+
"@settlemint/sdk-utils": "2.3.2-preff27199",
|
|
56
56
|
"graphql-request": "^7",
|
|
57
57
|
"zod": "^3.25.0"
|
|
58
58
|
},
|
package/dist/thegraph.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// src/thegraph.ts
|
|
2
|
-
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
3
|
-
import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
4
|
-
import { initGraphQLTada } from "gql.tada";
|
|
5
|
-
import { GraphQLClient } from "graphql-request";
|
|
6
|
-
import { z } from "zod/v4";
|
|
7
|
-
import { readFragment } from "gql.tada";
|
|
8
|
-
var ClientOptionsSchema = z.object({
|
|
9
|
-
instances: z.array(UrlOrPathSchema),
|
|
10
|
-
accessToken: ApplicationAccessTokenSchema,
|
|
11
|
-
subgraphName: z.string(),
|
|
12
|
-
cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
13
|
-
});
|
|
14
|
-
function getFullUrl(options) {
|
|
15
|
-
const instance = options.instances.find((instance2) => instance2.endsWith(`/${options.subgraphName}`));
|
|
16
|
-
if (!instance) {
|
|
17
|
-
throw new Error(`Instance for subgraph ${options.subgraphName} not found`);
|
|
18
|
-
}
|
|
19
|
-
return new URL(instance).toString();
|
|
20
|
-
}
|
|
21
|
-
function createTheGraphClient(options, clientOptions) {
|
|
22
|
-
ensureServer();
|
|
23
|
-
const validatedOptions = validate(ClientOptionsSchema, options);
|
|
24
|
-
const graphql = initGraphQLTada();
|
|
25
|
-
const fullUrl = getFullUrl(validatedOptions);
|
|
26
|
-
return {
|
|
27
|
-
client: new GraphQLClient(fullUrl, {
|
|
28
|
-
...clientOptions,
|
|
29
|
-
headers: {
|
|
30
|
-
...clientOptions?.headers ?? {},
|
|
31
|
-
"x-auth-token": validatedOptions.accessToken
|
|
32
|
-
}
|
|
33
|
-
}),
|
|
34
|
-
graphql
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export {
|
|
38
|
-
ClientOptionsSchema,
|
|
39
|
-
createTheGraphClient,
|
|
40
|
-
readFragment
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=thegraph.mjs.map
|
package/dist/thegraph.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod/v4\";\n\n/**\n * Type definition for GraphQL client configuration options\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating client options for the TheGraph client.\n */\nexport const ClientOptionsSchema = z.object({\n instances: z.array(UrlOrPathSchema),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type definition for client options derived from the ClientOptionsSchema\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Constructs the full URL for TheGraph GraphQL API based on the provided options\n *\n * @param options - The client options for configuring TheGraph client\n * @returns The complete GraphQL API URL as a string\n * @throws Will throw an error if no matching instance is found for the specified subgraph\n */\nfunction getFullUrl(options: ClientOptions): string {\n const instance = options.instances.find((instance) => instance.endsWith(`/${options.subgraphName}`));\n if (!instance) {\n throw new Error(`Instance for subgraph ${options.subgraphName} not found`);\n }\n return new URL(instance).toString();\n}\n\n/**\n * Creates a TheGraph GraphQL client with proper type safety using gql.tada\n *\n * @param options - Configuration options for the client including instance URLs,\n * access token and subgraph name\n * @param clientOptions - Optional GraphQL client configuration options\n * @returns An object containing:\n * - client: The configured GraphQL client instance\n * - graphql: The initialized gql.tada function for type-safe queries\n * @throws Will throw an error if the options fail validation against ClientOptionsSchema\n * @example\n * import { createTheGraphClient } from '@settlemint/sdk-thegraph';\n * import type { introspection } from '@schemas/the-graph-env-kits';\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * const { client, graphql } = createTheGraphClient<{\n * introspection: introspection;\n * disableMasking: true;\n * scalars: {\n * Bytes: string;\n * Int8: string;\n * BigInt: string;\n * BigDecimal: string;\n * Timestamp: string;\n * };\n * }>({\n * instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),\n * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,\n * subgraphName: 'kits'\n * }, {\n * fetch: requestLogger(logger, \"the-graph-kits\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n * query SearchAssets {\n * assets {\n * id\n * name\n * symbol\n * }\n * }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createTheGraphClient<const Setup extends AbstractSetupSchema>(\n options: ClientOptions,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n ensureServer();\n const validatedOptions = validate(ClientOptionsSchema, options);\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n headers: {\n ...(clientOptions?.headers ?? {}),\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B,iBAAiB,gBAAgB;AACxE,SAAmC,uBAAuB;AAC1D,SAAS,qBAAqB;AAC9B,SAAS,SAAS;AA6GlB,SAAS,oBAAoB;AAnGtB,IAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,WAAW,EAAE,MAAM,eAAe;AAAA,EAClC,aAAa;AAAA,EACb,cAAc,EAAE,OAAO;AAAA,EACvB,OAAO,EAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AACzG,CAAC;AAcD,SAAS,WAAW,SAAgC;AAClD,QAAM,WAAW,QAAQ,UAAU,KAAK,CAACA,cAAaA,UAAS,SAAS,IAAI,QAAQ,YAAY,EAAE,CAAC;AACnG,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,yBAAyB,QAAQ,YAAY,YAAY;AAAA,EAC3E;AACA,SAAO,IAAI,IAAI,QAAQ,EAAE,SAAS;AACpC;AAkDO,SAAS,qBACd,SACA,eAIA;AACA,eAAa;AACb,QAAM,mBAAmB,SAAS,qBAAqB,OAAO;AAC9D,QAAM,UAAU,gBAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,cAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,SAAS;AAAA,QACP,GAAI,eAAe,WAAW,CAAC;AAAA,QAC/B,gBAAgB,iBAAiB;AAAA,MACnC;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["instance"]}
|