@soda-gql/core 0.9.0 → 0.9.1
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 +67 -0
- package/dist/adapter.cjs +50 -3
- package/dist/adapter.cjs.map +1 -1
- package/dist/adapter.d.cts +52 -5
- package/dist/adapter.d.cts.map +1 -1
- package/dist/adapter.d.ts +52 -5
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +50 -3
- package/dist/adapter.js.map +1 -1
- package/dist/{index-Ib9pb2Si.d.cts → index-B_TU5U2U.d.ts} +11 -4
- package/dist/{index-wkJ6KSwK.d.ts.map → index-B_TU5U2U.d.ts.map} +1 -1
- package/dist/{schema-2qqtKss4.d.ts → index-BlVgxrXb.d.ts} +371 -300
- package/dist/index-BlVgxrXb.d.ts.map +1 -0
- package/dist/{index-wkJ6KSwK.d.ts → index-_6fYTfcA.d.cts} +11 -4
- package/dist/{index-Ib9pb2Si.d.cts.map → index-_6fYTfcA.d.cts.map} +1 -1
- package/dist/{schema-CPTxQbTv.d.cts → index-zCOsREx0.d.cts} +371 -300
- package/dist/index-zCOsREx0.d.cts.map +1 -0
- package/dist/index.cjs +47 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +47 -15
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/{schema-builder-BYJd50o2.d.cts → schema-builder-BI5PQkH7.d.cts} +2 -2
- package/dist/{schema-builder-BYJd50o2.d.cts.map → schema-builder-BI5PQkH7.d.cts.map} +1 -1
- package/dist/{schema-builder-Dhss2O1I.d.ts → schema-builder-CF_AwsOM.d.ts} +2 -2
- package/dist/{schema-builder-Dhss2O1I.d.ts.map → schema-builder-CF_AwsOM.d.ts.map} +1 -1
- package/package.json +1 -1
- package/dist/schema-2qqtKss4.d.ts.map +0 -1
- package/dist/schema-CPTxQbTv.d.cts.map +0 -1
package/README.md
CHANGED
|
@@ -251,6 +251,73 @@ $var.getVariablePath(varRef, (p) => p.profile.name);
|
|
|
251
251
|
// Returns: ["$user", "name"] (variable name + path after variable reference point)
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
## Adapter
|
|
255
|
+
|
|
256
|
+
Adapters customize the behavior of your GraphQL system with helpers, metadata configuration, and document transformation.
|
|
257
|
+
|
|
258
|
+
### Basic Usage
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
import { defineAdapter } from "@soda-gql/core/adapter";
|
|
262
|
+
|
|
263
|
+
const adapter = defineAdapter({
|
|
264
|
+
helpers: {
|
|
265
|
+
auth: {
|
|
266
|
+
requiresLogin: () => ({ requiresAuth: true }),
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
metadata: {
|
|
270
|
+
aggregateFragmentMetadata: (fragments) => ({
|
|
271
|
+
count: fragments.length,
|
|
272
|
+
}),
|
|
273
|
+
schemaLevel: { apiVersion: "v2" },
|
|
274
|
+
},
|
|
275
|
+
transformDocument: ({ document, operationType }) => {
|
|
276
|
+
// Schema-wide document transformation
|
|
277
|
+
return document;
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Document Transform
|
|
283
|
+
|
|
284
|
+
Operations can also define their own transform with typed metadata:
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
gql.default(({ query, $var }) =>
|
|
288
|
+
query.operation({
|
|
289
|
+
name: "GetUser",
|
|
290
|
+
metadata: () => ({ cacheHint: 300 }),
|
|
291
|
+
transformDocument: ({ document, metadata }) => {
|
|
292
|
+
// metadata is typed as { cacheHint: number }
|
|
293
|
+
return document;
|
|
294
|
+
},
|
|
295
|
+
fields: ({ f, $ }) => ({ ... }),
|
|
296
|
+
}),
|
|
297
|
+
);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Best Practice:** Define transform logic in helpers for reusability:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const adapter = defineAdapter({
|
|
304
|
+
helpers: {
|
|
305
|
+
transform: {
|
|
306
|
+
addCache: (ttl: number) => ({ document }) => {
|
|
307
|
+
// Transform logic here
|
|
308
|
+
return document;
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// Use helper in operation
|
|
315
|
+
query.operation({
|
|
316
|
+
transformDocument: transform.addCache(300),
|
|
317
|
+
...
|
|
318
|
+
});
|
|
319
|
+
```
|
|
320
|
+
|
|
254
321
|
## Runtime Exports
|
|
255
322
|
|
|
256
323
|
The `/runtime` subpath provides utilities for operation registration and retrieval:
|
package/dist/adapter.cjs
CHANGED
|
@@ -2,10 +2,10 @@ const require_schema = require('./schema-D2MW4DOF.cjs');
|
|
|
2
2
|
|
|
3
3
|
//#region packages/core/src/adapter/define-adapter.ts
|
|
4
4
|
/**
|
|
5
|
-
* Helper function for defining a unified adapter with helpers and
|
|
6
|
-
* Provides type inference for helpers, aggregateFragmentMetadata and
|
|
5
|
+
* Helper function for defining a unified adapter with helpers, metadata, and document transformation.
|
|
6
|
+
* Provides type inference for helpers, aggregateFragmentMetadata, schemaLevel, and transformDocument.
|
|
7
7
|
*
|
|
8
|
-
* @example
|
|
8
|
+
* @example Basic adapter with helpers and metadata
|
|
9
9
|
* ```typescript
|
|
10
10
|
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
11
11
|
* import type { FragmentMetaInfo, OperationMetadata } from "@soda-gql/core";
|
|
@@ -26,6 +26,53 @@ const require_schema = require('./schema-D2MW4DOF.cjs');
|
|
|
26
26
|
* },
|
|
27
27
|
* });
|
|
28
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Adapter with document transformation
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
33
|
+
* import { Kind, visit } from "graphql";
|
|
34
|
+
*
|
|
35
|
+
* export const adapter = defineAdapter({
|
|
36
|
+
* transformDocument: ({ document, operationType }) => {
|
|
37
|
+
* // Add @auth directive to all queries
|
|
38
|
+
* if (operationType === "query") {
|
|
39
|
+
* return visit(document, {
|
|
40
|
+
* OperationDefinition: (node) => ({
|
|
41
|
+
* ...node,
|
|
42
|
+
* directives: [
|
|
43
|
+
* ...(node.directives ?? []),
|
|
44
|
+
* { kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: "auth" } },
|
|
45
|
+
* ],
|
|
46
|
+
* }),
|
|
47
|
+
* });
|
|
48
|
+
* }
|
|
49
|
+
* return document;
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Using helpers for operation-level transform functions (recommended)
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Define transform functions as helpers for reusability
|
|
57
|
+
* const adapter = defineAdapter({
|
|
58
|
+
* helpers: {
|
|
59
|
+
* transform: {
|
|
60
|
+
* addCacheDirective: (ttl: number) => ({ document }) => {
|
|
61
|
+
* return visit(document, { ... });
|
|
62
|
+
* },
|
|
63
|
+
* },
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // Use helper in operation - clean and declarative
|
|
68
|
+
* gql(({ query, transform }) =>
|
|
69
|
+
* query.operation({
|
|
70
|
+
* name: "GetUser",
|
|
71
|
+
* transformDocument: transform.addCacheDirective(300),
|
|
72
|
+
* fields: ({ f }) => ({ ... }),
|
|
73
|
+
* }),
|
|
74
|
+
* );
|
|
75
|
+
* ```
|
|
29
76
|
*/
|
|
30
77
|
const defineAdapter = (adapter) => adapter;
|
|
31
78
|
|
package/dist/adapter.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.cjs","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":["import type { Adapter } from \"../types/metadata\";\n\n/**\n * Helper function for defining a unified adapter with helpers and
|
|
1
|
+
{"version":3,"file":"adapter.cjs","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":["import type { Adapter } from \"../types/metadata\";\n\n/**\n * Helper function for defining a unified adapter with helpers, metadata, and document transformation.\n * Provides type inference for helpers, aggregateFragmentMetadata, schemaLevel, and transformDocument.\n *\n * @example Basic adapter with helpers and metadata\n * ```typescript\n * import { defineAdapter } from \"@soda-gql/core/adapter\";\n * import type { FragmentMetaInfo, OperationMetadata } from \"@soda-gql/core\";\n *\n * export const adapter = defineAdapter({\n * helpers: {\n * auth: {\n * requiresLogin: () => ({ requiresAuth: true }),\n * adminOnly: () => ({ requiresAuth: true, role: \"admin\" }),\n * },\n * },\n * metadata: {\n * aggregateFragmentMetadata: (fragments: readonly FragmentMetaInfo<OperationMetadata>[]) =>\n * fragments.map((m) => m.metadata),\n * schemaLevel: {\n * apiVersion: \"v2\",\n * },\n * },\n * });\n * ```\n *\n * @example Adapter with document transformation\n * ```typescript\n * import { defineAdapter } from \"@soda-gql/core/adapter\";\n * import { Kind, visit } from \"graphql\";\n *\n * export const adapter = defineAdapter({\n * transformDocument: ({ document, operationType }) => {\n * // Add @auth directive to all queries\n * if (operationType === \"query\") {\n * return visit(document, {\n * OperationDefinition: (node) => ({\n * ...node,\n * directives: [\n * ...(node.directives ?? []),\n * { kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: \"auth\" } },\n * ],\n * }),\n * });\n * }\n * return document;\n * },\n * });\n * ```\n *\n * @example Using helpers for operation-level transform functions (recommended)\n * ```typescript\n * // Define transform functions as helpers for reusability\n * const adapter = defineAdapter({\n * helpers: {\n * transform: {\n * addCacheDirective: (ttl: number) => ({ document }) => {\n * return visit(document, { ... });\n * },\n * },\n * },\n * });\n *\n * // Use helper in operation - clean and declarative\n * gql(({ query, transform }) =>\n * query.operation({\n * name: \"GetUser\",\n * transformDocument: transform.addCacheDirective(300),\n * fields: ({ f }) => ({ ... }),\n * }),\n * );\n * ```\n */\nexport const defineAdapter = <\n THelpers extends object = object,\n TFragmentMetadata = unknown,\n TAggregatedFragmentMetadata = unknown,\n TSchemaLevel = unknown,\n>(\n adapter: Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel>,\n): Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel> => adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,MAAa,iBAMX,YACoF"}
|
package/dist/adapter.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as defineScalar } from "./schema-builder-
|
|
1
|
+
import { t as Adapter } from "./index-zCOsREx0.cjs";
|
|
2
|
+
import { r as defineScalar } from "./schema-builder-BI5PQkH7.cjs";
|
|
3
3
|
|
|
4
4
|
//#region packages/core/src/adapter/define-adapter.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Helper function for defining a unified adapter with helpers and
|
|
8
|
-
* Provides type inference for helpers, aggregateFragmentMetadata and
|
|
7
|
+
* Helper function for defining a unified adapter with helpers, metadata, and document transformation.
|
|
8
|
+
* Provides type inference for helpers, aggregateFragmentMetadata, schemaLevel, and transformDocument.
|
|
9
9
|
*
|
|
10
|
-
* @example
|
|
10
|
+
* @example Basic adapter with helpers and metadata
|
|
11
11
|
* ```typescript
|
|
12
12
|
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
13
13
|
* import type { FragmentMetaInfo, OperationMetadata } from "@soda-gql/core";
|
|
@@ -28,6 +28,53 @@ import { r as defineScalar } from "./schema-builder-BYJd50o2.cjs";
|
|
|
28
28
|
* },
|
|
29
29
|
* });
|
|
30
30
|
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Adapter with document transformation
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
35
|
+
* import { Kind, visit } from "graphql";
|
|
36
|
+
*
|
|
37
|
+
* export const adapter = defineAdapter({
|
|
38
|
+
* transformDocument: ({ document, operationType }) => {
|
|
39
|
+
* // Add @auth directive to all queries
|
|
40
|
+
* if (operationType === "query") {
|
|
41
|
+
* return visit(document, {
|
|
42
|
+
* OperationDefinition: (node) => ({
|
|
43
|
+
* ...node,
|
|
44
|
+
* directives: [
|
|
45
|
+
* ...(node.directives ?? []),
|
|
46
|
+
* { kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: "auth" } },
|
|
47
|
+
* ],
|
|
48
|
+
* }),
|
|
49
|
+
* });
|
|
50
|
+
* }
|
|
51
|
+
* return document;
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Using helpers for operation-level transform functions (recommended)
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Define transform functions as helpers for reusability
|
|
59
|
+
* const adapter = defineAdapter({
|
|
60
|
+
* helpers: {
|
|
61
|
+
* transform: {
|
|
62
|
+
* addCacheDirective: (ttl: number) => ({ document }) => {
|
|
63
|
+
* return visit(document, { ... });
|
|
64
|
+
* },
|
|
65
|
+
* },
|
|
66
|
+
* },
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Use helper in operation - clean and declarative
|
|
70
|
+
* gql(({ query, transform }) =>
|
|
71
|
+
* query.operation({
|
|
72
|
+
* name: "GetUser",
|
|
73
|
+
* transformDocument: transform.addCacheDirective(300),
|
|
74
|
+
* fields: ({ f }) => ({ ... }),
|
|
75
|
+
* }),
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
31
78
|
*/
|
|
32
79
|
declare const defineAdapter: <THelpers extends object = object, TFragmentMetadata = unknown, TAggregatedFragmentMetadata = unknown, TSchemaLevel = unknown>(adapter: Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel>) => Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel>;
|
|
33
80
|
//#endregion
|
package/dist/adapter.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.cts","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"adapter.d.cts","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA2EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,uJAMF,QAAQ,UAAU,mBAAmB,6BAA6B,kBAC1E,QAAQ,UAAU,mBAAmB,6BAA6B"}
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as defineScalar } from "./schema-builder-
|
|
1
|
+
import { t as Adapter } from "./index-BlVgxrXb.js";
|
|
2
|
+
import { r as defineScalar } from "./schema-builder-CF_AwsOM.js";
|
|
3
3
|
|
|
4
4
|
//#region packages/core/src/adapter/define-adapter.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Helper function for defining a unified adapter with helpers and
|
|
8
|
-
* Provides type inference for helpers, aggregateFragmentMetadata and
|
|
7
|
+
* Helper function for defining a unified adapter with helpers, metadata, and document transformation.
|
|
8
|
+
* Provides type inference for helpers, aggregateFragmentMetadata, schemaLevel, and transformDocument.
|
|
9
9
|
*
|
|
10
|
-
* @example
|
|
10
|
+
* @example Basic adapter with helpers and metadata
|
|
11
11
|
* ```typescript
|
|
12
12
|
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
13
13
|
* import type { FragmentMetaInfo, OperationMetadata } from "@soda-gql/core";
|
|
@@ -28,6 +28,53 @@ import { r as defineScalar } from "./schema-builder-Dhss2O1I.js";
|
|
|
28
28
|
* },
|
|
29
29
|
* });
|
|
30
30
|
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Adapter with document transformation
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
35
|
+
* import { Kind, visit } from "graphql";
|
|
36
|
+
*
|
|
37
|
+
* export const adapter = defineAdapter({
|
|
38
|
+
* transformDocument: ({ document, operationType }) => {
|
|
39
|
+
* // Add @auth directive to all queries
|
|
40
|
+
* if (operationType === "query") {
|
|
41
|
+
* return visit(document, {
|
|
42
|
+
* OperationDefinition: (node) => ({
|
|
43
|
+
* ...node,
|
|
44
|
+
* directives: [
|
|
45
|
+
* ...(node.directives ?? []),
|
|
46
|
+
* { kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: "auth" } },
|
|
47
|
+
* ],
|
|
48
|
+
* }),
|
|
49
|
+
* });
|
|
50
|
+
* }
|
|
51
|
+
* return document;
|
|
52
|
+
* },
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Using helpers for operation-level transform functions (recommended)
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Define transform functions as helpers for reusability
|
|
59
|
+
* const adapter = defineAdapter({
|
|
60
|
+
* helpers: {
|
|
61
|
+
* transform: {
|
|
62
|
+
* addCacheDirective: (ttl: number) => ({ document }) => {
|
|
63
|
+
* return visit(document, { ... });
|
|
64
|
+
* },
|
|
65
|
+
* },
|
|
66
|
+
* },
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Use helper in operation - clean and declarative
|
|
70
|
+
* gql(({ query, transform }) =>
|
|
71
|
+
* query.operation({
|
|
72
|
+
* name: "GetUser",
|
|
73
|
+
* transformDocument: transform.addCacheDirective(300),
|
|
74
|
+
* fields: ({ f }) => ({ ... }),
|
|
75
|
+
* }),
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
31
78
|
*/
|
|
32
79
|
declare const defineAdapter: <THelpers extends object = object, TFragmentMetadata = unknown, TAggregatedFragmentMetadata = unknown, TSchemaLevel = unknown>(adapter: Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel>) => Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel>;
|
|
33
80
|
//#endregion
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA2EA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,uJAMF,QAAQ,UAAU,mBAAmB,6BAA6B,kBAC1E,QAAQ,UAAU,mBAAmB,6BAA6B"}
|
package/dist/adapter.js
CHANGED
|
@@ -2,10 +2,10 @@ import { r as defineScalar } from "./schema-BiYcVVvm.js";
|
|
|
2
2
|
|
|
3
3
|
//#region packages/core/src/adapter/define-adapter.ts
|
|
4
4
|
/**
|
|
5
|
-
* Helper function for defining a unified adapter with helpers and
|
|
6
|
-
* Provides type inference for helpers, aggregateFragmentMetadata and
|
|
5
|
+
* Helper function for defining a unified adapter with helpers, metadata, and document transformation.
|
|
6
|
+
* Provides type inference for helpers, aggregateFragmentMetadata, schemaLevel, and transformDocument.
|
|
7
7
|
*
|
|
8
|
-
* @example
|
|
8
|
+
* @example Basic adapter with helpers and metadata
|
|
9
9
|
* ```typescript
|
|
10
10
|
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
11
11
|
* import type { FragmentMetaInfo, OperationMetadata } from "@soda-gql/core";
|
|
@@ -26,6 +26,53 @@ import { r as defineScalar } from "./schema-BiYcVVvm.js";
|
|
|
26
26
|
* },
|
|
27
27
|
* });
|
|
28
28
|
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Adapter with document transformation
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { defineAdapter } from "@soda-gql/core/adapter";
|
|
33
|
+
* import { Kind, visit } from "graphql";
|
|
34
|
+
*
|
|
35
|
+
* export const adapter = defineAdapter({
|
|
36
|
+
* transformDocument: ({ document, operationType }) => {
|
|
37
|
+
* // Add @auth directive to all queries
|
|
38
|
+
* if (operationType === "query") {
|
|
39
|
+
* return visit(document, {
|
|
40
|
+
* OperationDefinition: (node) => ({
|
|
41
|
+
* ...node,
|
|
42
|
+
* directives: [
|
|
43
|
+
* ...(node.directives ?? []),
|
|
44
|
+
* { kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: "auth" } },
|
|
45
|
+
* ],
|
|
46
|
+
* }),
|
|
47
|
+
* });
|
|
48
|
+
* }
|
|
49
|
+
* return document;
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Using helpers for operation-level transform functions (recommended)
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Define transform functions as helpers for reusability
|
|
57
|
+
* const adapter = defineAdapter({
|
|
58
|
+
* helpers: {
|
|
59
|
+
* transform: {
|
|
60
|
+
* addCacheDirective: (ttl: number) => ({ document }) => {
|
|
61
|
+
* return visit(document, { ... });
|
|
62
|
+
* },
|
|
63
|
+
* },
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* // Use helper in operation - clean and declarative
|
|
68
|
+
* gql(({ query, transform }) =>
|
|
69
|
+
* query.operation({
|
|
70
|
+
* name: "GetUser",
|
|
71
|
+
* transformDocument: transform.addCacheDirective(300),
|
|
72
|
+
* fields: ({ f }) => ({ ... }),
|
|
73
|
+
* }),
|
|
74
|
+
* );
|
|
75
|
+
* ```
|
|
29
76
|
*/
|
|
30
77
|
const defineAdapter = (adapter) => adapter;
|
|
31
78
|
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":["import type { Adapter } from \"../types/metadata\";\n\n/**\n * Helper function for defining a unified adapter with helpers and
|
|
1
|
+
{"version":3,"file":"adapter.js","names":[],"sources":["../src/adapter/define-adapter.ts"],"sourcesContent":["import type { Adapter } from \"../types/metadata\";\n\n/**\n * Helper function for defining a unified adapter with helpers, metadata, and document transformation.\n * Provides type inference for helpers, aggregateFragmentMetadata, schemaLevel, and transformDocument.\n *\n * @example Basic adapter with helpers and metadata\n * ```typescript\n * import { defineAdapter } from \"@soda-gql/core/adapter\";\n * import type { FragmentMetaInfo, OperationMetadata } from \"@soda-gql/core\";\n *\n * export const adapter = defineAdapter({\n * helpers: {\n * auth: {\n * requiresLogin: () => ({ requiresAuth: true }),\n * adminOnly: () => ({ requiresAuth: true, role: \"admin\" }),\n * },\n * },\n * metadata: {\n * aggregateFragmentMetadata: (fragments: readonly FragmentMetaInfo<OperationMetadata>[]) =>\n * fragments.map((m) => m.metadata),\n * schemaLevel: {\n * apiVersion: \"v2\",\n * },\n * },\n * });\n * ```\n *\n * @example Adapter with document transformation\n * ```typescript\n * import { defineAdapter } from \"@soda-gql/core/adapter\";\n * import { Kind, visit } from \"graphql\";\n *\n * export const adapter = defineAdapter({\n * transformDocument: ({ document, operationType }) => {\n * // Add @auth directive to all queries\n * if (operationType === \"query\") {\n * return visit(document, {\n * OperationDefinition: (node) => ({\n * ...node,\n * directives: [\n * ...(node.directives ?? []),\n * { kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: \"auth\" } },\n * ],\n * }),\n * });\n * }\n * return document;\n * },\n * });\n * ```\n *\n * @example Using helpers for operation-level transform functions (recommended)\n * ```typescript\n * // Define transform functions as helpers for reusability\n * const adapter = defineAdapter({\n * helpers: {\n * transform: {\n * addCacheDirective: (ttl: number) => ({ document }) => {\n * return visit(document, { ... });\n * },\n * },\n * },\n * });\n *\n * // Use helper in operation - clean and declarative\n * gql(({ query, transform }) =>\n * query.operation({\n * name: \"GetUser\",\n * transformDocument: transform.addCacheDirective(300),\n * fields: ({ f }) => ({ ... }),\n * }),\n * );\n * ```\n */\nexport const defineAdapter = <\n THelpers extends object = object,\n TFragmentMetadata = unknown,\n TAggregatedFragmentMetadata = unknown,\n TSchemaLevel = unknown,\n>(\n adapter: Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel>,\n): Adapter<THelpers, TFragmentMetadata, TAggregatedFragmentMetadata, TSchemaLevel> => adapter;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,MAAa,iBAMX,YACoF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as ConstValue, B as UnionMemberName, C as AnyFieldName, D as InferInputKind, F as OperationType, H as AnyVarRef, I as PickTypeSpecifierByFieldName, K as VarRef, L as ResolveInputProfileFromMeta, Mt as FieldPath, N as ObjectFieldRecord, O as InferInputProfile, S as AllInputTypeNames, T as AnyTypeName, U as AnyVarRefBrand, X as AnyDefaultValue, _ as FragmentMetadataBuilder, _t as PrimitiveTypeProfile, a as DefaultMetadataAdapter, at as OutputEnumSpecifier, bt as GetSignature, c as ExtractAdapterTypes, ct as OutputScalarSpecifier, ft as OutputTypenameSpecifier, gt as ObjectTypeProfile, ht as GetModifiedType, i as DefaultAdapter, it as InputTypeSpecifiers, k as InferOutputProfile, mt as GetConstAssignableType, n as AnyAdapter, nt as InputTypeKind, ot as OutputInferrableTypeSpecifier, p as OperationDocumentTransformer, pt as OutputUnionSpecifier, r as AnyMetadataAdapter, rt as InputTypeSpecifier, s as DocumentTransformer, st as OutputObjectSpecifier, t as Adapter, ut as OutputTypeSpecifier, vt as TypeProfile, w as AnyGraphqlSchema, xt as TypeModifier, y as MetadataBuilder, yt as ApplyTypeModifier } from "./index-BlVgxrXb.js";
|
|
2
2
|
import { ConstValueNode, NamedTypeNode, OperationTypeNode, TypeNode, ValueNode } from "graphql";
|
|
3
3
|
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
4
4
|
|
|
@@ -1074,8 +1074,10 @@ declare const createVarBuilder: <TSchema extends AnyGraphqlSchema>(inputTypeMeth
|
|
|
1074
1074
|
type GqlElementComposer<TContext> = <TResult extends AnyFragment | AnyOperation>(composeElement: (context: TContext) => TResult) => TResult;
|
|
1075
1075
|
/**
|
|
1076
1076
|
* Extracts the helpers type from an adapter.
|
|
1077
|
+
* Uses `any` for non-target type parameters to avoid contravariance issues
|
|
1078
|
+
* with the `aggregateFragmentMetadata` function parameter type.
|
|
1077
1079
|
*/
|
|
1078
|
-
type ExtractHelpers<TAdapter extends AnyAdapter> = TAdapter extends Adapter<infer THelpers,
|
|
1080
|
+
type ExtractHelpers<TAdapter extends AnyAdapter> = TAdapter extends Adapter<infer THelpers, any, any, any> ? THelpers : object;
|
|
1079
1081
|
/**
|
|
1080
1082
|
* Extracts the metadata adapter type from an adapter.
|
|
1081
1083
|
* Handles optional metadata property correctly.
|
|
@@ -1140,6 +1142,7 @@ declare const createGqlElementComposer: <TSchema extends AnyGraphqlSchema, TFrag
|
|
|
1140
1142
|
variables?: TVarDefinitions | undefined;
|
|
1141
1143
|
metadata?: MetadataBuilder<DeclaredVariables<TSchema, TVarDefinitions>, TOperationMetadata, ExtractAdapterTypes<ExtractMetadataAdapter<TAdapter>>["aggregatedFragmentMetadata"], ExtractAdapterTypes<ExtractMetadataAdapter<TAdapter>>["schemaLevel"]> | undefined;
|
|
1142
1144
|
fields: FieldsBuilder<TSchema, TSchema["operations"]["query"] & keyof TSchema["object"] & string, TVarDefinitions, TFields>;
|
|
1145
|
+
transformDocument?: OperationDocumentTransformer<TOperationMetadata> | undefined;
|
|
1143
1146
|
}) => Operation<"query", TOperationName, (keyof TVarDefinitions & string)[], ConstAssignableInput<TSchema, TVarDefinitions>, TFields, InferFields<TSchema, TFields>>;
|
|
1144
1147
|
};
|
|
1145
1148
|
mutation: {
|
|
@@ -1148,6 +1151,7 @@ declare const createGqlElementComposer: <TSchema extends AnyGraphqlSchema, TFrag
|
|
|
1148
1151
|
variables?: TVarDefinitions | undefined;
|
|
1149
1152
|
metadata?: MetadataBuilder<DeclaredVariables<TSchema, TVarDefinitions>, TOperationMetadata, ExtractAdapterTypes<ExtractMetadataAdapter<TAdapter>>["aggregatedFragmentMetadata"], ExtractAdapterTypes<ExtractMetadataAdapter<TAdapter>>["schemaLevel"]> | undefined;
|
|
1150
1153
|
fields: FieldsBuilder<TSchema, TSchema["operations"]["mutation"] & keyof TSchema["object"] & string, TVarDefinitions, TFields>;
|
|
1154
|
+
transformDocument?: OperationDocumentTransformer<TOperationMetadata> | undefined;
|
|
1151
1155
|
}) => Operation<"mutation", TOperationName, (keyof TVarDefinitions & string)[], ConstAssignableInput<TSchema, TVarDefinitions>, TFields, InferFields<TSchema, TFields>>;
|
|
1152
1156
|
};
|
|
1153
1157
|
subscription: {
|
|
@@ -1156,6 +1160,7 @@ declare const createGqlElementComposer: <TSchema extends AnyGraphqlSchema, TFrag
|
|
|
1156
1160
|
variables?: TVarDefinitions | undefined;
|
|
1157
1161
|
metadata?: MetadataBuilder<DeclaredVariables<TSchema, TVarDefinitions>, TOperationMetadata, ExtractAdapterTypes<ExtractMetadataAdapter<TAdapter>>["aggregatedFragmentMetadata"], ExtractAdapterTypes<ExtractMetadataAdapter<TAdapter>>["schemaLevel"]> | undefined;
|
|
1158
1162
|
fields: FieldsBuilder<TSchema, TSchema["operations"]["subscription"] & keyof TSchema["object"] & string, TVarDefinitions, TFields>;
|
|
1163
|
+
transformDocument?: OperationDocumentTransformer<TOperationMetadata> | undefined;
|
|
1159
1164
|
}) => Operation<"subscription", TOperationName, (keyof TVarDefinitions & string)[], ConstAssignableInput<TSchema, TVarDefinitions>, TFields, InferFields<TSchema, TFields>>;
|
|
1160
1165
|
};
|
|
1161
1166
|
$var: VarBuilder<TSchema>;
|
|
@@ -1175,15 +1180,17 @@ declare const createGqlElementComposer: <TSchema extends AnyGraphqlSchema, TFrag
|
|
|
1175
1180
|
*
|
|
1176
1181
|
* @param schema - The GraphQL schema definition
|
|
1177
1182
|
* @param adapter - Optional metadata adapter for custom metadata handling
|
|
1183
|
+
* @param transformDocument - Optional document transformer called after building
|
|
1178
1184
|
* @returns Operation type selector function
|
|
1179
1185
|
*
|
|
1180
1186
|
* @internal Used by `createGqlElementComposer`
|
|
1181
1187
|
*/
|
|
1182
|
-
declare const createOperationComposerFactory: <TSchema extends AnyGraphqlSchema, TAdapter extends AnyMetadataAdapter = DefaultMetadataAdapter>(schema: NoInfer<TSchema>, adapter?: TAdapter) => <TOperationType extends OperationType>(operationType: TOperationType) => <TOperationName extends string, TFields extends AnyFields, TVarDefinitions extends InputTypeSpecifiers = {}, TOperationMetadata = unknown>(options: {
|
|
1188
|
+
declare const createOperationComposerFactory: <TSchema extends AnyGraphqlSchema, TAdapter extends AnyMetadataAdapter = DefaultMetadataAdapter>(schema: NoInfer<TSchema>, adapter?: TAdapter, transformDocument?: DocumentTransformer<ExtractAdapterTypes<TAdapter>["schemaLevel"], ExtractAdapterTypes<TAdapter>["aggregatedFragmentMetadata"]>) => <TOperationType extends OperationType>(operationType: TOperationType) => <TOperationName extends string, TFields extends AnyFields, TVarDefinitions extends InputTypeSpecifiers = {}, TOperationMetadata = unknown>(options: {
|
|
1183
1189
|
name: TOperationName;
|
|
1184
1190
|
variables?: TVarDefinitions;
|
|
1185
1191
|
metadata?: MetadataBuilder<ReturnType<typeof createVarRefs<TSchema, TVarDefinitions>>, TOperationMetadata, ExtractAdapterTypes<TAdapter>["aggregatedFragmentMetadata"], ExtractAdapterTypes<TAdapter>["schemaLevel"]>;
|
|
1186
1192
|
fields: FieldsBuilder<TSchema, TSchema["operations"][TOperationType] & keyof TSchema["object"] & string, TVarDefinitions, TFields>;
|
|
1193
|
+
transformDocument?: OperationDocumentTransformer<TOperationMetadata>;
|
|
1187
1194
|
}) => Operation<TOperationType, TOperationName, (keyof TVarDefinitions & string)[], ConstAssignableInput<TSchema, TVarDefinitions>, TFields, InferFields<TSchema, TFields>>;
|
|
1188
1195
|
//#endregion
|
|
1189
1196
|
//#region packages/core/src/utils/hidden.d.ts
|
|
@@ -1194,4 +1201,4 @@ type Hidden<T> = () => T;
|
|
|
1194
1201
|
declare function wrapByKey<TName$1 extends string, TValue$1>(name: TName$1, value: TValue$1): { [K in TName$1]: TValue$1 };
|
|
1195
1202
|
//#endregion
|
|
1196
1203
|
export { NestedUnionFieldsBuilder as $, AnyDirectiveRefBrand as $t, AnyOperationOf as A, AbstractFieldSelection as At, AnyFieldSelectionFactory as B, AnyAssignableInputValue as Bt, withFragmentUsageCollection as C, Tuple as Ct, createVarRefs as D, buildDocument as Dt, createVarAssignments as E, buildConstValueNode as Et, FragmentInferMeta as F, FieldSelectionTemplateOf as Ft, FieldSelectionFactoryObjectReturn as G, FieldArgumentValue as Gt, FieldSelectionFactories as H, AssignableInput as Ht, GqlElement as I, InferField as It, FieldSelectionFactoryUnionReturn as J, AnyConstAssignableInputValue as Jt, FieldSelectionFactoryPrimitiveReturn as K, AnyConstDirectiveAttachments as Kt, GqlElementAttachment as L, InferFields as Lt, OperationInferMeta as M, AnyFields as Mt, AnyFragment as N, AnyNestedObject as Nt, createFieldFactories as O, buildOperationTypeNode as Ot, Fragment as P, AnyNestedUnion as Pt, NestedObjectFieldsBuilderTools as Q, AnyDirectiveRef as Qt, GqlElementContext as R, AnyDirectiveAttachments as Rt, recordFragmentUsage as S, StripSymbols as St, createGqlFragmentComposers as T, buildArgumentValue as Tt, FieldSelectionFactory as U, AssignableInputByFieldName as Ut, AnyFieldSelectionFactoryReturn as V, AnyAssigningInput as Vt, FieldSelectionFactoryFieldArguments as W, DeclaredVariables as Wt, FieldsBuilderTools as X, ConstAssignableInputValue as Xt, FieldsBuilder as Y, ConstAssignableInput as Yt, NestedObjectFieldsBuilder as Z, GetAssignableType as Zt, VarSpecifier as _, ColocateHelper as _t, ExtractMetadataAdapter as a, AttachmentShape as at, createVarMethodFactory as b, createColocateHelper as bt, GqlElementComposerOptions as c, AnyDirectiveMethod as ct, InputTypeMethods as d, DirectiveMethod as dt, DirectiveLocation as en, EmptyObject as et, ResolveTypeFromMeta as f, StandardDirectives as ft, VarBuilderMethods as g, isDirectiveRef as gt, VarBuilder as h, createStandardDirectives as ht, createOperationComposerFactory as i, empty as it, Operation as j, AnyFieldSelection as jt, AnyOperation as k, buildWithTypeModifier as kt, createGqlElementComposer as l, DirectiveArgValue as lt, SchemaAwareGetValueAt as m, createDirectiveMethod as mt, Hidden as n, DirectiveRefInner as nn, OptionalArg as nt, FragmentBuildersAll as o, AttachmentToProperty as ot, SchemaAwareGetNameAt as p, createDirectiveBuilder as pt, FieldSelectionFactoryReturn as q, AnyConstAssignableInput as qt, hidden as r, SwitchIfOmittable as rt, GqlElementComposer as s, AttachmentsTupleToIntersection as st, wrapByKey as t, DirectiveRef as tn, IfOmittable as tt, InputTypeMethod as u, DirectiveBuilder as ut, createVarBuilder as v, ColocatedEntries as vt, FragmentBuilderFor as w, UnionToIntersection as wt, FragmentUsageRecord as x, StripFunctions as xt, createVarMethod as y, ColocatedFields as yt, GqlElementDefinitionFactory as z, AnyAssignableInput as zt };
|
|
1197
|
-
//# sourceMappingURL=index-
|
|
1204
|
+
//# sourceMappingURL=index-B_TU5U2U.d.ts.map
|