@settlemint/sdk-thegraph 1.1.13 → 1.1.14
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/thegraph.cjs.map +1 -1
- package/dist/thegraph.d.cts +3 -3
- package/dist/thegraph.d.ts +3 -3
- 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:119](https://github.com/settlemint/sdk/blob/v1.1.
|
|
57
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:119](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/thegraph/src/thegraph.ts#L119)
|
|
58
58
|
|
|
59
59
|
Creates a TheGraph GraphQL client with proper type safety using gql.tada
|
|
60
60
|
|
|
@@ -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:123](https://github.com/settlemint/sdk/blob/v1.1.
|
|
85
|
-
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:124](https://github.com/settlemint/sdk/blob/v1.1.
|
|
84
|
+
| `client` | `GraphQLClient` | [sdk/thegraph/src/thegraph.ts:123](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/thegraph/src/thegraph.ts#L123) |
|
|
85
|
+
| `graphql` | `initGraphQLTada`\<`Setup`\> | [sdk/thegraph/src/thegraph.ts:124](https://github.com/settlemint/sdk/blob/v1.1.14/sdk/thegraph/src/thegraph.ts#L124) |
|
|
86
86
|
|
|
87
87
|
##### Throws
|
|
88
88
|
|
|
@@ -92,7 +92,7 @@ Will throw an error if the options fail validation against ClientOptionsSchema
|
|
|
92
92
|
|
|
93
93
|
```ts
|
|
94
94
|
import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
95
|
-
import type { introspection } from '@schemas/the-graph-env-
|
|
95
|
+
import type { introspection } from '@schemas/the-graph-env-kits';
|
|
96
96
|
|
|
97
97
|
// Server-side usage
|
|
98
98
|
const { client, graphql } = createTheGraphClient<{
|
|
@@ -108,7 +108,7 @@ const { client, graphql } = createTheGraphClient<{
|
|
|
108
108
|
}>({
|
|
109
109
|
instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
110
110
|
accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
111
|
-
subgraphName: '
|
|
111
|
+
subgraphName: 'kits'
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
// Browser-side usage
|
|
@@ -123,7 +123,7 @@ const { client, graphql } = createTheGraphClient<{
|
|
|
123
123
|
Timestamp: string;
|
|
124
124
|
};
|
|
125
125
|
}>({
|
|
126
|
-
subgraphName: '
|
|
126
|
+
subgraphName: 'kits'
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
// Making GraphQL queries
|
|
@@ -146,7 +146,7 @@ const result = await client.request(query);
|
|
|
146
146
|
|
|
147
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:36](https://github.com/settlemint/sdk/blob/v1.1.
|
|
149
|
+
Defined in: [sdk/thegraph/src/thegraph.ts:36](https://github.com/settlemint/sdk/blob/v1.1.14/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.14/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.14/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.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 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-
|
|
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-kits';\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: 'kits'\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: 'kits'\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
|
@@ -61,7 +61,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
61
61
|
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
|
|
62
62
|
* @example
|
|
63
63
|
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
64
|
-
* import type { introspection } from '@schemas/the-graph-env-
|
|
64
|
+
* import type { introspection } from '@schemas/the-graph-env-kits';
|
|
65
65
|
*
|
|
66
66
|
* // Server-side usage
|
|
67
67
|
* const { client, graphql } = createTheGraphClient<{
|
|
@@ -77,7 +77,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
77
77
|
* }>({
|
|
78
78
|
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
79
79
|
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
80
|
-
* subgraphName: '
|
|
80
|
+
* subgraphName: 'kits'
|
|
81
81
|
* });
|
|
82
82
|
*
|
|
83
83
|
* // Browser-side usage
|
|
@@ -92,7 +92,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
92
92
|
* Timestamp: string;
|
|
93
93
|
* };
|
|
94
94
|
* }>({
|
|
95
|
-
* subgraphName: '
|
|
95
|
+
* subgraphName: 'kits'
|
|
96
96
|
* });
|
|
97
97
|
*
|
|
98
98
|
* // Making GraphQL queries
|
package/dist/thegraph.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
61
61
|
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
|
|
62
62
|
* @example
|
|
63
63
|
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
|
|
64
|
-
* import type { introspection } from '@schemas/the-graph-env-
|
|
64
|
+
* import type { introspection } from '@schemas/the-graph-env-kits';
|
|
65
65
|
*
|
|
66
66
|
* // Server-side usage
|
|
67
67
|
* const { client, graphql } = createTheGraphClient<{
|
|
@@ -77,7 +77,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
77
77
|
* }>({
|
|
78
78
|
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
|
|
79
79
|
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN!,
|
|
80
|
-
* subgraphName: '
|
|
80
|
+
* subgraphName: 'kits'
|
|
81
81
|
* });
|
|
82
82
|
*
|
|
83
83
|
* // Browser-side usage
|
|
@@ -92,7 +92,7 @@ type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
|
92
92
|
* Timestamp: string;
|
|
93
93
|
* };
|
|
94
94
|
* }>({
|
|
95
|
-
* subgraphName: '
|
|
95
|
+
* subgraphName: 'kits'
|
|
96
96
|
* });
|
|
97
97
|
*
|
|
98
98
|
* // Making GraphQL queries
|
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 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-
|
|
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-kits';\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: 'kits'\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: 'kits'\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.14",
|
|
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.14",
|
|
56
56
|
"graphql-request": "^7",
|
|
57
57
|
"zod": "^3"
|
|
58
58
|
},
|