@soda-gql/core 0.2.0 → 0.4.0

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.
Files changed (40) hide show
  1. package/README.md +67 -55
  2. package/dist/adapter.cjs +1 -1
  3. package/dist/adapter.d.cts +2 -2
  4. package/dist/adapter.d.ts +2 -2
  5. package/dist/adapter.js +1 -1
  6. package/dist/{index-Djr9A4KL.d.ts → index-CVmfSjJv.d.ts} +160 -231
  7. package/dist/index-CVmfSjJv.d.ts.map +1 -0
  8. package/dist/{index-B-erotAZ.d.cts → index-eFR-ZKOA.d.cts} +160 -231
  9. package/dist/index-eFR-ZKOA.d.cts.map +1 -0
  10. package/dist/index.cjs +260 -147
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +13 -4
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.ts +13 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +259 -146
  17. package/dist/index.js.map +1 -1
  18. package/dist/runtime.cjs +1 -1
  19. package/dist/runtime.cjs.map +1 -1
  20. package/dist/runtime.d.cts +2 -2
  21. package/dist/runtime.d.ts +2 -2
  22. package/dist/runtime.js +1 -1
  23. package/dist/runtime.js.map +1 -1
  24. package/dist/{schema-BygZwEX8.d.ts → schema-5Vfg289u.d.cts} +162 -74
  25. package/dist/schema-5Vfg289u.d.cts.map +1 -0
  26. package/dist/{schema-D9wIW5Dl.js → schema-BbCrsNkQ.js} +2 -2
  27. package/dist/{schema-D9wIW5Dl.js.map → schema-BbCrsNkQ.js.map} +1 -1
  28. package/dist/{schema-DRkKucYe.d.cts → schema-DnlCvCK4.d.ts} +162 -74
  29. package/dist/schema-DnlCvCK4.d.ts.map +1 -0
  30. package/dist/{schema-Bip7o0g3.cjs → schema-DuWaRhdp.cjs} +1 -7
  31. package/dist/{schema-Bip7o0g3.cjs.map → schema-DuWaRhdp.cjs.map} +1 -1
  32. package/dist/{schema-builder-vwQtCGYI.d.ts → schema-builder-D_K9ESSn.d.ts} +2 -2
  33. package/dist/{schema-builder-vwQtCGYI.d.ts.map → schema-builder-D_K9ESSn.d.ts.map} +1 -1
  34. package/dist/{schema-builder-8zadflz-.d.cts → schema-builder-cy5uLVP1.d.cts} +2 -2
  35. package/dist/{schema-builder-8zadflz-.d.cts.map → schema-builder-cy5uLVP1.d.cts.map} +1 -1
  36. package/package.json +1 -1
  37. package/dist/index-B-erotAZ.d.cts.map +0 -1
  38. package/dist/index-Djr9A4KL.d.ts.map +0 -1
  39. package/dist/schema-BygZwEX8.d.ts.map +0 -1
  40. package/dist/schema-DRkKucYe.d.cts.map +0 -1
package/README.md CHANGED
@@ -17,11 +17,11 @@ soda-gql uses two main building blocks for constructing GraphQL operations:
17
17
 
18
18
  ### Fragments
19
19
 
20
- Reusable type-safe field selections. Fragments define how to select fields from a GraphQL type and can be embedded in operations.
20
+ Reusable type-safe field selections. Fragments define how to select fields from a GraphQL type and can be spread in operations.
21
21
 
22
22
  ### Operations
23
23
 
24
- Complete GraphQL operations (query/mutation/subscription) with field selections. Operations define variables, select fields, and can embed fragments for reusable field selections.
24
+ Complete GraphQL operations (query/mutation/subscription) with field selections. Operations define variables, select fields, and can spread fragments for reusable field selections.
25
25
 
26
26
  ## Usage
27
27
 
@@ -36,15 +36,15 @@ import { gql } from "@/graphql-system";
36
36
  Fragments define reusable field selections for a specific GraphQL type:
37
37
 
38
38
  ```typescript
39
- export const userFragment = gql.default(({ fragment }, { $var }) =>
40
- fragment.User(
41
- { variables: [$var("includeEmail").scalar("Boolean:?")] },
42
- ({ f, $ }) => [
43
- f.id(),
44
- f.name(),
45
- f.email({ if: $.includeEmail }),
46
- ],
47
- ),
39
+ export const userFragment = gql.default(({ fragment, $var }) =>
40
+ fragment.User({
41
+ variables: { ...$var("includeEmail").Boolean("?") },
42
+ fields: ({ f, $ }) => ({
43
+ ...f.id(),
44
+ ...f.name(),
45
+ ...f.email({ if: $.includeEmail }),
46
+ }),
47
+ }),
48
48
  );
49
49
  ```
50
50
 
@@ -53,29 +53,25 @@ export const userFragment = gql.default(({ fragment }, { $var }) =>
53
53
  Operations define complete GraphQL queries, mutations, or subscriptions:
54
54
 
55
55
  ```typescript
56
- export const getUserQuery = gql.default(({ query }, { $var }) =>
57
- query.operation(
58
- {
59
- name: "GetUser",
60
- variables: [$var("id").scalar("ID:!")],
61
- },
62
- ({ f, $ }) => [
63
- f.user({ id: $.id })(({ f }) => [f.id(), f.name()]),
64
- ],
65
- ),
56
+ export const getUserQuery = gql.default(({ query, $var }) =>
57
+ query.operation({
58
+ name: "GetUser",
59
+ variables: { ...$var("id").ID("!") },
60
+ fields: ({ f, $ }) => ({
61
+ ...f.user({ id: $.id })(({ f }) => ({ ...f.id(), ...f.name() })),
62
+ }),
63
+ }),
66
64
  );
67
65
 
68
- // Operation with embedded fragment
69
- export const getUserWithFragment = gql.default(({ query }, { $var }) =>
70
- query.operation(
71
- {
72
- name: "GetUserWithFragment",
73
- variables: [$var("id").scalar("ID:!"), $var("includeEmail").scalar("Boolean:?")],
74
- },
75
- ({ f, $ }) => [
76
- f.user({ id: $.id })(({ f }) => [userFragment.embed({ includeEmail: $.includeEmail })]),
77
- ],
78
- ),
66
+ // Operation with spread fragment
67
+ export const getUserWithFragment = gql.default(({ query, $var }) =>
68
+ query.operation({
69
+ name: "GetUserWithFragment",
70
+ variables: { ...$var("id").ID("!"), ...$var("includeEmail").Boolean("?") },
71
+ fields: ({ f, $ }) => ({
72
+ ...f.user({ id: $.id })(({ f }) => ({ ...userFragment.spread({ includeEmail: $.includeEmail }) })),
73
+ }),
74
+ }),
79
75
  );
80
76
  ```
81
77
 
@@ -95,12 +91,30 @@ Variables are declared using a string-based type syntax:
95
91
 
96
92
  | Pattern | Description |
97
93
  |---------|-------------|
98
- | `f.id()` | Basic field selection |
99
- | `f.posts({ limit: 10 })` | Field with arguments |
100
- | `f.posts()(({ f }) => [...])` | Nested selection (curried) |
101
- | `f.id(null, { alias: "uuid" })` | Field with alias |
102
- | `f.email({ if: $.includeEmail })` | Conditional field |
103
- | `userFragment.embed({})` | Use fragment fields |
94
+ | `...f.id()` | Basic field selection |
95
+ | `...f.posts({ limit: 10 })` | Field with arguments |
96
+ | `...f.posts()(({ f }) => ({ ... }))` | Nested selection (curried) |
97
+ | `...f.id(null, { alias: "uuid" })` | Field with alias |
98
+ | `...f.email({ if: $.includeEmail })` | Conditional field |
99
+ | `...userFragment.spread({})` | Use fragment fields |
100
+
101
+ ## Understanding the Inject Module
102
+
103
+ The inject module (`{schema}.inject.ts`) bridges your GraphQL schema with TypeScript types.
104
+
105
+ **Why hand-written?**
106
+ - Custom scalar types (DateTime, JSON, etc.) need explicit TypeScript type mappings
107
+ - Version-controlled to keep type behavior explicit and reviewable
108
+
109
+ **What it contains:**
110
+ - `scalar`: TypeScript type definitions for each GraphQL scalar
111
+
112
+ **Scaffolding:**
113
+ ```bash
114
+ bun run soda-gql codegen --emit-inject-template ./src/graphql-system/default.inject.ts
115
+ ```
116
+
117
+ This creates a template with standard scalars (ID, String, Int, Float, Boolean) that you can customize.
104
118
 
105
119
  ## Defining Custom Scalars
106
120
 
@@ -166,7 +180,7 @@ const myAttachment: GqlElementAttachment<typeof userFragment, "custom", { value:
166
180
 
167
181
  // Attach to a fragment
168
182
  export const userFragment = gql
169
- .default(({ fragment }) => fragment.User({}, ({ f }) => [f.id(), f.name()]))
183
+ .default(({ fragment }) => fragment.User({ fields: ({ f }) => ({ ...f.id(), ...f.name() }) }))
170
184
  .attach(myAttachment);
171
185
 
172
186
  // Access the attached property
@@ -201,22 +215,20 @@ Metadata is defined on operations:
201
215
 
202
216
  ```typescript
203
217
  // Operation with metadata
204
- export const getUserQuery = gql.default(({ query }, { $var }) =>
205
- query.operation(
206
- {
207
- name: "GetUser",
208
- variables: [$var("id").scalar("ID:!")],
209
- metadata: ({ $, document }) => ({
210
- headers: { "X-Request-ID": "user-query" },
211
- custom: {
212
- requiresAuth: true,
213
- cacheTtl: 300,
214
- trackedVariables: [$var.getInner($.id)],
215
- },
216
- }),
217
- },
218
- ({ f, $ }) => [f.user({ id: $.id })(({ f }) => [f.id(), f.name()])],
219
- ),
218
+ export const getUserQuery = gql.default(({ query, $var }) =>
219
+ query.operation({
220
+ name: "GetUser",
221
+ variables: { ...$var("id").ID("!") },
222
+ metadata: ({ $, document }) => ({
223
+ headers: { "X-Request-ID": "user-query" },
224
+ custom: {
225
+ requiresAuth: true,
226
+ cacheTtl: 300,
227
+ trackedVariables: [$var.getInner($.id)],
228
+ },
229
+ }),
230
+ fields: ({ f, $ }) => ({ ...f.user({ id: $.id })(({ f }) => ({ ...f.id(), ...f.name() })) }),
231
+ }),
220
232
  );
221
233
  ```
222
234
 
package/dist/adapter.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_schema = require('./schema-Bip7o0g3.cjs');
1
+ const require_schema = require('./schema-DuWaRhdp.cjs');
2
2
 
3
3
  //#region packages/core/src/adapter/define-adapter.ts
4
4
  /**
@@ -1,5 +1,5 @@
1
- import { I as Adapter } from "./schema-DRkKucYe.cjs";
2
- import { r as defineScalar } from "./schema-builder-8zadflz-.cjs";
1
+ import { R as Adapter } from "./schema-5Vfg289u.cjs";
2
+ import { r as defineScalar } from "./schema-builder-cy5uLVP1.cjs";
3
3
 
4
4
  //#region packages/core/src/adapter/define-adapter.d.ts
5
5
 
package/dist/adapter.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as Adapter } from "./schema-BygZwEX8.js";
2
- import { r as defineScalar } from "./schema-builder-vwQtCGYI.js";
1
+ import { R as Adapter } from "./schema-DnlCvCK4.js";
2
+ import { r as defineScalar } from "./schema-builder-D_K9ESSn.js";
3
3
 
4
4
  //#region packages/core/src/adapter/define-adapter.d.ts
5
5
 
package/dist/adapter.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as defineScalar } from "./schema-D9wIW5Dl.js";
1
+ import { r as defineScalar } from "./schema-BbCrsNkQ.js";
2
2
 
3
3
  //#region packages/core/src/adapter/define-adapter.ts
4
4
  /**