@settlemint/sdk-thegraph 1.1.11 → 1.1.12-maina4a29729
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 +8 -8
- package/dist/thegraph.cjs +4 -2
- package/dist/thegraph.cjs.map +1 -1
- package/dist/thegraph.d.cts +6 -0
- package/dist/thegraph.d.ts +6 -0
- package/dist/thegraph.mjs +4 -2
- package/dist/thegraph.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ For detailed information about using TheGraph with the SettleMint platform, chec
|
|
|
54
54
|
|
|
55
55
|
> **createTheGraphClient**\<`Setup`\>(`options`, `clientOptions`?): `object`
|
|
56
56
|
|
|
57
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:
|
|
57
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:119](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/thegraph/src/thegraph.ts#L119)
|
|
58
58
|
|
|
59
59
|
Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
60
60
|
|
|
@@ -68,7 +68,7 @@ Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
|
68
68
|
|
|
69
69
|
| Parameter | Type | Description |
|
|
70
70
|
| ------ | ------ | ------ |
|
|
71
|
-
| `options` | `Omit`\<\{ `accessToken`: `string`; `instances`: `string`[]; `runtime`: `"server"`; `subgraphName`: `string`; \} \| \{ `runtime`: `"browser"`; `subgraphName`: `string`; \}, `"runtime"`\> & `Record`\<`string`, `unknown`\> | Configuration options for the client: - For server-side: instance URLs, access token and subgraph name - For browser-side: just subgraph name |
|
|
71
|
+
| `options` | `Omit`\<\{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instances`: `string`[]; `runtime`: `"server"`; `subgraphName`: `string`; \} \| \{ `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `runtime`: `"browser"`; `subgraphName`: `string`; \}, `"runtime"`\> & `Record`\<`string`, `unknown`\> | Configuration options for the client: - For server-side: instance URLs, access token and subgraph name - For browser-side: just subgraph name |
|
|
72
72
|
| `clientOptions`? | `RequestConfig` | Optional GraphQL client configuration options |
|
|
73
73
|
|
|
74
74
|
##### Returns
|
|
@@ -81,8 +81,8 @@ An object containing:
|
|
|
81
81
|
|
|
82
82
|
| Name | Type | Defined in |
|
|
83
83
|
| ------ | ------ | ------ |
|
|
84
|
-
| `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:
|
|
85
|
-
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:
|
|
84
|
+
| `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:123](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/thegraph/src/thegraph.ts#L123) |
|
|
85
|
+
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:124](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/thegraph/src/thegraph.ts#L124) |
|
|
86
86
|
|
|
87
87
|
##### Throws
|
|
88
88
|
|
|
@@ -144,9 +144,9 @@ const result = await client.request(query);
|
|
|
144
144
|
|
|
145
145
|
#### ClientOptions
|
|
146
146
|
|
|
147
|
-
> **ClientOptions**: \{ `accessToken`: `string`; `instances`: `string`[]; `runtime`: `"server"`; `subgraphName`: `string`; \} \| \{ `runtime`: `"browser"`; `subgraphName`: `string`; \}
|
|
147
|
+
> **ClientOptions**: \{ `accessToken`: `string`; `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `instances`: `string`[]; `runtime`: `"server"`; `subgraphName`: `string`; \} \| \{ `cache`: `"default"` \| `"force-cache"` \| `"no-cache"` \| `"no-store"` \| `"only-if-cached"` \| `"reload"`; `runtime`: `"browser"`; `subgraphName`: `string`; \}
|
|
148
148
|
|
|
149
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:
|
|
149
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:36](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/thegraph/src/thegraph.ts#L36)
|
|
150
150
|
|
|
151
151
|
Type definition for client options derived from the ClientOptionsSchema
|
|
152
152
|
|
|
@@ -156,7 +156,7 @@ Type definition for client options derived from the ClientOptionsSchema
|
|
|
156
156
|
|
|
157
157
|
> **RequestConfig**: `ConstructorParameters`\<*typeof* `GraphQLClient`\>\[`1`\]
|
|
158
158
|
|
|
159
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:10](https://github.com/settlemint/sdk/blob/v1.1.
|
|
159
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:10](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/thegraph/src/thegraph.ts#L10)
|
|
160
160
|
|
|
161
161
|
Type definition for GraphQL client configuration options
|
|
162
162
|
|
|
@@ -166,7 +166,7 @@ Type definition for GraphQL client configuration options
|
|
|
166
166
|
|
|
167
167
|
> `const` **ClientOptionsSchema**: `ZodDiscriminatedUnion`\<[`ClientOptions`](README.md#clientoptions)\>
|
|
168
168
|
|
|
169
|
-
Defined in: [sdk/thegraph/src/thegraph.ts:18](https://github.com/settlemint/sdk/blob/v1.1.
|
|
169
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:18](https://github.com/settlemint/sdk/blob/v1.1.12/sdk/thegraph/src/thegraph.ts#L18)
|
|
170
170
|
|
|
171
171
|
Schema for validating client options for the TheGraph client.
|
|
172
172
|
Defines two possible runtime configurations:
|
package/dist/thegraph.cjs
CHANGED
|
@@ -36,11 +36,13 @@ var ClientOptionsSchema = import_zod.z.discriminatedUnion("runtime", [
|
|
|
36
36
|
instances: import_zod.z.array(import_validation.UrlOrPathSchema),
|
|
37
37
|
runtime: import_zod.z.literal("server"),
|
|
38
38
|
accessToken: import_validation.ApplicationAccessTokenSchema,
|
|
39
|
-
subgraphName: import_zod.z.string()
|
|
39
|
+
subgraphName: import_zod.z.string(),
|
|
40
|
+
cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
40
41
|
}),
|
|
41
42
|
import_zod.z.object({
|
|
42
43
|
runtime: import_zod.z.literal("browser"),
|
|
43
|
-
subgraphName: import_zod.z.string()
|
|
44
|
+
subgraphName: import_zod.z.string(),
|
|
45
|
+
cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
44
46
|
})
|
|
45
47
|
]);
|
|
46
48
|
function getFullUrl(options) {
|
package/dist/thegraph.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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\";\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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\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: 'starterkits'\n * });\n *\n * // Browser-side usage\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 * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;
|
|
1
|
+
{"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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\";\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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\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 z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\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: 'starterkits'\n * });\n *\n * // Browser-side usage\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 * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\n }),\n }),\n graphql,\n };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;AA6IlB,IAAAA,cAA6B;AAhItB,IAAM,sBAAsB,aAAE,mBAAmB,WAAW;AAAA,EACjE,aAAE,OAAO;AAAA,IACP,WAAW,aAAE,MAAM,iCAAe;AAAA,IAClC,SAAS,aAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,IACb,cAAc,aAAE,OAAO;AAAA,IACvB,OAAO,aAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,CAAC;AAAA,EACD,aAAE,OAAO;AAAA,IACP,SAAS,aAAE,QAAQ,SAAS;AAAA,IAC5B,cAAc,aAAE,OAAO;AAAA,IACvB,OAAO,aAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,CAAC;AACH,CAAC;AAcD,SAAS,WAAW,SAAgC;AAClD,MAAI,QAAQ,YAAY,UAAU;AAChC,UAAM,WAAW,QAAQ,UAAU,KAAK,CAACC,cAAaA,UAAS,SAAS,IAAI,QAAQ,YAAY,EAAE,CAAC;AACnG,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,yBAAyB,QAAQ,YAAY,YAAY;AAAA,IAC3E;AACA,WAAO,IAAI,IAAI,QAAQ,EAAE,SAAS;AAAA,EACpC;AACA,SAAO,IAAI;AAAA,IACT,2BAA2B,mBAAmB,QAAQ,YAAY,CAAC;AAAA,IACnE,QAAQ,UAAU,UAAU;AAAA,EAC9B,EAAE,SAAS;AACb;AA8DO,SAAS,qBACd,SACA,eAIA;AACA,QAAM,uBAAmB,4BAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,8BAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAI,iBAAiB,YAAY,YAAY;AAAA,QAC3C,SAAS;AAAA,UACP,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql","instance"]}
|
package/dist/thegraph.d.cts
CHANGED
|
@@ -18,25 +18,31 @@ declare const ClientOptionsSchema: z.ZodDiscriminatedUnion<"runtime", [z.ZodObje
|
|
|
18
18
|
runtime: z.ZodLiteral<"server">;
|
|
19
19
|
accessToken: z.ZodString;
|
|
20
20
|
subgraphName: z.ZodString;
|
|
21
|
+
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
21
22
|
}, "strip", z.ZodTypeAny, {
|
|
22
23
|
runtime: "server";
|
|
23
24
|
instances: string[];
|
|
24
25
|
accessToken: string;
|
|
25
26
|
subgraphName: string;
|
|
27
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
26
28
|
}, {
|
|
27
29
|
runtime: "server";
|
|
28
30
|
instances: string[];
|
|
29
31
|
accessToken: string;
|
|
30
32
|
subgraphName: string;
|
|
33
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
31
34
|
}>, z.ZodObject<{
|
|
32
35
|
runtime: z.ZodLiteral<"browser">;
|
|
33
36
|
subgraphName: z.ZodString;
|
|
37
|
+
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
34
38
|
}, "strip", z.ZodTypeAny, {
|
|
35
39
|
runtime: "browser";
|
|
36
40
|
subgraphName: string;
|
|
41
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
37
42
|
}, {
|
|
38
43
|
runtime: "browser";
|
|
39
44
|
subgraphName: string;
|
|
45
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
40
46
|
}>]>;
|
|
41
47
|
/**
|
|
42
48
|
* Type definition for client options derived from the ClientOptionsSchema
|
package/dist/thegraph.d.ts
CHANGED
|
@@ -18,25 +18,31 @@ declare const ClientOptionsSchema: z.ZodDiscriminatedUnion<"runtime", [z.ZodObje
|
|
|
18
18
|
runtime: z.ZodLiteral<"server">;
|
|
19
19
|
accessToken: z.ZodString;
|
|
20
20
|
subgraphName: z.ZodString;
|
|
21
|
+
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
21
22
|
}, "strip", z.ZodTypeAny, {
|
|
22
23
|
runtime: "server";
|
|
23
24
|
instances: string[];
|
|
24
25
|
accessToken: string;
|
|
25
26
|
subgraphName: string;
|
|
27
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
26
28
|
}, {
|
|
27
29
|
runtime: "server";
|
|
28
30
|
instances: string[];
|
|
29
31
|
accessToken: string;
|
|
30
32
|
subgraphName: string;
|
|
33
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
31
34
|
}>, z.ZodObject<{
|
|
32
35
|
runtime: z.ZodLiteral<"browser">;
|
|
33
36
|
subgraphName: z.ZodString;
|
|
37
|
+
cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>;
|
|
34
38
|
}, "strip", z.ZodTypeAny, {
|
|
35
39
|
runtime: "browser";
|
|
36
40
|
subgraphName: string;
|
|
41
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
37
42
|
}, {
|
|
38
43
|
runtime: "browser";
|
|
39
44
|
subgraphName: string;
|
|
45
|
+
cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined;
|
|
40
46
|
}>]>;
|
|
41
47
|
/**
|
|
42
48
|
* Type definition for client options derived from the ClientOptionsSchema
|
package/dist/thegraph.mjs
CHANGED
|
@@ -10,11 +10,13 @@ var ClientOptionsSchema = z.discriminatedUnion("runtime", [
|
|
|
10
10
|
instances: z.array(UrlOrPathSchema),
|
|
11
11
|
runtime: z.literal("server"),
|
|
12
12
|
accessToken: ApplicationAccessTokenSchema,
|
|
13
|
-
subgraphName: z.string()
|
|
13
|
+
subgraphName: z.string(),
|
|
14
|
+
cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
14
15
|
}),
|
|
15
16
|
z.object({
|
|
16
17
|
runtime: z.literal("browser"),
|
|
17
|
-
subgraphName: z.string()
|
|
18
|
+
subgraphName: z.string(),
|
|
19
|
+
cache: z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
|
|
18
20
|
})
|
|
19
21
|
]);
|
|
20
22
|
function getFullUrl(options) {
|
package/dist/thegraph.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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\";\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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\n accessToken: ApplicationAccessTokenSchema,\n subgraphName: z.string(),\n }),\n z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\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: 'starterkits'\n * });\n *\n * // Browser-side usage\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 * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\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;
|
|
1
|
+
{"version":3,"sources":["../src/thegraph.ts"],"sourcesContent":["import { runsOnServer } 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\";\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 * Defines two possible runtime configurations:\n * 1. Server-side with instance URLs, access token and subgraph name\n * 2. Browser-side with just subgraph name\n */\nexport const ClientOptionsSchema = z.discriminatedUnion(\"runtime\", [\n z.object({\n instances: z.array(UrlOrPathSchema),\n runtime: z.literal(\"server\"),\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 z.object({\n runtime: z.literal(\"browser\"),\n subgraphName: z.string(),\n cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n }),\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 if (options.runtime === \"server\") {\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 return new URL(\n `/proxy/thegraph/graphql/${encodeURIComponent(options.subgraphName)}`,\n window?.location?.origin ?? \"http://localhost:3000\",\n ).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:\n * - For server-side: instance URLs, access token and subgraph name\n * - For browser-side: just 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-starterkits';\n *\n * // Server-side usage\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: 'starterkits'\n * });\n *\n * // Browser-side usage\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 * subgraphName: 'starterkits'\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: Omit<ClientOptions, \"runtime\"> & Record<string, unknown>,\n clientOptions?: RequestConfig,\n): {\n client: GraphQLClient;\n graphql: initGraphQLTada<Setup>;\n} {\n const validatedOptions = validate(ClientOptionsSchema, {\n ...options,\n runtime: runsOnServer ? \"server\" : \"browser\",\n });\n const graphql = initGraphQLTada<Setup>();\n const fullUrl = getFullUrl(validatedOptions);\n\n return {\n client: new GraphQLClient(fullUrl, {\n ...clientOptions,\n ...(validatedOptions.runtime === \"server\" && {\n headers: {\n \"x-auth-token\": validatedOptions.accessToken,\n },\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;AA6IlB,SAAS,oBAAoB;AAhItB,IAAM,sBAAsB,EAAE,mBAAmB,WAAW;AAAA,EACjE,EAAE,OAAO;AAAA,IACP,WAAW,EAAE,MAAM,eAAe;AAAA,IAClC,SAAS,EAAE,QAAQ,QAAQ;AAAA,IAC3B,aAAa;AAAA,IACb,cAAc,EAAE,OAAO;AAAA,IACvB,OAAO,EAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,CAAC;AAAA,EACD,EAAE,OAAO;AAAA,IACP,SAAS,EAAE,QAAQ,SAAS;AAAA,IAC5B,cAAc,EAAE,OAAO;AAAA,IACvB,OAAO,EAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzG,CAAC;AACH,CAAC;AAcD,SAAS,WAAW,SAAgC;AAClD,MAAI,QAAQ,YAAY,UAAU;AAChC,UAAM,WAAW,QAAQ,UAAU,KAAK,CAACA,cAAaA,UAAS,SAAS,IAAI,QAAQ,YAAY,EAAE,CAAC;AACnG,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,yBAAyB,QAAQ,YAAY,YAAY;AAAA,IAC3E;AACA,WAAO,IAAI,IAAI,QAAQ,EAAE,SAAS;AAAA,EACpC;AACA,SAAO,IAAI;AAAA,IACT,2BAA2B,mBAAmB,QAAQ,YAAY,CAAC;AAAA,IACnE,QAAQ,UAAU,UAAU;AAAA,EAC9B,EAAE,SAAS;AACb;AA8DO,SAAS,qBACd,SACA,eAIA;AACA,QAAM,mBAAmB,SAAS,qBAAqB;AAAA,IACrD,GAAG;AAAA,IACH,SAAS,eAAe,WAAW;AAAA,EACrC,CAAC;AACD,QAAM,UAAU,gBAAuB;AACvC,QAAM,UAAU,WAAW,gBAAgB;AAE3C,SAAO;AAAA,IACL,QAAQ,IAAI,cAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,GAAI,iBAAiB,YAAY,YAAY;AAAA,QAC3C,SAAS;AAAA,UACP,gBAAgB,iBAAiB;AAAA,QACnC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["instance"]}
|
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": "1.1.
|
|
4
|
+
"version": "1.1.12-maina4a29729",
|
|
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": "1.1.
|
|
55
|
+
"@settlemint/sdk-utils": "1.1.12-maina4a29729",
|
|
56
56
|
"graphql-request": "^7",
|
|
57
57
|
"zod": "^3"
|
|
58
58
|
},
|