@distilled.cloud/core 1.0.0-rc.13 → 1.0.0-rc.15
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/lib/api.d.ts +4 -4
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +3 -5
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/category.js +3 -5
- package/lib/category.js.map +1 -1
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -1
- package/lib/codegen/boolean-string-enums.js +2 -6
- package/lib/codegen/boolean-string-enums.js.map +1 -1
- package/lib/codegen/boolean-string-enums.test.js +3 -5
- package/lib/codegen/boolean-string-enums.test.js.map +1 -1
- package/lib/codegen/cli.d.ts +5 -4
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +12 -9
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/defer-naming.test.d.ts +2 -0
- package/lib/codegen/defer-naming.test.d.ts.map +1 -0
- package/lib/codegen/defer-naming.test.js +105 -0
- package/lib/codegen/defer-naming.test.js.map +1 -0
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +1 -3
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/format.d.ts +0 -12
- package/lib/codegen/format.d.ts.map +1 -1
- package/lib/codegen/format.js +10 -6
- package/lib/codegen/format.js.map +1 -1
- package/lib/codegen/generated-at.d.ts +29 -0
- package/lib/codegen/generated-at.d.ts.map +1 -0
- package/lib/codegen/generated-at.js +78 -0
- package/lib/codegen/generated-at.js.map +1 -0
- package/lib/codegen/generated-at.test.d.ts +2 -0
- package/lib/codegen/generated-at.test.d.ts.map +1 -0
- package/lib/codegen/generated-at.test.js +81 -0
- package/lib/codegen/generated-at.test.js.map +1 -0
- package/lib/codegen/generator.d.ts +4 -2
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +37 -75
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/generator.test.js +4 -9
- package/lib/codegen/generator.test.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts.map +1 -1
- package/lib/codegen/graphql-client.js +12 -33
- package/lib/codegen/graphql-client.js.map +1 -1
- package/lib/codegen/graphql-client.test.js +4 -12
- package/lib/codegen/graphql-client.test.js.map +1 -1
- package/lib/codegen/graphql.d.ts.map +1 -1
- package/lib/codegen/graphql.js +7 -20
- package/lib/codegen/graphql.js.map +1 -1
- package/lib/codegen/model-diff.d.ts +10 -0
- package/lib/codegen/model-diff.d.ts.map +1 -0
- package/lib/codegen/model-diff.js +67 -0
- package/lib/codegen/model-diff.js.map +1 -0
- package/lib/codegen/naming.d.ts.map +1 -1
- package/lib/codegen/naming.js.map +1 -1
- package/lib/codegen/openapi-binary.test.js +1 -1
- package/lib/codegen/openapi-binary.test.js.map +1 -1
- package/lib/codegen/openapi-cli.d.ts +11 -11
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +26 -51
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +9 -1
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +48 -42
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/operations.d.ts.map +1 -1
- package/lib/codegen/operations.js.map +1 -1
- package/lib/codegen/pagination.d.ts.map +1 -1
- package/lib/codegen/pagination.js +2 -4
- package/lib/codegen/pagination.js.map +1 -1
- package/lib/codegen/patch-audit.d.ts +84 -0
- package/lib/codegen/patch-audit.d.ts.map +1 -0
- package/lib/codegen/patch-audit.js +366 -0
- package/lib/codegen/patch-audit.js.map +1 -0
- package/lib/codegen/patch-audit.test.d.ts +2 -0
- package/lib/codegen/patch-audit.test.d.ts.map +1 -0
- package/lib/codegen/patch-audit.test.js +141 -0
- package/lib/codegen/patch-audit.test.js.map +1 -0
- package/lib/codegen/patches.d.ts +59 -10
- package/lib/codegen/patches.d.ts.map +1 -1
- package/lib/codegen/patches.js +233 -63
- package/lib/codegen/patches.js.map +1 -1
- package/lib/codegen/patches.test.js +8 -4
- package/lib/codegen/patches.test.js.map +1 -1
- package/lib/codegen/prelude.js +1 -1
- package/lib/codegen/prelude.js.map +1 -1
- package/lib/codegen/proto.d.ts.map +1 -1
- package/lib/codegen/proto.js +2 -4
- package/lib/codegen/proto.js.map +1 -1
- package/lib/codegen/protocol-imports.test.d.ts +2 -0
- package/lib/codegen/protocol-imports.test.d.ts.map +1 -0
- package/lib/codegen/protocol-imports.test.js +36 -0
- package/lib/codegen/protocol-imports.test.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +23 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -1
- package/lib/codegen/rewrite-operation-ids.js +97 -59
- package/lib/codegen/rewrite-operation-ids.js.map +1 -1
- package/lib/codegen/rewrite-operation-ids.test.js +19 -101
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -1
- package/lib/codegen/spec-path.d.ts +1 -1
- package/lib/codegen/spec-path.d.ts.map +1 -1
- package/lib/codegen/spec-path.js +1 -1
- package/lib/codegen/spec-path.js.map +1 -1
- package/lib/codegen/untagged-unions.test.js +1 -1
- package/lib/codegen/untagged-unions.test.js.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/error-category.js.map +1 -1
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +7 -5
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +4 -8
- package/lib/graphql.d.ts.map +1 -1
- package/lib/graphql.js +20 -48
- package/lib/graphql.js.map +1 -1
- package/lib/graphql.test.js +6 -6
- package/lib/graphql.test.js.map +1 -1
- package/lib/graphql.types.d.ts.map +1 -1
- package/lib/graphql.types.js.map +1 -1
- package/lib/json-patch.d.ts +13 -6
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +34 -19
- package/lib/json-patch.js.map +1 -1
- package/lib/json-patch.test.d.ts +2 -0
- package/lib/json-patch.test.d.ts.map +1 -0
- package/lib/json-patch.test.js +65 -0
- package/lib/json-patch.test.js.map +1 -0
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +6 -16
- package/lib/pagination.js.map +1 -1
- package/lib/pagination.test.js +3 -6
- package/lib/pagination.test.js.map +1 -1
- package/lib/protocol-http.d.ts +20 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +41 -47
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.js +20 -10
- package/lib/protocol-http.test.js.map +1 -1
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +9 -18
- package/lib/protocol-rest.js.map +1 -1
- package/lib/protocol-rest.test.d.ts +2 -0
- package/lib/protocol-rest.test.d.ts.map +1 -0
- package/lib/protocol-rest.test.js +498 -0
- package/lib/protocol-rest.test.js.map +1 -0
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/response-validation.js.map +1 -1
- package/lib/response-validation.test.js +10 -5
- package/lib/response-validation.test.js.map +1 -1
- package/lib/retry-after.d.ts.map +1 -1
- package/lib/retry-after.js +1 -1
- package/lib/retry-after.js.map +1 -1
- package/lib/retry-after.test.d.ts +2 -0
- package/lib/retry-after.test.d.ts.map +1 -0
- package/lib/retry-after.test.js +204 -0
- package/lib/retry-after.test.js.map +1 -0
- package/lib/retry.d.ts.map +1 -1
- package/lib/retry.js +1 -2
- package/lib/retry.js.map +1 -1
- package/lib/retry.test.d.ts +2 -0
- package/lib/retry.test.d.ts.map +1 -0
- package/lib/retry.test.js +407 -0
- package/lib/retry.test.js.map +1 -0
- package/lib/sdks.test.d.ts +2 -0
- package/lib/sdks.test.d.ts.map +1 -0
- package/lib/sdks.test.js +76 -0
- package/lib/sdks.test.js.map +1 -0
- package/lib/testing.d.ts +2 -2
- package/lib/testing.d.ts.map +1 -1
- package/lib/testing.js +1 -1
- package/lib/testing.js.map +1 -1
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js.map +1 -1
- package/lib/xml.d.ts.map +1 -1
- package/lib/xml.js +3 -7
- package/lib/xml.js.map +1 -1
- package/lib/xml.test.js +11 -12
- package/lib/xml.test.js.map +1 -1
- package/package.json +7 -10
- package/src/api.ts +38 -55
- package/src/category.ts +21 -50
- package/src/codegen/boolean-string-enums.test.ts +12 -28
- package/src/codegen/boolean-string-enums.ts +2 -10
- package/src/codegen/cli.ts +29 -47
- package/src/codegen/defer-naming.test.ts +113 -0
- package/src/codegen/emit.ts +2 -5
- package/src/codegen/format.ts +12 -10
- package/src/codegen/generated-at.test.ts +89 -0
- package/src/codegen/generated-at.ts +88 -0
- package/src/codegen/generator.test.ts +8 -22
- package/src/codegen/generator.ts +72 -191
- package/src/codegen/graphql-client.test.ts +12 -42
- package/src/codegen/graphql-client.ts +30 -95
- package/src/codegen/graphql.ts +22 -94
- package/src/codegen/model-diff.ts +67 -0
- package/src/codegen/naming.ts +1 -2
- package/src/codegen/openapi-binary.test.ts +5 -12
- package/src/codegen/openapi-cli.ts +38 -79
- package/src/codegen/openapi.ts +79 -136
- package/src/codegen/operations.ts +2 -5
- package/src/codegen/pagination.ts +4 -11
- package/src/codegen/patch-audit.test.ts +160 -0
- package/src/codegen/patch-audit.ts +480 -0
- package/src/codegen/patches.test.ts +14 -21
- package/src/codegen/patches.ts +313 -103
- package/src/codegen/prelude.ts +1 -1
- package/src/codegen/proto.ts +18 -54
- package/src/codegen/protocol-imports.test.ts +39 -0
- package/src/codegen/rewrite-operation-ids.test.ts +23 -114
- package/src/codegen/rewrite-operation-ids.ts +111 -98
- package/src/codegen/spec-path.ts +3 -6
- package/src/codegen/untagged-unions.test.ts +3 -7
- package/src/error-category.ts +5 -17
- package/src/errors.ts +16 -31
- package/src/graphql.test.ts +6 -8
- package/src/graphql.ts +76 -219
- package/src/graphql.types.ts +10 -25
- package/src/json-patch.test.ts +77 -0
- package/src/json-patch.ts +54 -60
- package/src/pagination.test.ts +13 -35
- package/src/pagination.ts +44 -111
- package/src/protocol-http.test.ts +36 -30
- package/src/protocol-http.ts +73 -138
- package/src/protocol-rest.test.ts +703 -0
- package/src/protocol-rest.ts +24 -62
- package/src/response-validation.test.ts +12 -18
- package/src/response-validation.ts +3 -12
- package/src/retry-after.test.ts +267 -0
- package/src/retry-after.ts +4 -10
- package/src/retry.test.ts +566 -0
- package/src/retry.ts +6 -21
- package/src/sdks.test.ts +87 -0
- package/src/testing.ts +4 -10
- package/src/trait.ts +21 -67
- package/src/xml.test.ts +15 -33
- package/src/xml.ts +9 -25
package/src/graphql.ts
CHANGED
|
@@ -64,7 +64,10 @@ const inspect = Symbol.for("nodejs.util.inspect.custom");
|
|
|
64
64
|
/** A plan that cannot be compiled (a programming error, raised as a defect). */
|
|
65
65
|
export class GqlError {
|
|
66
66
|
readonly _tag = "GqlError" as const;
|
|
67
|
-
|
|
67
|
+
readonly message: string;
|
|
68
|
+
constructor(message: string) {
|
|
69
|
+
this.message = message;
|
|
70
|
+
}
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
// ── Errors ──────────────────────────────────────────────────────────────────
|
|
@@ -80,9 +83,7 @@ export const errorFields = {
|
|
|
80
83
|
message: S.String,
|
|
81
84
|
code: S.optional(S.String),
|
|
82
85
|
path: S.optional(S.Array(S.Union([S.String, S.Number]))),
|
|
83
|
-
locations: S.optional(
|
|
84
|
-
S.Array(S.Struct({ line: S.Number, column: S.Number })),
|
|
85
|
-
),
|
|
86
|
+
locations: S.optional(S.Array(S.Struct({ line: S.Number, column: S.Number }))),
|
|
86
87
|
extensions: S.optional(S.Unknown),
|
|
87
88
|
traceId: S.optional(S.String),
|
|
88
89
|
status: S.optional(S.Number),
|
|
@@ -119,27 +120,22 @@ export class UnknownGraphQLError extends S.TaggedError<UnknownGraphQLError>()(
|
|
|
119
120
|
) {}
|
|
120
121
|
|
|
121
122
|
/** One response carried errors with different tags; none is hidden. */
|
|
122
|
-
export class GraphQLFailure<
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
export class GraphQLFailure<E extends GraphQLIssue = GraphQLIssue> extends Data.TaggedError(
|
|
124
|
+
"GraphQLFailure",
|
|
125
|
+
)<{
|
|
125
126
|
readonly errors: readonly [E, ...E[]];
|
|
126
127
|
readonly data: unknown;
|
|
127
128
|
readonly status?: number;
|
|
128
129
|
}> {
|
|
129
130
|
get message(): string {
|
|
130
131
|
return this.errors
|
|
131
|
-
.map(
|
|
132
|
-
(e) =>
|
|
133
|
-
`${e._tag}${e.path?.length ? ` at ${e.path.join(".")}` : ""}: ${e.message}`,
|
|
134
|
-
)
|
|
132
|
+
.map((e) => `${e._tag}${e.path?.length ? ` at ${e.path.join(".")}` : ""}: ${e.message}`)
|
|
135
133
|
.join("; ");
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
/** The request never produced a GraphQL response (network, HTTP, non-JSON). */
|
|
140
|
-
export class GraphQLTransportError extends Data.TaggedError(
|
|
141
|
-
"GraphQLTransportError",
|
|
142
|
-
)<{
|
|
138
|
+
export class GraphQLTransportError extends Data.TaggedError("GraphQLTransportError")<{
|
|
143
139
|
readonly message: string;
|
|
144
140
|
readonly status?: number;
|
|
145
141
|
/** Server retry hint in seconds. */
|
|
@@ -148,9 +144,7 @@ export class GraphQLTransportError extends Data.TaggedError(
|
|
|
148
144
|
}> {}
|
|
149
145
|
|
|
150
146
|
/** A paginated connection reported more pages without a new cursor. */
|
|
151
|
-
export class GraphQLPaginationError extends Data.TaggedError(
|
|
152
|
-
"GraphQLPaginationError",
|
|
153
|
-
)<{
|
|
147
|
+
export class GraphQLPaginationError extends Data.TaggedError("GraphQLPaginationError")<{
|
|
154
148
|
readonly message: string;
|
|
155
149
|
readonly cursor: string | null;
|
|
156
150
|
}> {}
|
|
@@ -229,11 +223,7 @@ export const objectField = (name: string, objectType: TypeMeta): FieldMeta => ({
|
|
|
229
223
|
kind: "object",
|
|
230
224
|
of: objectType,
|
|
231
225
|
});
|
|
232
|
-
export const listField = (
|
|
233
|
-
name: string,
|
|
234
|
-
itemType: TypeMeta,
|
|
235
|
-
argTypes?: ArgMeta,
|
|
236
|
-
): FieldMeta => ({
|
|
226
|
+
export const listField = (name: string, itemType: TypeMeta, argTypes?: ArgMeta): FieldMeta => ({
|
|
237
227
|
name,
|
|
238
228
|
kind: "list",
|
|
239
229
|
of: itemType,
|
|
@@ -268,9 +258,7 @@ const fieldResult = (parent: TypeRef, field: FieldMeta): TypeRef => {
|
|
|
268
258
|
if (field.kind === "object") return objectRef(field.of!);
|
|
269
259
|
return listRef(objectRef(field.of!)); // list | connection
|
|
270
260
|
};
|
|
271
|
-
return parent.tag === "list"
|
|
272
|
-
? listRef(fieldResult(parent.of, field))
|
|
273
|
-
: inner();
|
|
261
|
+
return parent.tag === "list" ? listRef(fieldResult(parent.of, field)) : inner();
|
|
274
262
|
};
|
|
275
263
|
|
|
276
264
|
const unwrapList = (typeRef: TypeRef): TypeRef => {
|
|
@@ -318,9 +306,7 @@ const log = (..._args: Array<unknown>): void => {};
|
|
|
318
306
|
* `owner: Query<User>` again — TypeScript leaves the cycle lazy. Fields
|
|
319
307
|
* inherit the errors of the root they were read from.
|
|
320
308
|
*/
|
|
321
|
-
type QueryFields<Value, Error> = [NonNullable<Value>] extends [
|
|
322
|
-
ReadonlyArray<infer Item>,
|
|
323
|
-
]
|
|
309
|
+
type QueryFields<Value, Error> = [NonNullable<Value>] extends [ReadonlyArray<infer Item>]
|
|
324
310
|
? {
|
|
325
311
|
readonly [Field in keyof NonNullable<Item>]: Query<
|
|
326
312
|
NonNullable<Item>[Field] | Nullish<Item>,
|
|
@@ -345,8 +331,7 @@ type Nullish<Value> = Extract<Value, null | undefined>;
|
|
|
345
331
|
* A lazy GraphQL selection. `Value` is the plain data after `Query.fn` runs;
|
|
346
332
|
* `Error` is the union of typed errors the roots it reads can return.
|
|
347
333
|
*/
|
|
348
|
-
export type Query<Value, Error = never> = QueryNode<Value, Error> &
|
|
349
|
-
QueryFields<Value, Error>;
|
|
334
|
+
export type Query<Value, Error = never> = QueryNode<Value, Error> & QueryFields<Value, Error>;
|
|
350
335
|
|
|
351
336
|
/** Strip Query/Effect wrappers from a returned plan down to plain data. */
|
|
352
337
|
export type UnwrapPlan<Plan> =
|
|
@@ -456,16 +441,14 @@ export class QueryNode<out Value = unknown, out Error = never> {
|
|
|
456
441
|
readonly [QuerySymbol] = QuerySymbol;
|
|
457
442
|
declare readonly valueType: Value;
|
|
458
443
|
declare readonly errorType: Error;
|
|
459
|
-
|
|
444
|
+
readonly expr: Expr;
|
|
445
|
+
constructor(expr: Expr) {
|
|
446
|
+
this.expr = expr;
|
|
460
447
|
return proxy(this) as QueryNode<Value, Error>;
|
|
461
448
|
}
|
|
462
449
|
pipe<Self>(this: Self): Self;
|
|
463
450
|
pipe<Self, Out1>(this: Self, step1: (_: Self) => Out1): Out1;
|
|
464
|
-
pipe<Self, Out1, Out2>(
|
|
465
|
-
this: Self,
|
|
466
|
-
step1: (_: Self) => Out1,
|
|
467
|
-
step2: (_: Out1) => Out2,
|
|
468
|
-
): Out2;
|
|
451
|
+
pipe<Self, Out1, Out2>(this: Self, step1: (_: Self) => Out1, step2: (_: Out1) => Out2): Out2;
|
|
469
452
|
pipe<Self, Out1, Out2, Out3>(
|
|
470
453
|
this: Self,
|
|
471
454
|
step1: (_: Self) => Out1,
|
|
@@ -682,9 +665,7 @@ export const rootLeaf = <Value, Error = never>(
|
|
|
682
665
|
const printExpr = (expr: Expr): string => {
|
|
683
666
|
switch (expr._tag) {
|
|
684
667
|
case "Root":
|
|
685
|
-
return expr.args
|
|
686
|
-
? `${expr.field}(${JSON.stringify(expr.args)})`
|
|
687
|
-
: expr.field;
|
|
668
|
+
return expr.args ? `${expr.field}(${JSON.stringify(expr.args)})` : expr.field;
|
|
688
669
|
case "Prop":
|
|
689
670
|
return `${printExpr(expr.parent)}.${expr.field.name}`;
|
|
690
671
|
case "Item":
|
|
@@ -765,15 +746,10 @@ const ensureChild = (
|
|
|
765
746
|
isList?: boolean;
|
|
766
747
|
},
|
|
767
748
|
): SelNode => {
|
|
768
|
-
const key =
|
|
769
|
-
options.args === undefined
|
|
770
|
-
? field
|
|
771
|
-
: `${field}:${stableStringify(options.args)}`;
|
|
749
|
+
const key = options.args === undefined ? field : `${field}:${stableStringify(options.args)}`;
|
|
772
750
|
const existing = parent.children.get(key);
|
|
773
751
|
if (existing) return existing;
|
|
774
|
-
const taken = new Set(
|
|
775
|
-
[...parent.children.values()].map((c) => c.alias ?? c.field),
|
|
776
|
-
);
|
|
752
|
+
const taken = new Set([...parent.children.values()].map((c) => c.alias ?? c.field));
|
|
777
753
|
let alias: string | undefined;
|
|
778
754
|
if (taken.has(field)) {
|
|
779
755
|
do {
|
|
@@ -804,9 +780,7 @@ const paintAbs = (forest: Forest, expr: Expr): Path => {
|
|
|
804
780
|
switch (expr._tag) {
|
|
805
781
|
case "Root": {
|
|
806
782
|
if (forest.kind !== undefined && forest.kind !== expr.op) {
|
|
807
|
-
throw new GqlError(
|
|
808
|
-
`cannot mix ${forest.kind} and ${expr.op} in one document`,
|
|
809
|
-
);
|
|
783
|
+
throw new GqlError(`cannot mix ${forest.kind} and ${expr.op} in one document`);
|
|
810
784
|
}
|
|
811
785
|
forest.kind = expr.op;
|
|
812
786
|
const node = ensureChild(forest, forest.roots, expr.field, {
|
|
@@ -814,8 +788,7 @@ const paintAbs = (forest: Forest, expr: Expr): Path => {
|
|
|
814
788
|
argTypes: expr.argTypes,
|
|
815
789
|
// Leaf roots (`projectDelete: Boolean!`) take no sub-selection.
|
|
816
790
|
isScalar:
|
|
817
|
-
expr.type.tag === "scalar" ||
|
|
818
|
-
(expr.type.tag === "list" && expr.type.of.tag === "scalar"),
|
|
791
|
+
expr.type.tag === "scalar" || (expr.type.tag === "list" && expr.type.of.tag === "scalar"),
|
|
819
792
|
isList: expr.type.tag === "list" && !expr.connection,
|
|
820
793
|
});
|
|
821
794
|
const key = node.alias ?? node.field;
|
|
@@ -833,9 +806,7 @@ const paintAbs = (forest: Forest, expr: Expr): Path => {
|
|
|
833
806
|
isList: expr.field.kind === "list",
|
|
834
807
|
});
|
|
835
808
|
const path = [...parentPath, node.alias ?? node.field];
|
|
836
|
-
return expr.field.kind === "connection"
|
|
837
|
-
? [...path, ...paintConnection(forest, node)]
|
|
838
|
-
: path;
|
|
809
|
+
return expr.field.kind === "connection" ? [...path, ...paintConnection(forest, node)] : path;
|
|
839
810
|
}
|
|
840
811
|
default:
|
|
841
812
|
throw new GqlError(`paintAbs: ${expr._tag}`);
|
|
@@ -858,12 +829,8 @@ const selAt = (roots: SelNode, path: Path): SelNode => {
|
|
|
858
829
|
};
|
|
859
830
|
|
|
860
831
|
const connectionNodeSel = (connection: SelNode): SelNode => {
|
|
861
|
-
const edges = [...connection.children.values()].find(
|
|
862
|
-
|
|
863
|
-
);
|
|
864
|
-
const node = edges
|
|
865
|
-
? [...edges.children.values()].find((c) => c.field === "node")
|
|
866
|
-
: undefined;
|
|
832
|
+
const edges = [...connection.children.values()].find((c) => c.field === "edges");
|
|
833
|
+
const node = edges ? [...edges.children.values()].find((c) => c.field === "node") : undefined;
|
|
867
834
|
if (!node) throw new GqlError("internal: connection missing edges.node");
|
|
868
835
|
return node;
|
|
869
836
|
};
|
|
@@ -874,15 +841,11 @@ const relSel = (expr: Expr, listSel: SelNode): SelNode => {
|
|
|
874
841
|
return listSel;
|
|
875
842
|
case "Prop": {
|
|
876
843
|
const parent = relSel(expr.parent, listSel);
|
|
877
|
-
const child = [...parent.children.values()].find(
|
|
878
|
-
(c) => c.field === expr.field.name,
|
|
879
|
-
);
|
|
844
|
+
const child = [...parent.children.values()].find((c) => c.field === expr.field.name);
|
|
880
845
|
if (!child) {
|
|
881
846
|
throw new GqlError(`missing ${expr.field.name} in list selection`);
|
|
882
847
|
}
|
|
883
|
-
return expr.field.kind === "connection"
|
|
884
|
-
? connectionNodeSel(child)
|
|
885
|
-
: child;
|
|
848
|
+
return expr.field.kind === "connection" ? connectionNodeSel(child) : child;
|
|
886
849
|
}
|
|
887
850
|
default:
|
|
888
851
|
return listSel;
|
|
@@ -896,17 +859,12 @@ const paintRel = (forest: Forest, expr: Expr, listSel: SelNode): void => {
|
|
|
896
859
|
return;
|
|
897
860
|
case "Prop": {
|
|
898
861
|
paintRel(forest, expr.parent, listSel);
|
|
899
|
-
const child = ensureChild(
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
expr.field.
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
argTypes: expr.field.argTypes,
|
|
906
|
-
isScalar: expr.field.kind === "scalar",
|
|
907
|
-
isList: expr.field.kind === "list",
|
|
908
|
-
},
|
|
909
|
-
);
|
|
862
|
+
const child = ensureChild(forest, relSel(expr.parent, listSel), expr.field.name, {
|
|
863
|
+
args: expr.args,
|
|
864
|
+
argTypes: expr.field.argTypes,
|
|
865
|
+
isScalar: expr.field.kind === "scalar",
|
|
866
|
+
isList: expr.field.kind === "list",
|
|
867
|
+
});
|
|
910
868
|
if (expr.field.kind === "connection") paintConnection(forest, child);
|
|
911
869
|
return;
|
|
912
870
|
}
|
|
@@ -1075,41 +1033,26 @@ const nodesFromConnection = (value: unknown): unknown => {
|
|
|
1075
1033
|
if (Array.isArray(value)) return value.map(nodesFromConnection);
|
|
1076
1034
|
const edges = (value as Record<string, unknown>).edges;
|
|
1077
1035
|
if (!Array.isArray(edges)) return [];
|
|
1078
|
-
return edges.map((edge) =>
|
|
1079
|
-
edge == null ? edge : (edge as Record<string, unknown>).node,
|
|
1080
|
-
);
|
|
1036
|
+
return edges.map((edge) => (edge == null ? edge : (edge as Record<string, unknown>).node));
|
|
1081
1037
|
};
|
|
1082
1038
|
|
|
1083
1039
|
const readField = (parent: unknown, name: string): unknown => {
|
|
1084
1040
|
if (parent == null) return parent;
|
|
1085
1041
|
if (Array.isArray(parent)) {
|
|
1086
|
-
return parent.map((item) =>
|
|
1087
|
-
item == null ? item : (item as Record<string, unknown>)[name],
|
|
1088
|
-
);
|
|
1042
|
+
return parent.map((item) => (item == null ? item : (item as Record<string, unknown>)[name]));
|
|
1089
1043
|
}
|
|
1090
1044
|
return (parent as Record<string, unknown>)[name];
|
|
1091
1045
|
};
|
|
1092
1046
|
|
|
1093
|
-
const extractAbs = (
|
|
1094
|
-
expr: Expr,
|
|
1095
|
-
data: unknown,
|
|
1096
|
-
rootAlias: WeakMap<object, string>,
|
|
1097
|
-
): unknown => {
|
|
1047
|
+
const extractAbs = (expr: Expr, data: unknown, rootAlias: WeakMap<object, string>): unknown => {
|
|
1098
1048
|
switch (expr._tag) {
|
|
1099
1049
|
case "Root": {
|
|
1100
|
-
const raw = (data as Record<string, unknown>)[
|
|
1101
|
-
rootAlias.get(expr) ?? expr.field
|
|
1102
|
-
];
|
|
1050
|
+
const raw = (data as Record<string, unknown>)[rootAlias.get(expr) ?? expr.field];
|
|
1103
1051
|
return expr.connection ? nodesFromConnection(raw) : raw;
|
|
1104
1052
|
}
|
|
1105
1053
|
case "Prop": {
|
|
1106
|
-
const value = readField(
|
|
1107
|
-
|
|
1108
|
-
expr.field.name,
|
|
1109
|
-
);
|
|
1110
|
-
return expr.field.kind === "connection"
|
|
1111
|
-
? nodesFromConnection(value)
|
|
1112
|
-
: value;
|
|
1054
|
+
const value = readField(extractAbs(expr.parent, data, rootAlias), expr.field.name);
|
|
1055
|
+
return expr.field.kind === "connection" ? nodesFromConnection(value) : value;
|
|
1113
1056
|
}
|
|
1114
1057
|
default:
|
|
1115
1058
|
throw new GqlError(`extractAbs: ${expr._tag}`);
|
|
@@ -1122,9 +1065,7 @@ const extractRel = (expr: Expr, item: unknown): unknown => {
|
|
|
1122
1065
|
return item;
|
|
1123
1066
|
case "Prop": {
|
|
1124
1067
|
const value = readField(extractRel(expr.parent, item), expr.field.name);
|
|
1125
|
-
return expr.field.kind === "connection"
|
|
1126
|
-
? nodesFromConnection(value)
|
|
1127
|
-
: value;
|
|
1068
|
+
return expr.field.kind === "connection" ? nodesFromConnection(value) : value;
|
|
1128
1069
|
}
|
|
1129
1070
|
default:
|
|
1130
1071
|
throw new GqlError(`extractRel: ${expr._tag}`);
|
|
@@ -1159,29 +1100,21 @@ const interpretExpr = (
|
|
|
1159
1100
|
return item;
|
|
1160
1101
|
case "Root":
|
|
1161
1102
|
case "Prop":
|
|
1162
|
-
return inItem(expr)
|
|
1163
|
-
? extractRel(expr, item)
|
|
1164
|
-
: extractAbs(expr, data, rootAlias);
|
|
1103
|
+
return inItem(expr) ? extractRel(expr, item) : extractAbs(expr, data, rootAlias);
|
|
1165
1104
|
case "MapValue":
|
|
1166
1105
|
return expr.mapFn(interpretExpr(expr.parent, data, rootAlias, item));
|
|
1167
1106
|
case "Filter": {
|
|
1168
1107
|
const list = interpretExpr(expr.parent, data, rootAlias, item);
|
|
1169
1108
|
const arr = Array.isArray(list) ? list : [];
|
|
1170
|
-
return arr.filter((row) =>
|
|
1171
|
-
Boolean(interpretExpr(expr.predicate, data, rootAlias, row)),
|
|
1172
|
-
);
|
|
1109
|
+
return arr.filter((row) => Boolean(interpretExpr(expr.predicate, data, rootAlias, row)));
|
|
1173
1110
|
}
|
|
1174
1111
|
case "MapItems": {
|
|
1175
1112
|
const list = interpretExpr(expr.parent, data, rootAlias, item);
|
|
1176
1113
|
if (expr.single) {
|
|
1177
|
-
return list == null
|
|
1178
|
-
? null
|
|
1179
|
-
: interpretValueSync(expr.mapped, data, rootAlias, list);
|
|
1114
|
+
return list == null ? null : interpretValueSync(expr.mapped, data, rootAlias, list);
|
|
1180
1115
|
}
|
|
1181
1116
|
const arr = Array.isArray(list) ? list : [];
|
|
1182
|
-
return arr.map((row) =>
|
|
1183
|
-
interpretValueSync(expr.mapped, data, rootAlias, row),
|
|
1184
|
-
);
|
|
1117
|
+
return arr.map((row) => interpretValueSync(expr.mapped, data, rootAlias, row));
|
|
1185
1118
|
}
|
|
1186
1119
|
case "FlatMap":
|
|
1187
1120
|
throw new GqlError("FlatMap must be interpreted as Effect");
|
|
@@ -1199,9 +1132,7 @@ const interpretValueSync = (
|
|
|
1199
1132
|
}
|
|
1200
1133
|
if (plan !== null && typeof plan === "object" && !Effect.isEffect(plan)) {
|
|
1201
1134
|
const out: Record<string, unknown> = {};
|
|
1202
|
-
for (const [key, nested] of Object.entries(
|
|
1203
|
-
plan as Record<string, unknown>,
|
|
1204
|
-
)) {
|
|
1135
|
+
for (const [key, nested] of Object.entries(plan as Record<string, unknown>)) {
|
|
1205
1136
|
out[key] = interpretValueSync(nested, data, rootAlias, item);
|
|
1206
1137
|
}
|
|
1207
1138
|
return out;
|
|
@@ -1229,9 +1160,7 @@ const interpretPlan = (
|
|
|
1229
1160
|
if (Effect.isEffect(plan)) return yield* plan;
|
|
1230
1161
|
if (plan !== null && typeof plan === "object" && !Array.isArray(plan)) {
|
|
1231
1162
|
const out: Record<string, unknown> = {};
|
|
1232
|
-
for (const [key, nested] of Object.entries(
|
|
1233
|
-
plan as Record<string, unknown>,
|
|
1234
|
-
)) {
|
|
1163
|
+
for (const [key, nested] of Object.entries(plan as Record<string, unknown>)) {
|
|
1235
1164
|
out[key] = yield* interpretPlan(nested, data, rootAlias);
|
|
1236
1165
|
}
|
|
1237
1166
|
return out;
|
|
@@ -1258,20 +1187,14 @@ const evaluatePlan = <Plan>(
|
|
|
1258
1187
|
rootAlias = compiled.rootAlias;
|
|
1259
1188
|
}
|
|
1260
1189
|
return (yield* interpretPlan(plan, data, rootAlias)) as UnwrapPlan<Plan>;
|
|
1261
|
-
}) as Effect.Effect<
|
|
1262
|
-
UnwrapPlan<Plan>,
|
|
1263
|
-
QueryError<PlanError<Plan>>,
|
|
1264
|
-
GqlTransport
|
|
1265
|
-
>;
|
|
1190
|
+
}) as Effect.Effect<UnwrapPlan<Plan>, QueryError<PlanError<Plan>>, GqlTransport>;
|
|
1266
1191
|
|
|
1267
1192
|
/**
|
|
1268
1193
|
* POST one compiled document and fail with its classified errors. Queries
|
|
1269
1194
|
* are retried (bounded) while every failure is retryable; mutations never
|
|
1270
1195
|
* are, since an error can follow a side effect that already happened.
|
|
1271
1196
|
*/
|
|
1272
|
-
const execute = (
|
|
1273
|
-
compiled: Compiled,
|
|
1274
|
-
): Effect.Effect<unknown, ExecuteError, GqlTransport> => {
|
|
1197
|
+
const execute = (compiled: Compiled): Effect.Effect<unknown, ExecuteError, GqlTransport> => {
|
|
1275
1198
|
const once = Effect.gen(function* () {
|
|
1276
1199
|
const transport = yield* GqlTransport;
|
|
1277
1200
|
const response = yield* transport.execute(compiled);
|
|
@@ -1304,9 +1227,7 @@ type ExecuteError = GraphQLIssue | GraphQLFailure | GraphQLTransportError;
|
|
|
1304
1227
|
|
|
1305
1228
|
const isRetryable = (compiled: Compiled, error: ExecuteError): boolean => {
|
|
1306
1229
|
if (error instanceof GraphQLTransportError) {
|
|
1307
|
-
return
|
|
1308
|
-
error.status === undefined || error.status === 429 || error.status >= 500
|
|
1309
|
-
);
|
|
1230
|
+
return error.status === undefined || error.status === 429 || error.status >= 500;
|
|
1310
1231
|
}
|
|
1311
1232
|
const retryable = new Set(
|
|
1312
1233
|
[...compiled.rootErrors.values()].flatMap((root) =>
|
|
@@ -1332,10 +1253,7 @@ const classify = (
|
|
|
1332
1253
|
response: GraphQLResponse,
|
|
1333
1254
|
): GraphQLIssue => {
|
|
1334
1255
|
const path = Array.isArray(raw.path) ? raw.path : undefined;
|
|
1335
|
-
const root =
|
|
1336
|
-
typeof path?.[0] === "string"
|
|
1337
|
-
? compiled.rootErrors.get(path[0])
|
|
1338
|
-
: undefined;
|
|
1256
|
+
const root = typeof path?.[0] === "string" ? compiled.rootErrors.get(path[0]) : undefined;
|
|
1339
1257
|
const candidates = root
|
|
1340
1258
|
? root.errors
|
|
1341
1259
|
: uniqueByTag(
|
|
@@ -1365,10 +1283,7 @@ const classify = (
|
|
|
1365
1283
|
? raw.traceId
|
|
1366
1284
|
: undefined,
|
|
1367
1285
|
status: response.status,
|
|
1368
|
-
retryAfter:
|
|
1369
|
-
retryHeader && /^\d+(\.\d+)?$/.test(retryHeader)
|
|
1370
|
-
? Number(retryHeader)
|
|
1371
|
-
: undefined,
|
|
1286
|
+
retryAfter: retryHeader && /^\d+(\.\d+)?$/.test(retryHeader) ? Number(retryHeader) : undefined,
|
|
1372
1287
|
};
|
|
1373
1288
|
const matches = candidates.flatMap((spec) =>
|
|
1374
1289
|
spec.matchers
|
|
@@ -1376,24 +1291,19 @@ const classify = (
|
|
|
1376
1291
|
(matcher) =>
|
|
1377
1292
|
(matcher.code === undefined || matcher.code === code) &&
|
|
1378
1293
|
(matcher.message === undefined || matcher.message === message) &&
|
|
1379
|
-
(matcher.messageIncludes === undefined ||
|
|
1380
|
-
message.includes(matcher.messageIncludes)),
|
|
1294
|
+
(matcher.messageIncludes === undefined || message.includes(matcher.messageIncludes)),
|
|
1381
1295
|
)
|
|
1382
1296
|
.map((matcher) => ({
|
|
1383
1297
|
spec,
|
|
1384
1298
|
score:
|
|
1385
|
-
(matcher.code ? 1 : 0) +
|
|
1386
|
-
(matcher.message ? 4 : 0) +
|
|
1387
|
-
(matcher.messageIncludes ? 2 : 0),
|
|
1299
|
+
(matcher.code ? 1 : 0) + (matcher.message ? 4 : 0) + (matcher.messageIncludes ? 2 : 0),
|
|
1388
1300
|
})),
|
|
1389
1301
|
);
|
|
1390
1302
|
matches.sort((a, b) => b.score - a.score);
|
|
1391
1303
|
const best = matches[0];
|
|
1392
1304
|
if (
|
|
1393
1305
|
best &&
|
|
1394
|
-
!matches.some(
|
|
1395
|
-
(match) => match.score === best.score && match.spec.tag !== best.spec.tag,
|
|
1396
|
-
)
|
|
1306
|
+
!matches.some((match) => match.score === best.score && match.spec.tag !== best.spec.tag)
|
|
1397
1307
|
) {
|
|
1398
1308
|
return best.spec.make(props);
|
|
1399
1309
|
}
|
|
@@ -1428,9 +1338,7 @@ const filterImpl = (
|
|
|
1428
1338
|
|
|
1429
1339
|
export function filterQuery<Item, Error = never>(
|
|
1430
1340
|
predicate: (item: Query<Item>) => QueryNode<boolean, any>,
|
|
1431
|
-
): (
|
|
1432
|
-
source: QueryNode<readonly Item[] | null, Error>,
|
|
1433
|
-
) => Query<readonly Item[], Error>;
|
|
1341
|
+
): (source: QueryNode<readonly Item[] | null, Error>) => Query<readonly Item[], Error>;
|
|
1434
1342
|
export function filterQuery<Item, Error = never>(
|
|
1435
1343
|
source: QueryNode<readonly Item[] | null, Error>,
|
|
1436
1344
|
predicate: (item: Query<Item>) => QueryNode<boolean, any>,
|
|
@@ -1453,18 +1361,13 @@ type MapInput<Value> = [NonNullable<Value>] extends [ReadonlyArray<infer Item>]
|
|
|
1453
1361
|
: Value;
|
|
1454
1362
|
|
|
1455
1363
|
/** An object mapped through a `null` value stays `null`. */
|
|
1456
|
-
type MapOutput<Value, Mapped> = [NonNullable<Value>] extends [
|
|
1457
|
-
ReadonlyArray<unknown>,
|
|
1458
|
-
]
|
|
1364
|
+
type MapOutput<Value, Mapped> = [NonNullable<Value>] extends [ReadonlyArray<unknown>]
|
|
1459
1365
|
? ReadonlyArray<UnwrapPlan<Mapped>>
|
|
1460
1366
|
: [NonNullable<Value>] extends [object]
|
|
1461
1367
|
? UnwrapPlan<Mapped> | Nullish<Value>
|
|
1462
1368
|
: Mapped;
|
|
1463
1369
|
|
|
1464
|
-
const mapImpl = (
|
|
1465
|
-
source: QueryNode,
|
|
1466
|
-
mapFn: (value: any) => unknown,
|
|
1467
|
-
): Query<unknown> => {
|
|
1370
|
+
const mapImpl = (source: QueryNode, mapFn: (value: any) => unknown): Query<unknown> => {
|
|
1468
1371
|
if (source.expr.type.tag === "object") {
|
|
1469
1372
|
const mapped = mapFn(
|
|
1470
1373
|
new QueryNode({
|
|
@@ -1516,10 +1419,7 @@ export function mapQuery(sourceOrMapFn: any, mapFn?: any): any {
|
|
|
1516
1419
|
return mapImpl(sourceOrMapFn, mapFn);
|
|
1517
1420
|
}
|
|
1518
1421
|
|
|
1519
|
-
const flatMapImpl = (
|
|
1520
|
-
source: QueryNode,
|
|
1521
|
-
flatMapFn: (value: unknown) => unknown,
|
|
1522
|
-
): Query<unknown> => {
|
|
1422
|
+
const flatMapImpl = (source: QueryNode, flatMapFn: (value: unknown) => unknown): Query<unknown> => {
|
|
1523
1423
|
log("flatMap", printExpr(source.expr));
|
|
1524
1424
|
return make({
|
|
1525
1425
|
_tag: "FlatMap",
|
|
@@ -1529,26 +1429,12 @@ const flatMapImpl = (
|
|
|
1529
1429
|
});
|
|
1530
1430
|
};
|
|
1531
1431
|
|
|
1532
|
-
export function flatMapQuery<
|
|
1533
|
-
Value,
|
|
1534
|
-
Result,
|
|
1535
|
-
Error,
|
|
1536
|
-
Requirements,
|
|
1537
|
-
SourceError = never,
|
|
1538
|
-
>(
|
|
1432
|
+
export function flatMapQuery<Value, Result, Error, Requirements, SourceError = never>(
|
|
1539
1433
|
flatMapFn: (
|
|
1540
1434
|
value: Value,
|
|
1541
1435
|
) => Effect.Effect<Result, Error, Requirements> | QueryNode<Result, Error>,
|
|
1542
|
-
): (
|
|
1543
|
-
|
|
1544
|
-
) => Query<Result, SourceError | Error>;
|
|
1545
|
-
export function flatMapQuery<
|
|
1546
|
-
Value,
|
|
1547
|
-
Result,
|
|
1548
|
-
Error,
|
|
1549
|
-
Requirements,
|
|
1550
|
-
SourceError = never,
|
|
1551
|
-
>(
|
|
1436
|
+
): (source: QueryNode<Value, SourceError>) => Query<Result, SourceError | Error>;
|
|
1437
|
+
export function flatMapQuery<Value, Result, Error, Requirements, SourceError = never>(
|
|
1552
1438
|
source: QueryNode<Value, SourceError>,
|
|
1553
1439
|
flatMapFn: (
|
|
1554
1440
|
value: Value,
|
|
@@ -1571,11 +1457,7 @@ export const queryFn =
|
|
|
1571
1457
|
build: (...args: Arguments) => Plan,
|
|
1572
1458
|
): ((
|
|
1573
1459
|
...args: Arguments
|
|
1574
|
-
) => Effect.Effect<
|
|
1575
|
-
UnwrapPlan<Plan>,
|
|
1576
|
-
QueryError<PlanError<Plan>>,
|
|
1577
|
-
GqlTransport
|
|
1578
|
-
>) =>
|
|
1460
|
+
) => Effect.Effect<UnwrapPlan<Plan>, QueryError<PlanError<Plan>>, GqlTransport>) =>
|
|
1579
1461
|
(...args) => {
|
|
1580
1462
|
const plan = build(...args);
|
|
1581
1463
|
return evaluatePlan(plan);
|
|
@@ -1595,9 +1477,7 @@ const connectionOf = (expr: Expr): RootExpr | PropExpr => {
|
|
|
1595
1477
|
(base._tag === "Root" && base.connection === true) ||
|
|
1596
1478
|
(base._tag === "Prop" && base.field.kind === "connection");
|
|
1597
1479
|
if (!isConnection || inItem(base)) {
|
|
1598
|
-
throw new GqlError(
|
|
1599
|
-
`Query.pages needs a Relay connection, got ${printExpr(base)}`,
|
|
1600
|
-
);
|
|
1480
|
+
throw new GqlError(`Query.pages needs a Relay connection, got ${printExpr(base)}`);
|
|
1601
1481
|
}
|
|
1602
1482
|
const argTypes = base._tag === "Root" ? base.argTypes : base.field.argTypes;
|
|
1603
1483
|
if (!argTypes || !("after" in argTypes)) {
|
|
@@ -1607,11 +1487,7 @@ const connectionOf = (expr: Expr): RootExpr | PropExpr => {
|
|
|
1607
1487
|
};
|
|
1608
1488
|
|
|
1609
1489
|
/** Rebuild `expr` with the connection's `after` argument set. */
|
|
1610
|
-
const withCursor = (
|
|
1611
|
-
expr: Expr,
|
|
1612
|
-
connection: Expr,
|
|
1613
|
-
after: string | undefined,
|
|
1614
|
-
): Expr => {
|
|
1490
|
+
const withCursor = (expr: Expr, connection: Expr, after: string | undefined): Expr => {
|
|
1615
1491
|
if (expr === connection) {
|
|
1616
1492
|
const current = expr as RootExpr | PropExpr;
|
|
1617
1493
|
return { ...current, args: { ...current.args, after } } as Expr;
|
|
@@ -1653,27 +1529,18 @@ const fetchPage = <Item>(
|
|
|
1653
1529
|
const pageExpr = withCursor(query.expr, connection, state.after);
|
|
1654
1530
|
const forest = emptyForest();
|
|
1655
1531
|
visitExpr(forest, pageExpr);
|
|
1656
|
-
const nodePath = paintAbs(
|
|
1657
|
-
forest,
|
|
1658
|
-
withCursor(connection, connection, state.after),
|
|
1659
|
-
);
|
|
1532
|
+
const nodePath = paintAbs(forest, withCursor(connection, connection, state.after));
|
|
1660
1533
|
const connectionPath = nodePath.slice(0, -2);
|
|
1661
|
-
const pageInfo = ensureChild(
|
|
1662
|
-
forest,
|
|
1663
|
-
selAt(forest.roots, connectionPath),
|
|
1664
|
-
"pageInfo",
|
|
1665
|
-
{},
|
|
1666
|
-
);
|
|
1534
|
+
const pageInfo = ensureChild(forest, selAt(forest.roots, connectionPath), "pageInfo", {});
|
|
1667
1535
|
ensureChild(forest, pageInfo, "hasNextPage", { isScalar: true });
|
|
1668
1536
|
ensureChild(forest, pageInfo, "endCursor", { isScalar: true });
|
|
1669
1537
|
const compiled = emit(forest);
|
|
1670
1538
|
log("page\n" + compiled.document);
|
|
1671
1539
|
const data = yield* execute(compiled);
|
|
1672
|
-
const items = (yield* interpretPlan(
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
)) as ReadonlyArray<Item> | null | undefined;
|
|
1540
|
+
const items = (yield* interpretPlan(make(pageExpr), data, compiled.rootAlias)) as
|
|
1541
|
+
| ReadonlyArray<Item>
|
|
1542
|
+
| null
|
|
1543
|
+
| undefined;
|
|
1677
1544
|
const info = readPath(data, [...connectionPath, "pageInfo"]) as
|
|
1678
1545
|
| { hasNextPage?: boolean; endCursor?: string | null }
|
|
1679
1546
|
| null
|
|
@@ -1702,11 +1569,7 @@ const fetchPage = <Item>(
|
|
|
1702
1569
|
*/
|
|
1703
1570
|
export const pagesQuery = <Item, Error>(
|
|
1704
1571
|
query: QueryNode<ReadonlyArray<Item> | null, Error>,
|
|
1705
|
-
): Stream.Stream<
|
|
1706
|
-
ReadonlyArray<Item>,
|
|
1707
|
-
QueryError<Error> | GraphQLPaginationError,
|
|
1708
|
-
GqlTransport
|
|
1709
|
-
> =>
|
|
1572
|
+
): Stream.Stream<ReadonlyArray<Item>, QueryError<Error> | GraphQLPaginationError, GqlTransport> =>
|
|
1710
1573
|
Stream.unwrap(
|
|
1711
1574
|
Effect.sync(() => {
|
|
1712
1575
|
const connection = connectionOf(query.expr);
|
|
@@ -1725,10 +1588,7 @@ export const pagesQuery = <Item, Error>(
|
|
|
1725
1588
|
fetchPage(query, connection, state).pipe(
|
|
1726
1589
|
Effect.map(([items, next]) => [[items], next] as const),
|
|
1727
1590
|
) as Effect.Effect<
|
|
1728
|
-
readonly [
|
|
1729
|
-
ReadonlyArray<ReadonlyArray<Item>>,
|
|
1730
|
-
Option.Option<PageState>,
|
|
1731
|
-
],
|
|
1591
|
+
readonly [ReadonlyArray<ReadonlyArray<Item>>, Option.Option<PageState>],
|
|
1732
1592
|
QueryError<Error> | GraphQLPaginationError,
|
|
1733
1593
|
GqlTransport
|
|
1734
1594
|
>,
|
|
@@ -1739,8 +1599,5 @@ export const pagesQuery = <Item, Error>(
|
|
|
1739
1599
|
/** Every node of a Relay connection, across all pages. */
|
|
1740
1600
|
export const itemsQuery = <Item, Error>(
|
|
1741
1601
|
query: QueryNode<ReadonlyArray<Item> | null, Error>,
|
|
1742
|
-
): Stream.Stream<
|
|
1743
|
-
|
|
1744
|
-
QueryError<Error> | GraphQLPaginationError,
|
|
1745
|
-
GqlTransport
|
|
1746
|
-
> => pagesQuery(query).pipe(Stream.flatMap(Stream.fromIterable));
|
|
1602
|
+
): Stream.Stream<Item, QueryError<Error> | GraphQLPaginationError, GqlTransport> =>
|
|
1603
|
+
pagesQuery(query).pipe(Stream.flatMap(Stream.fromIterable));
|