@settlemint/sdk-thegraph 2.3.4 → 2.3.5
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 +9 -9
- package/dist/browser/thegraph.d.ts +1 -1
- package/dist/browser/thegraph.js +3 -5
- package/dist/browser/thegraph.js.map +1 -1
- package/dist/thegraph.cjs +3 -5
- package/dist/thegraph.cjs.map +1 -1
- package/dist/thegraph.d.cts +1 -1
- package/dist/thegraph.d.ts +1 -1
- package/dist/thegraph.js +3 -5
- package/dist/thegraph.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ The SDK offers a type-safe interface for all TheGraph operations, with comprehen
|
|
|
52
52
|
|
|
53
53
|
> **createTheGraphClient**\<`Setup`\>(`options`, `clientOptions?`): `object`
|
|
54
54
|
|
|
55
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:
|
|
55
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:91](https://github.com/settlemint/sdk/blob/v2.3.5/sdk/thegraph/src/thegraph.ts#L91)
|
|
56
56
|
|
|
57
57
|
Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
58
58
|
|
|
@@ -66,8 +66,8 @@ Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
|
66
66
|
|
|
67
67
|
| Parameter | Type | Description |
|
|
68
68
|
| ------ | ------ | ------ |
|
|
69
|
-
| `options` | \{ `accessToken
|
|
70
|
-
| `options.accessToken
|
|
69
|
+
| `options` | \{ `accessToken?`: `string`; `cache?`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instances`: `string`[]; `subgraphName`: `string`; \} | Configuration options for the client including instance URLs, access token and subgraph name |
|
|
70
|
+
| `options.accessToken?` | `string` | - |
|
|
71
71
|
| `options.cache?` | `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"` | - |
|
|
72
72
|
| `options.instances?` | `string`[] | - |
|
|
73
73
|
| `options.subgraphName?` | `string` | - |
|
|
@@ -83,8 +83,8 @@ An object containing:
|
|
|
83
83
|
|
|
84
84
|
| Name | Type | Defined in |
|
|
85
85
|
| ------ | ------ | ------ |
|
|
86
|
-
| `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:
|
|
87
|
-
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:
|
|
86
|
+
| `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:95](https://github.com/settlemint/sdk/blob/v2.3.5/sdk/thegraph/src/thegraph.ts#L95) |
|
|
87
|
+
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:96](https://github.com/settlemint/sdk/blob/v2.3.5/sdk/thegraph/src/thegraph.ts#L96) |
|
|
88
88
|
|
|
89
89
|
##### Throws
|
|
90
90
|
|
|
@@ -137,7 +137,7 @@ const result = await client.request(query);
|
|
|
137
137
|
|
|
138
138
|
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\>
|
|
139
139
|
|
|
140
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:
|
|
140
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:26](https://github.com/settlemint/sdk/blob/v2.3.5/sdk/thegraph/src/thegraph.ts#L26)
|
|
141
141
|
|
|
142
142
|
Type definition for client options derived from the ClientOptionsSchema
|
|
143
143
|
|
|
@@ -147,7 +147,7 @@ Type definition for client options derived from the ClientOptionsSchema
|
|
|
147
147
|
|
|
148
148
|
> **RequestConfig** = `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
|
|
149
149
|
|
|
150
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:
|
|
150
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:11](https://github.com/settlemint/sdk/blob/v2.3.5/sdk/thegraph/src/thegraph.ts#L11)
|
|
151
151
|
|
|
152
152
|
Type definition for GraphQL client configuration options
|
|
153
153
|
|
|
@@ -155,9 +155,9 @@ Type definition for GraphQL client configuration options
|
|
|
155
155
|
|
|
156
156
|
#### ClientOptionsSchema
|
|
157
157
|
|
|
158
|
-
> `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodString
|
|
158
|
+
> `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodOptional`\<`ZodString`\>; `cache`: `ZodOptional`\<`ZodEnum`\<\{ `default`: `"default"`; `force-cache`: `"force-cache"`; `no-cache`: `"no-cache"`; `no-store`: `"no-store"`; `only-if-cached`: `"only-if-cached"`; `reload`: `"reload"`; \}\>\>; `instances`: `ZodArray`\<`ZodUnion`\<readonly \[`ZodString`, `ZodString`\]\>\>; `subgraphName`: `ZodString`; \}, `$strip`\>
|
|
159
159
|
|
|
160
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:
|
|
160
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:16](https://github.com/settlemint/sdk/blob/v2.3.5/sdk/thegraph/src/thegraph.ts#L16)
|
|
161
161
|
|
|
162
162
|
Schema for validating client options for the TheGraph client.
|
|
163
163
|
|
|
@@ -15,7 +15,7 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
|
15
15
|
*/
|
|
16
16
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
17
17
|
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
|
|
18
|
-
accessToken: z.ZodString
|
|
18
|
+
accessToken: z.ZodOptional<z.ZodString>;
|
|
19
19
|
subgraphName: z.ZodString;
|
|
20
20
|
cache: z.ZodOptional<z.ZodEnum<{
|
|
21
21
|
default: "default";
|
package/dist/browser/thegraph.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendHeaders } from "@settlemint/sdk-utils/http";
|
|
1
2
|
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
2
3
|
import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
4
|
import { initGraphQLTada, readFragment } from "gql.tada";
|
|
@@ -10,7 +11,7 @@ import { z } from "zod/v4";
|
|
|
10
11
|
*/
|
|
11
12
|
const ClientOptionsSchema = z.object({
|
|
12
13
|
instances: z.array(UrlOrPathSchema),
|
|
13
|
-
accessToken: ApplicationAccessTokenSchema,
|
|
14
|
+
accessToken: ApplicationAccessTokenSchema.optional(),
|
|
14
15
|
subgraphName: z.string(),
|
|
15
16
|
cache: z.enum([
|
|
16
17
|
"default",
|
|
@@ -91,10 +92,7 @@ function createTheGraphClient(options, clientOptions) {
|
|
|
91
92
|
return {
|
|
92
93
|
client: new GraphQLClient(fullUrl, {
|
|
93
94
|
...clientOptions,
|
|
94
|
-
headers: {
|
|
95
|
-
...clientOptions?.headers ?? {},
|
|
96
|
-
"x-auth-token": validatedOptions.accessToken
|
|
97
|
-
}
|
|
95
|
+
headers: appendHeaders(clientOptions?.headers, { "x-auth-token": validatedOptions.accessToken })
|
|
98
96
|
}),
|
|
99
97
|
graphql
|
|
100
98
|
};
|
|
@@ -1 +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:
|
|
1
|
+
{"version":3,"file":"thegraph.js","names":["options: ClientOptions","instance","clientOptions?: RequestConfig"],"sources":["../../src/thegraph.ts"],"sourcesContent":["import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { 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.optional(),\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: appendHeaders(clientOptions?.headers, { \"x-auth-token\": validatedOptions.accessToken }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;AAeA,MAAa,sBAAsB,EAAE,OAAO;CAC1C,WAAW,EAAE,MAAM,gBAAgB;CACnC,aAAa,6BAA6B,UAAU;CACpD,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,cAAc,eAAe,SAAS,EAAE,gBAAgB,iBAAiB,YAAa,EAAC;EACjG;EACD;CACD;AACF"}
|
package/dist/thegraph.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
+
const __settlemint_sdk_utils_http = __toESM(require("@settlemint/sdk-utils/http"));
|
|
24
25
|
const __settlemint_sdk_utils_runtime = __toESM(require("@settlemint/sdk-utils/runtime"));
|
|
25
26
|
const __settlemint_sdk_utils_validation = __toESM(require("@settlemint/sdk-utils/validation"));
|
|
26
27
|
const gql_tada = __toESM(require("gql.tada"));
|
|
@@ -33,7 +34,7 @@ const zod_v4 = __toESM(require("zod/v4"));
|
|
|
33
34
|
*/
|
|
34
35
|
const ClientOptionsSchema = zod_v4.z.object({
|
|
35
36
|
instances: zod_v4.z.array(__settlemint_sdk_utils_validation.UrlOrPathSchema),
|
|
36
|
-
accessToken: __settlemint_sdk_utils_validation.ApplicationAccessTokenSchema,
|
|
37
|
+
accessToken: __settlemint_sdk_utils_validation.ApplicationAccessTokenSchema.optional(),
|
|
37
38
|
subgraphName: zod_v4.z.string(),
|
|
38
39
|
cache: zod_v4.z.enum([
|
|
39
40
|
"default",
|
|
@@ -114,10 +115,7 @@ function createTheGraphClient(options, clientOptions) {
|
|
|
114
115
|
return {
|
|
115
116
|
client: new graphql_request.GraphQLClient(fullUrl, {
|
|
116
117
|
...clientOptions,
|
|
117
|
-
headers: {
|
|
118
|
-
...clientOptions?.headers ?? {},
|
|
119
|
-
"x-auth-token": validatedOptions.accessToken
|
|
120
|
-
}
|
|
118
|
+
headers: (0, __settlemint_sdk_utils_http.appendHeaders)(clientOptions?.headers, { "x-auth-token": validatedOptions.accessToken })
|
|
121
119
|
}),
|
|
122
120
|
graphql
|
|
123
121
|
};
|
package/dist/thegraph.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thegraph.cjs","names":["UrlOrPathSchema","
|
|
1
|
+
{"version":3,"file":"thegraph.cjs","names":["UrlOrPathSchema","options: ClientOptions","instance","clientOptions?: RequestConfig","GraphQLClient"],"sources":["../src/thegraph.ts"],"sourcesContent":["import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { 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.optional(),\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: appendHeaders(clientOptions?.headers, { \"x-auth-token\": validatedOptions.accessToken }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,sBAAsB,SAAE,OAAO;CAC1C,WAAW,SAAE,MAAMA,kDAAgB;CACnC,aAAa,+DAA6B,UAAU;CACpD,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,+CAAc,eAAe,SAAS,EAAE,gBAAgB,iBAAiB,YAAa,EAAC;EACjG;EACD;CACD;AACF"}
|
package/dist/thegraph.d.cts
CHANGED
|
@@ -15,7 +15,7 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
|
15
15
|
*/
|
|
16
16
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
17
17
|
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
|
|
18
|
-
accessToken: z.ZodString
|
|
18
|
+
accessToken: z.ZodOptional<z.ZodString>;
|
|
19
19
|
subgraphName: z.ZodString;
|
|
20
20
|
cache: z.ZodOptional<z.ZodEnum<{
|
|
21
21
|
default: "default";
|
package/dist/thegraph.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
|
|
|
15
15
|
*/
|
|
16
16
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
17
17
|
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
|
|
18
|
-
accessToken: z.ZodString
|
|
18
|
+
accessToken: z.ZodOptional<z.ZodString>;
|
|
19
19
|
subgraphName: z.ZodString;
|
|
20
20
|
cache: z.ZodOptional<z.ZodEnum<{
|
|
21
21
|
default: "default";
|
package/dist/thegraph.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { appendHeaders } from "@settlemint/sdk-utils/http";
|
|
1
2
|
import { ensureServer } from "@settlemint/sdk-utils/runtime";
|
|
2
3
|
import { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from "@settlemint/sdk-utils/validation";
|
|
3
4
|
import { initGraphQLTada, readFragment } from "gql.tada";
|
|
@@ -10,7 +11,7 @@ import { z } from "zod/v4";
|
|
|
10
11
|
*/
|
|
11
12
|
const ClientOptionsSchema = z.object({
|
|
12
13
|
instances: z.array(UrlOrPathSchema),
|
|
13
|
-
accessToken: ApplicationAccessTokenSchema,
|
|
14
|
+
accessToken: ApplicationAccessTokenSchema.optional(),
|
|
14
15
|
subgraphName: z.string(),
|
|
15
16
|
cache: z.enum([
|
|
16
17
|
"default",
|
|
@@ -91,10 +92,7 @@ function createTheGraphClient(options, clientOptions) {
|
|
|
91
92
|
return {
|
|
92
93
|
client: new GraphQLClient(fullUrl, {
|
|
93
94
|
...clientOptions,
|
|
94
|
-
headers: {
|
|
95
|
-
...clientOptions?.headers ?? {},
|
|
96
|
-
"x-auth-token": validatedOptions.accessToken
|
|
97
|
-
}
|
|
95
|
+
headers: appendHeaders(clientOptions?.headers, { "x-auth-token": validatedOptions.accessToken })
|
|
98
96
|
}),
|
|
99
97
|
graphql
|
|
100
98
|
};
|
package/dist/thegraph.js.map
CHANGED
|
@@ -1 +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:
|
|
1
|
+
{"version":3,"file":"thegraph.js","names":["options: ClientOptions","instance","clientOptions?: RequestConfig"],"sources":["../src/thegraph.ts"],"sourcesContent":["import { appendHeaders } from \"@settlemint/sdk-utils/http\";\nimport { 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.optional(),\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: appendHeaders(clientOptions?.headers, { \"x-auth-token\": validatedOptions.accessToken }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;AAeA,MAAa,sBAAsB,EAAE,OAAO;CAC1C,WAAW,EAAE,MAAM,gBAAgB;CACnC,aAAa,6BAA6B,UAAU;CACpD,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,cAAc,eAAe,SAAS,EAAE,gBAAgB,iBAAiB,YAAa,EAAC;EACjG;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.
|
|
4
|
+
"version": "2.3.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"gql.tada": "^1",
|
|
55
|
-
"@settlemint/sdk-utils": "2.3.
|
|
55
|
+
"@settlemint/sdk-utils": "2.3.5",
|
|
56
56
|
"graphql-request": "^7",
|
|
57
57
|
"zod": "^3.25.0"
|
|
58
58
|
},
|