@pothos/selection-mapper 0.1.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 (86) hide show
  1. package/.swcrc +10 -0
  2. package/LICENSE +6 -0
  3. package/README.md +92 -0
  4. package/dts/adapter.d.ts +74 -0
  5. package/dts/adapter.d.ts.map +1 -0
  6. package/dts/deep-equal.d.ts +7 -0
  7. package/dts/deep-equal.d.ts.map +1 -0
  8. package/dts/index.d.ts +13 -0
  9. package/dts/index.d.ts.map +1 -0
  10. package/dts/loader-map.d.ts +63 -0
  11. package/dts/loader-map.d.ts.map +1 -0
  12. package/dts/matches.d.ts +113 -0
  13. package/dts/matches.d.ts.map +1 -0
  14. package/dts/node.d.ts +85 -0
  15. package/dts/node.d.ts.map +1 -0
  16. package/dts/plan.d.ts +176 -0
  17. package/dts/plan.d.ts.map +1 -0
  18. package/dts/types.d.ts +97 -0
  19. package/dts/types.d.ts.map +1 -0
  20. package/dts/walk.d.ts +24 -0
  21. package/dts/walk.d.ts.map +1 -0
  22. package/esm/adapter.d.ts +74 -0
  23. package/esm/adapter.d.ts.map +1 -0
  24. package/esm/adapter.js +47 -0
  25. package/esm/adapter.js.map +1 -0
  26. package/esm/deep-equal.d.ts +7 -0
  27. package/esm/deep-equal.d.ts.map +1 -0
  28. package/esm/deep-equal.js +50 -0
  29. package/esm/deep-equal.js.map +1 -0
  30. package/esm/index.d.ts +13 -0
  31. package/esm/index.d.ts.map +1 -0
  32. package/esm/index.js +12 -0
  33. package/esm/index.js.map +1 -0
  34. package/esm/loader-map.d.ts +63 -0
  35. package/esm/loader-map.d.ts.map +1 -0
  36. package/esm/loader-map.js +197 -0
  37. package/esm/loader-map.js.map +1 -0
  38. package/esm/matches.d.ts +113 -0
  39. package/esm/matches.d.ts.map +1 -0
  40. package/esm/matches.js +419 -0
  41. package/esm/matches.js.map +1 -0
  42. package/esm/node.d.ts +85 -0
  43. package/esm/node.d.ts.map +1 -0
  44. package/esm/node.js +232 -0
  45. package/esm/node.js.map +1 -0
  46. package/esm/package.json +3 -0
  47. package/esm/plan.d.ts +176 -0
  48. package/esm/plan.d.ts.map +1 -0
  49. package/esm/plan.js +339 -0
  50. package/esm/plan.js.map +1 -0
  51. package/esm/types.d.ts +97 -0
  52. package/esm/types.d.ts.map +1 -0
  53. package/esm/types.js +10 -0
  54. package/esm/types.js.map +1 -0
  55. package/esm/walk.d.ts +24 -0
  56. package/esm/walk.d.ts.map +1 -0
  57. package/esm/walk.js +442 -0
  58. package/esm/walk.js.map +1 -0
  59. package/lib/adapter.js +43 -0
  60. package/lib/adapter.js.map +1 -0
  61. package/lib/deep-equal.js +60 -0
  62. package/lib/deep-equal.js.map +1 -0
  63. package/lib/index.js +57 -0
  64. package/lib/index.js.map +1 -0
  65. package/lib/loader-map.js +209 -0
  66. package/lib/loader-map.js.map +1 -0
  67. package/lib/matches.js +427 -0
  68. package/lib/matches.js.map +1 -0
  69. package/lib/node.js +245 -0
  70. package/lib/node.js.map +1 -0
  71. package/lib/plan.js +349 -0
  72. package/lib/plan.js.map +1 -0
  73. package/lib/types.js +9 -0
  74. package/lib/types.js.map +1 -0
  75. package/lib/walk.js +455 -0
  76. package/lib/walk.js.map +1 -0
  77. package/package.json +55 -0
  78. package/src/adapter.ts +96 -0
  79. package/src/deep-equal.ts +67 -0
  80. package/src/index.ts +32 -0
  81. package/src/loader-map.ts +287 -0
  82. package/src/matches.ts +681 -0
  83. package/src/node.ts +327 -0
  84. package/src/plan.ts +454 -0
  85. package/src/types.ts +123 -0
  86. package/src/walk.ts +696 -0
package/dts/plan.d.ts ADDED
@@ -0,0 +1,176 @@
1
+ import { type GraphQLNamedType, type GraphQLResolveInfo } from 'graphql';
2
+ import type { Adapter, NodeBase } from './adapter.js';
3
+ import { type Mapping, type Mappings } from './loader-map.js';
4
+ import type { Node } from './node.js';
5
+ import type { EntryOptions, Position, WalkedType } from './types.js';
6
+ /**
7
+ * One merge a traversal collected, in the order it happened: a type's selection, a same-model
8
+ * variant's, a nested selection's relation query, or a field's. A play folds the list into a
9
+ * node; nothing is merged, accepted or rejected before then.
10
+ *
11
+ * A record holds its query by reference, so a select function that mutates the query it returned
12
+ * after returning it changes what a later play builds — a bug in the select function. Nothing
13
+ * copies it: a query is opaque to this package, which could only copy one by round-tripping it
14
+ * through the adapter on every field.
15
+ */
16
+ export type RootMerge<Query> = {
17
+ kind: 'type';
18
+ query: Query;
19
+ } | {
20
+ kind: 'query';
21
+ query: Query;
22
+ } | {
23
+ kind: 'variant';
24
+ type: WalkedType;
25
+ variant: WalkedType;
26
+ query: Query;
27
+ } | {
28
+ kind: 'field';
29
+ key: string;
30
+ alias: string;
31
+ query: Query;
32
+ mapping: Mapping;
33
+ };
34
+ /**
35
+ * A plan played: the node its merges built and the mappings the accepted merges recorded. A play
36
+ * owns its node, so a caller may merge into one without disturbing the plan or another play.
37
+ */
38
+ export interface PlayedPlan<Model, Query, NodeType extends NodeBase<Model> = Node<Model>> {
39
+ plan: Plan<Model, Query, NodeType>;
40
+ root: NodeType;
41
+ mappings: Mappings;
42
+ }
43
+ /**
44
+ * What a plan takes from whatever created it: an entry point's options, or the plan it hangs
45
+ * beneath. A parent plan satisfies this, so a nested plan is created from its parent directly
46
+ * with nothing allocated to carry the values across.
47
+ */
48
+ export interface PlanSource {
49
+ context: object;
50
+ info: GraphQLResolveInfo;
51
+ /** Whether a fragment under `@defer` is walked; defaults to the adapter's own setting. */
52
+ skipDeferredFragments?: boolean;
53
+ }
54
+ export declare class Plan<Model, Query, NodeType extends NodeBase<Model> = Node<Model>> {
55
+ readonly adapter: Adapter<Model, Query, NodeType>;
56
+ readonly position?: Position | undefined;
57
+ /** Merged first by a play a caller gives no seed of its own. */
58
+ readonly initial?: Query | undefined;
59
+ readonly context: object;
60
+ readonly info: GraphQLResolveInfo;
61
+ readonly skipDeferredFragments: boolean;
62
+ /** What the plan loads. A node is created for it once per play. */
63
+ readonly model: Model;
64
+ /**
65
+ * The merges waiting on a user callback that returned a promise, in the order they were
66
+ * appended. Absent until the first one: a synchronous plan never creates a promise.
67
+ */
68
+ pending?: Promise<void>;
69
+ /** The traversal's whole output: every merge it collected, in the order it collected them. */
70
+ private readonly merges;
71
+ /**
72
+ * The play `settle` ran, which a later play takes whole when the seed conflicts with none of
73
+ * it. Never handed out: a play that reuses it copies it into a node of its own.
74
+ */
75
+ private played?;
76
+ /**
77
+ * The plan for the field `info` resolves, settled, or undefined when paths are given and
78
+ * nothing is selected under them. Declared synchronous: the result is a promise only when a
79
+ * select function returned one, and must then be awaited. The plan is handed out rather than
80
+ * played, so a plugin that owes a resolver a synchronous query builder settles this first and
81
+ * plays it behind the resolver's own selection with `plan.query(select)`.
82
+ */
83
+ static fromInfo<Model, Query, NodeType extends NodeBase<Model> = Node<Model>>(adapter: Adapter<Model, Query, NodeType>, options: EntryOptions<Query>): Plan<Model, Query, NodeType> | undefined;
84
+ /**
85
+ * The plan loading the field `info` resolves for its parent row, played. The loaded row
86
+ * replaces the parent the field resolver sees, so besides the field's own selection it
87
+ * carries the parent type's type-level selection. The field is what the row is loaded for, so
88
+ * it is merged first and a type-level relation whose arguments conflict with it is left out.
89
+ */
90
+ static forParentRow<Model, Query, NodeType extends NodeBase<Model> = Node<Model>>(adapter: Adapter<Model, Query, NodeType>, context: object, info: GraphQLResolveInfo, skipDeferredFragments?: boolean): PlayedPlan<Model, Query, NodeType>;
91
+ /**
92
+ * `source` is an entry point's options for a root plan and the parent plan for a nested one,
93
+ * which is why `initial` is passed beside it: it belongs to the root alone and a nested plan
94
+ * must never inherit one. `position` is where the field this plan hangs beneath is, undefined
95
+ * when there is no field above the plan.
96
+ */
97
+ constructor(adapter: Adapter<Model, Query, NodeType>, source: PlanSource, type: GraphQLNamedType, position?: Position | undefined,
98
+ /** Merged first by a play a caller gives no seed of its own. */
99
+ initial?: Query | undefined);
100
+ /**
101
+ * The plan beneath one nested selection: this plan's adapter, context, info and deferred
102
+ * setting, with merges of its own. It hangs beneath the field whose select function made it.
103
+ */
104
+ nested(type: GraphQLNamedType, position: Position): Plan<Model, Query, NodeType>;
105
+ /** Appends one merge to the list a play folds. The traversal's only way to add to a plan. */
106
+ collect(merge: RootMerge<Query>): void;
107
+ /**
108
+ * The relation query of the nested selection this plan was made for. It takes the head of the
109
+ * list, so it is merged before the fields walked beneath it whether the callback that produced
110
+ * it answered at once or resolved after the walk. A nested plan has at most one.
111
+ */
112
+ collectQuery(query: Query): void;
113
+ /**
114
+ * Appends the merge of `value` to the plan's pending chain. Only merges are chained, never user
115
+ * code, so a link can never append another and the chain needs no loop. Each link waits on the
116
+ * previous one, so async merges run in the order they were appended. Both promises get a
117
+ * handler at once, so a callback that rejects early is never an unhandled rejection.
118
+ */
119
+ chain<T>(value: PromiseLike<T>, merge: (v: T) => void): void;
120
+ /**
121
+ * A plan that threw synchronously never reaches `finish`, so the merges it had already chained
122
+ * would reject unobserved once their callbacks settle. The throw is what the caller sees.
123
+ */
124
+ abandon(): void;
125
+ /**
126
+ * The single exit of every entry point: `done`, a method of this plan, runs now when nothing is
127
+ * pending, else after every pending merge, in which case the result is a promise behind the
128
+ * declared synchronous type. Fixed arity, so the synchronous call allocates nothing.
129
+ */
130
+ finish<R>(done: (this: this) => R): R;
131
+ finish<A, R>(done: (this: this, arg: A) => R, arg: A): R;
132
+ /**
133
+ * A fresh node with this plan's merges folded into it, and the mappings of the merges it took.
134
+ * `seed` takes the place of the plan's own `initial`: it is merged before anything the traversal
135
+ * collected, so a relation or computed value the document plans with other arguments loses, and
136
+ * its field falls back to loading on its own.
137
+ *
138
+ * Synchronous, and runs no user callback, so a play of an async plan costs no more than a play
139
+ * of a synchronous one.
140
+ */
141
+ play(seed?: Query): PlayedPlan<Model, Query, NodeType>;
142
+ /**
143
+ * The plan played behind `seed`, its mappings recorded for the resolvers beneath it, and its
144
+ * node serialized. A cached plan accepts the current resolver info to scope each execution.
145
+ * Every play records its mappings on the request context; an adapter whose
146
+ * resolvers read a loaded row another way simply never looks them up.
147
+ */
148
+ query(seed?: Query, info?: GraphQLResolveInfo): Query;
149
+ /**
150
+ * The plan played once, so a play-time error — a conflict between two type-level selections —
151
+ * is raised now rather than only inside a `query()` a resolver may never call. That play is
152
+ * kept, and a later one whose seed conflicts with none of it takes it whole, so settling costs
153
+ * the resolver's own play nothing.
154
+ */
155
+ settle(): this;
156
+ /**
157
+ * The plan played, with `type`'s type-level selection merged in behind it, minus what conflicts
158
+ * with the field the row is loaded for. A parent-row plan is never replayed behind a caller's
159
+ * selection, so it plays once, here.
160
+ */
161
+ enterParentType(type: GraphQLNamedType): PlayedPlan<Model, Query, NodeType>;
162
+ /**
163
+ * A settled play that a play seeded with `seed` can take whole, or undefined. A seed conflicting
164
+ * with nothing the settled play holds changes no decision it made, since every rejection was
165
+ * against something the seed leaves in place — unless the seed stands in for the plan's own
166
+ * `initial`, which the settled play already merged.
167
+ */
168
+ private reusable;
169
+ /**
170
+ * Unlike a field-level select, a type-level selection has no per-field fallback, so a relation
171
+ * argument or a computed value that conflicts with what is already in the node is an error
172
+ * rather than a rejection.
173
+ */
174
+ private mergeVariant;
175
+ }
176
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,kBAAkB,EAAgB,MAAM,SAAS,CAAC;AACvF,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAoC,MAAM,iBAAiB,CAAC;AAUhG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAgB,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAOnF;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,CAAC,KAAK,IACvB;IAAE,IAAI,EAAE,MA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ter contract and the entry points mention: where a field is, what a select
3
+ * function is handed, what an entry point takes, and how one merge differs from a plain one.
4
+ */
5
+ import type { MaybePromise } from '@pothos/core';
6
+ import type { FieldNode, GraphQLField, GraphQLInterfaceType, GraphQLObjectType, GraphQLResolveInfo } from 'graphql';
7
+ import type { IndirectInclude, PathSegment } from './matches.js';
8
+ export type WalkedType = GraphQLInterfaceType | GraphQLObjectType;
9
+ /**
10
+ * Where a field is. One link of a chain running from the field an entry point was called for down
11
+ * to the field being planned: the field's node in the document, the type it was found on, and the
12
+ * position of the field the plan it was found in hangs beneath.
13
+ *
14
+ * The walker builds one per select invocation and reads none of it, so a caller that wants a path
15
+ * or a name walks `parent` itself and materializes what it needs. A plan whose fields nothing asks
16
+ * about costs one link per select function and no arrays at all.
17
+ */
18
+ export interface Position {
19
+ /** The field this one is selected beneath, or undefined at the field the plan started from. */
20
+ readonly parent: Position | undefined;
21
+ /** The type the field was walked on: its parent type, or a same-model type the plan moved to. */
22
+ readonly type: WalkedType;
23
+ readonly field: GraphQLField<unknown, unknown>;
24
+ /** The field's node in the document, which carries its alias and arguments. */
25
+ readonly node: FieldNode;
26
+ }
27
+ /** A relation query: a query, or a callback building one from the field's arguments. */
28
+ export type NestedQuery<Query> = MaybePromise<Query | null | undefined> | ((args: object, ctx: object, position: Position) => MaybePromise<Query | null | undefined>);
29
+ /**
30
+ * The callback handed to a field's select function to plan the selection beneath the field:
31
+ * `query` is merged first (a function is called with the field's args, `true` means no query),
32
+ * then the selection found under `path` (an explicit include, or a string path from the field's
33
+ * return type) is walked as `type` (or the field's return type). Declared synchronous: the result
34
+ * is a promise only when a callback beneath it returned one, and must then be awaited.
35
+ */
36
+ export type NestedSelection<Query> = (query?: NestedQuery<Query> | true, path?: PathSegment[] | IndirectInclude, type?: string) => Query;
37
+ /** Inspect fields beneath the current selection, through fragments and wrappers. */
38
+ export interface SelectedFieldNode {
39
+ /** Lazily collect selected schema field names; aliases do not change the names. */
40
+ (): ReadonlySet<string>;
41
+ (path: string[]): FieldNode | null;
42
+ }
43
+ /** A function field selection. A falsy result selects nothing. */
44
+ export type SelectFn<Query> = (args: object, ctx: object, nested: NestedSelection<Query>, selectedFieldNode: SelectedFieldNode, position: Position) => MaybePromise<Query | false | null | undefined>;
45
+ export interface EntryOptions<Query> {
46
+ context: object;
47
+ info: GraphQLResolveInfo;
48
+ typeName?: string;
49
+ path?: PathSegment[];
50
+ paths?: PathSegment[][];
51
+ /**
52
+ * Merged into the root before anything is walked, so on a conflict it wins. `Plan.fromInfo`
53
+ * answers undefined when paths are given and nothing is selected under them; what a caller
54
+ * hands its resolver then is the caller's own rule, not this package's.
55
+ */
56
+ initial?: Query;
57
+ /**
58
+ * Overrides `Adapter.skipDeferredFragments` for this plan. The setting belongs to a builder
59
+ * while prisma's adapter is a module singleton, so that plugin passes it per entry point
60
+ * instead of putting it on the adapter.
61
+ */
62
+ skipDeferredFragments?: boolean;
63
+ }
64
+ /** How one merge into an adapter's node differs from a plain one. */
65
+ export interface MergeOptions {
66
+ /**
67
+ * The node's own top-level arguments are not compared. A field's selection is merged into a
68
+ * node whose arguments came from somewhere else, so only what is nested below is checked.
69
+ */
70
+ ignoreArgs?: boolean;
71
+ /**
72
+ * The query is a relation query, not a selection. A query without a column selection must add
73
+ * no columns: the plan beneath it adds the ones it needs.
74
+ */
75
+ asQuery?: boolean;
76
+ /**
77
+ * Keys that conflict with what the node holds are left out, one at a time, instead of the merge
78
+ * being refused or throwing.
79
+ */
80
+ lenient?: boolean;
81
+ /**
82
+ * The response key of the field the query came from, so an adapter that keeps one slot per
83
+ * selected field can name it. Absent for a type-level selection, an initial selection and a
84
+ * staged query.
85
+ */
86
+ alias?: string;
87
+ }
88
+ /**
89
+ * A key of a type-level selection that cannot be merged with what a node already holds. `kind`
90
+ * chooses the error message, so it is the ORM's own word for the key rather than this package's:
91
+ * prisma reports a conflicting `_count` as a `relation`, since that is what a user wrote.
92
+ */
93
+ export interface TypeLevelConflict {
94
+ kind: 'extra' | 'relation';
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AACpF,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;CACpC;AAED,kEAAkE;AAClE,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI,CAC5B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,EAC9B,iBAAiB,EAAE,iBAAiB,EACpC,QAAQ,EAAE,QAAQ,KACf,YAAY,CAAC,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEpD,MAAM,WAAW,YAAY,CAAC,KAAK;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,kBAAkB,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd"}
package/dts/walk.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { type FieldNode, type GraphQLNamedType } from 'graphql';
2
+ import type { NodeBase } from './adapter.js';
3
+ import type { Plan } from './plan.js';
4
+ import type { WalkedType } from './types.js';
5
+ /**
6
+ * One selection to walk into a plan, before any indirect include on `type` is followed: the
7
+ * selection sets of `fieldNodes` (every node selecting one field), walked as `type`.
8
+ */
9
+ export interface Branch {
10
+ type: GraphQLNamedType;
11
+ fieldNodes: readonly FieldNode[];
12
+ indirectPath: string[];
13
+ deferred: boolean;
14
+ }
15
+ /**
16
+ * Walks every branch into `plan`. The types the selections are walked as, and the variants their
17
+ * fragments move to, are all collected before any field is, so type-level selections come first
18
+ * in the merge list and the plan does not depend on which occurrence of a field, or which path
19
+ * match, came first in the document.
20
+ */
21
+ export declare function walkBranches<Model, Query, NodeType extends NodeBase<Model>>(plan: Plan<Model, Query, NodeType>, branches: Branch[]): void;
22
+ /** Collects what `fieldNode` (a field of `type`) selects. */
23
+ export declare function walkField<Model, Query, NodeType extends NodeBase<Model>>(plan: Plan<Model, Query, NodeType>, type: WalkedType, fieldNode: FieldNode, indirectPath: string[]): void;
24
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,SAAS,EAGd,KAAK,gBAAgB,EAOtB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAc7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAuC,UAAU,EAAE,MAAM,YAAY,CAAC;AAwClF;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,gBAAgB,CAAC;IACvB,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IACjC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAYD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,SAAS,QAAQ,CAAC,KAAK,CAAC,EACzE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAClC,QAAQ,EAAE,MAAM,EAAE,QAoCnB;AA4ND,6DAA6D;AAC7D,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,SAAS,QAAQ,CAAC,KAAK,CAAC,EACtE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAClC,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,EAAE,QAmDvB"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The ORM boundary: what an adapter tells the traversal, and where the selections it produces
3
+ * accumulate. One class, so an adapter's state and helpers have a home and the members it has
4
+ * nothing to say about are inherited rather than checked for.
5
+ */
6
+ import type { GraphQLField, GraphQLNamedType } from 'graphql';
7
+ import type { MergeOptions, SelectFn, TypeLevelConflict, WalkedType } from './types.js';
8
+ /**
9
+ * What the traversal requires of a node: the model it loads. `Model` is the adapter's model
10
+ * description: whatever it needs to look a relation's target up by name. One object per model,
11
+ * so model identity is the same as model equality.
12
+ */
13
+ export interface NodeBase<Model> {
14
+ model: Model;
15
+ }
16
+ /**
17
+ * The ORM boundary, translation only. `Model` is the model description a node carries, `Query`
18
+ * the ORM's own selection format (prisma `{ select, include, ...args }`, drizzle
19
+ * `DBQueryConfig`), opaque to the traversal, and `NodeType` what selections accumulate into, of
20
+ * which the traversal reads only `model`.
21
+ *
22
+ * Six members must be answered: three translate a schema into queries (`modelFor`,
23
+ * `typeSelection`, `fieldSelection`) and three accumulate them (`createNode`, `mergeQuery`,
24
+ * `toQuery`). The four below those are the merge rules, inherited with the answer an adapter with
25
+ * no conflicts to report wants: nothing ever conflicts, and node-to-node work round-trips through
26
+ * `toQuery`. An adapter that gives every consumer of a relation its own slot inherits all four.
27
+ *
28
+ * `NodeAdapter` in node.ts overrides all four over a concrete query tree, and is what the prisma
29
+ * and drizzle adapters extend; an adapter whose query is not such a tree extends this directly.
30
+ */
31
+ export declare abstract class Adapter<Model, Query, NodeType extends NodeBase<Model>> {
32
+ /**
33
+ * Whether a fragment under `@defer` is walked. `EntryOptions.skipDeferredFragments` overrides
34
+ * it for one entry point.
35
+ */
36
+ skipDeferredFragments: boolean;
37
+ /**
38
+ * The model a type carries, or undefined. Does not follow indirect includes (the walker's own
39
+ * `modelOf` does). One object per model: identity is model identity.
40
+ */
41
+ abstract modelFor(type: GraphQLNamedType): Model | undefined;
42
+ /** What the type always needs, merged whenever the type is entered, or undefined. */
43
+ abstract typeSelection(type: GraphQLNamedType): Query | undefined;
44
+ /**
45
+ * What the field selects: a static query, a select function, or nothing. `type` is the type the
46
+ * field is being walked on (its parent type, or a same-model type the plan moved to), for an
47
+ * adapter that classifies a selection's keys against the parent model.
48
+ */
49
+ abstract fieldSelection(field: GraphQLField<unknown, unknown>, type: WalkedType): Query | SelectFn<Query> | undefined;
50
+ /** A fresh, empty node for `model`. */
51
+ abstract createNode(model: Model): NodeType;
52
+ /** Folds `query` into `node`, in place. Never mutates `query`. */
53
+ abstract mergeQuery(node: NodeType, query: Query, options?: MergeOptions): void;
54
+ /** The node as a query of this ORM's format. */
55
+ abstract toQuery(node: NodeType): Query;
56
+ /**
57
+ * Whether merging `query` into `node` would leave everything already selected as it is. A yes
58
+ * or no; `firstConflict` is the version that names a key. Inherited: nothing ever conflicts.
59
+ */
60
+ canMergeQuery(_node: NodeType, _query: Query, _options?: MergeOptions): boolean;
61
+ /**
62
+ * The first key of a type-level `query` that conflicts with what `node` holds, for the error
63
+ * message that names it. Inherited: none.
64
+ */
65
+ firstConflict(_node: NodeType, _query: Query): TypeLevelConflict | undefined;
66
+ /**
67
+ * `mergeQuery` from another node: everything `from` holds, merged into `node`. Inherited: the
68
+ * round trip through `toQuery`.
69
+ */
70
+ mergeNode(node: NodeType, from: NodeType): void;
71
+ /** `canMergeQuery` node to node. Inherited: the round trip through `toQuery`. */
72
+ canMergeNode(node: NodeType, from: NodeType): boolean;
73
+ }
74
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExF;;;;GAIG;AACH,MAAM,WAAW,QAAQ,CAAC,KAAK;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,SAAS,QAAQ,CAAC,KAAK,CAAC;IAC1E;;;OAGG;IACH,qBAAqB,UAAQ;IAE7B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,CAAC;IAE7D,qFAAqF;IACrF,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,gBAAgB,GAAG,KAAK,GAAG,SAAS,CAAC;IAElE;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CACrB,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,EACrC,IAAI,EAAE,UAAU,GACf,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC;IAEvC,uCAAuC;IACvC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC;IAE5C,kEAAkE;IAClE,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAEhF,gDAAgD;IAChD,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,KAAK,CAAC;IAExC;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,OAAO,CAE9E;IAED;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,GAAG,iBAAiB,GAAG,SAAS,CAE3E;IAED;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAE9C;IAED,iFAAiF;IACjF,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAEpD;CACF"}
package/esm/adapter.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The ORM boundary: what an adapter tells the traversal, and where the selections it produces
3
+ * accumulate. One class, so an adapter's state and helpers have a home and the members it has
4
+ * nothing to say about are inherited rather than checked for.
5
+ */ /**
6
+ * The ORM boundary, translation only. `Model` is the model description a node carries, `Query`
7
+ * the ORM's own selection format (prisma `{ select, include, ...args }`, drizzle
8
+ * `DBQueryConfig`), opaque to the traversal, and `NodeType` what selections accumulate into, of
9
+ * which the traversal reads only `model`.
10
+ *
11
+ * Six members must be answered: three translate a schema into queries (`modelFor`,
12
+ * `typeSelection`, `fieldSelection`) and three accumulate them (`createNode`, `mergeQuery`,
13
+ * `toQuery`). The four below those are the merge rules, inherited with the answer an adapter with
14
+ * no conflicts to report wants: nothing ever conflicts, and node-to-node work round-trips through
15
+ * `toQuery`. An adapter that gives every consumer of a relation its own slot inherits all four.
16
+ *
17
+ * `NodeAdapter` in node.ts overrides all four over a concrete query tree, and is what the prisma
18
+ * and drizzle adapters extend; an adapter whose query is not such a tree extends this directly.
19
+ */ export class Adapter {
20
+ /**
21
+ * Whether a fragment under `@defer` is walked. `EntryOptions.skipDeferredFragments` overrides
22
+ * it for one entry point.
23
+ */ skipDeferredFragments = true;
24
+ /**
25
+ * Whether merging `query` into `node` would leave everything already selected as it is. A yes
26
+ * or no; `firstConflict` is the version that names a key. Inherited: nothing ever conflicts.
27
+ */ canMergeQuery(_node, _query, _options) {
28
+ return true;
29
+ }
30
+ /**
31
+ * The first key of a type-level `query` that conflicts with what `node` holds, for the error
32
+ * message that names it. Inherited: none.
33
+ */ firstConflict(_node, _query) {
34
+ return undefined;
35
+ }
36
+ /**
37
+ * `mergeQuery` from another node: everything `from` holds, merged into `node`. Inherited: the
38
+ * round trip through `toQuery`.
39
+ */ mergeNode(node, from) {
40
+ this.mergeQuery(node, this.toQuery(from));
41
+ }
42
+ /** `canMergeQuery` node to node. Inherited: the round trip through `toQuery`. */ canMergeNode(node, from) {
43
+ return this.canMergeQuery(node, this.toQuery(from));
44
+ }
45
+ }
46
+
47
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapter.ts"],"names":["Adapter","skipDeferredFragments","canMergeQuery","_node","_query","_options","firstConflict","undefined","mergeNode","node","from","mergeQuery","toQuery","canMergeNode"],"mappings":"AAAA;;;;CAIC,GAaD;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAeA;IACpB;;;GAGC,GACDC,wBAAwB,KAAK;IA8B7B;;;GAGC,GACDC,cAAcC,KAAe,EAAEC,MAAa,EAAEC,QAAuB,EAAW;QAC9E,OAAO;IACT;IAEA;;;GAGC,GACDC,cAAcH,KAAe,EAAEC,MAAa,EAAiC;QAC3E,OAAOG;IACT;IAEA;;;GAGC,GACDC,UAAUC,IAAc,EAAEC,IAAc,EAAQ;QAC9C,IAAI,CAACC,UAAU,CAACF,MAAM,IAAI,CAACG,OAAO,CAACF;IACrC;IAEA,+EAA+E,GAC/EG,aAAaJ,IAAc,EAAEC,IAAc,EAAW;QACpD,OAAO,IAAI,CAACR,aAAa,CAACO,MAAM,IAAI,CAACG,OAAO,CAACF;IAC/C;AACF"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Structural equality for query arguments (`where`, `orderBy`, `take`, ...). Keys holding
3
+ * `undefined` are treated as absent, so `{ where: cond ? filter : undefined }` compares equal to
4
+ * `{}` when the condition is false.
5
+ */
6
+ export declare function deepEqual(left: unknown, right: unknown): boolean;
7
+ //# sourceMappingURL=deep-equal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-equal.d.ts","sourceRoot":"","sources":["../src/deep-equal.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAyDhE"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Structural equality for query arguments (`where`, `orderBy`, `take`, ...). Keys holding
3
+ * `undefined` are treated as absent, so `{ where: cond ? filter : undefined }` compares equal to
4
+ * `{}` when the condition is false.
5
+ */ export function deepEqual(left, right) {
6
+ if (left === right) {
7
+ return true;
8
+ }
9
+ if (left && right && typeof left === 'object' && typeof right === 'object') {
10
+ if (Array.isArray(left) || Array.isArray(right)) {
11
+ if (!Array.isArray(left) || !Array.isArray(right)) {
12
+ return false;
13
+ }
14
+ const { length } = left;
15
+ if (right.length !== length) {
16
+ return false;
17
+ }
18
+ for(let i = 0; i < length; i += 1){
19
+ if (!deepEqual(left[i], right[i])) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ }
25
+ const lValue = left.valueOf?.();
26
+ const rValue = right.valueOf?.();
27
+ // A boxed value (a Date, a boxed primitive) compares by its primitive, whichever side it is
28
+ // on: a plain object's `valueOf` returns the object itself, and a null-prototype object has
29
+ // none at all, so neither is mistaken for one.
30
+ if (lValue != null && typeof lValue !== 'object' || rValue != null && typeof rValue !== 'object') {
31
+ return lValue === rValue;
32
+ }
33
+ const keys = comparedKeys(left);
34
+ if (keys.length !== comparedKeys(right).length) {
35
+ return false;
36
+ }
37
+ for (const key of keys){
38
+ if (!deepEqual(left[key], right[key])) {
39
+ return false;
40
+ }
41
+ }
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+ function comparedKeys(value) {
47
+ return Object.keys(value).filter((key)=>value[key] !== undefined);
48
+ }
49
+
50
+ //# sourceMappingURL=deep-equal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/deep-equal.ts"],"names":["deepEqual","left","right","Array","isArray","length","i","lValue","valueOf","rValue","keys","comparedKeys","key","value","Object","filter","undefined"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,SAASA,UAAUC,IAAa,EAAEC,KAAc;IACrD,IAAID,SAASC,OAAO;QAClB,OAAO;IACT;IAEA,IAAID,QAAQC,SAAS,OAAOD,SAAS,YAAY,OAAOC,UAAU,UAAU;QAC1E,IAAIC,MAAMC,OAAO,CAACH,SAASE,MAAMC,OAAO,CAACF,QAAQ;YAC/C,IAAI,CAACC,MAAMC,OAAO,CAACH,SAAS,CAACE,MAAMC,OAAO,CAACF,QAAQ;gBACjD,OAAO;YACT;YAEA,MAAM,EAAEG,MAAM,EAAE,GAAGJ;YAEnB,IAAIC,MAAMG,MAAM,KAAKA,QAAQ;gBAC3B,OAAO;YACT;YAEA,IAAK,IAAIC,IAAI,GAAGA,IAAID,QAAQC,KAAK,EAAG;gBAClC,IAAI,CAACN,UAAUC,IAAI,CAACK,EAAE,EAAEJ,KAAK,CAACI,EAAE,GAAG;oBACjC,OAAO;gBACT;YACF;YAEA,OAAO;QACT;QAEA,MAAMC,SAASN,KAAKO,OAAO;QAC3B,MAAMC,SAASP,MAAMM,OAAO;QAE5B,4FAA4F;QAC5F,4FAA4F;QAC5F,+CAA+C;QAC/C,IACE,AAACD,UAAU,QAAQ,OAAOA,WAAW,YACpCE,UAAU,QAAQ,OAAOA,WAAW,UACrC;YACA,OAAOF,WAAWE;QACpB;QAEA,MAAMC,OAAOC,aAAaV;QAE1B,IAAIS,KAAKL,MAAM,KAAKM,aAAaT,OAAkCG,MAAM,EAAE;YACzE,OAAO;QACT;QAEA,KAAK,MAAMO,OAAOF,KAAM;YACtB,IACE,CAACV,UAAU,AAACC,IAAgC,CAACW,IAAI,EAAE,AAACV,KAAiC,CAACU,IAAI,GAC1F;gBACA,OAAO;YACT;QACF;QAEA,OAAO;IACT;IAEA,OAAO;AACT;AAEA,SAASD,aAAaE,KAA8B;IAClD,OAAOC,OAAOJ,IAAI,CAACG,OAAOE,MAAM,CAAC,CAACH,MAAQC,KAAK,CAACD,IAAI,KAAKI;AAC3D"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * What the ORM plugins use: the `Plan` class with the two entry points on it, the `Adapter`
3
+ * classes their own adapters extend, and the loader-map, usage and equality helpers their
4
+ * adapters and loaders call. Everything else is module-private; see the README.
5
+ */
6
+ export { Adapter } from './adapter.js';
7
+ export { deepEqual } from './deep-equal.js';
8
+ export { cacheKey, getLoaderMapping, type Mappings, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings, } from './loader-map.js';
9
+ export { type IndirectInclude, type IndirectPathSegment, type PathSegment, selectedFieldNames, } from './matches.js';
10
+ export { type Node, NodeAdapter, type QueryVisitor } from './node.js';
11
+ export { Plan, type PlayedPlan } from './plan.js';
12
+ export type { MergeOptions, NestedSelection, Position, SelectedFieldNode, SelectFn, WalkedType, } from './types.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,QAAQ,EACb,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,IAAI,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,YAAY,EACV,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,UAAU,GACX,MAAM,YAAY,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * What the ORM plugins use: the `Plan` class with the two entry points on it, the `Adapter`
3
+ * classes their own adapters extend, and the loader-map, usage and equality helpers their
4
+ * adapters and loaders call. Everything else is module-private; see the README.
5
+ */ export { Adapter } from './adapter.js';
6
+ export { deepEqual } from './deep-equal.js';
7
+ export { cacheKey, getLoaderMapping, setFieldMapping, setLoaderMappings, setRowFieldMapping, setRowMappings } from './loader-map.js';
8
+ export { selectedFieldNames } from './matches.js';
9
+ export { NodeAdapter } from './node.js';
10
+ export { Plan } from './plan.js';
11
+
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["Adapter","deepEqual","cacheKey","getLoaderMapping","setFieldMapping","setLoaderMappings","setRowFieldMapping","setRowMappings","selectedFieldNames","NodeAdapter","Plan"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,OAAO,QAAQ,eAAe;AACvC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACEC,QAAQ,EACRC,gBAAgB,EAEhBC,eAAe,EACfC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,QACT,kBAAkB;AACzB,SAIEC,kBAAkB,QACb,eAAe;AACtB,SAAoBC,WAAW,QAA2B,YAAY;AACtE,SAASC,IAAI,QAAyB,YAAY"}
@@ -0,0 +1,63 @@
1
+ import type { GraphQLResolveInfo } from 'graphql';
2
+ import type { Position } from './types.js';
3
+ /**
4
+ * What a plan records for one field whose selection was merged: the mappings of the fields walked
5
+ * beneath it, and, for a field a select function planned, the position it was planned at, so a
6
+ * resolver can ask the same question of it that the select path asked. A static selection records
7
+ * the shared empty mapping and has no position: it ran no callback that could have read one.
8
+ */
9
+ export interface Mapping {
10
+ nested: Mappings;
11
+ position?: Position;
12
+ }
13
+ /**
14
+ * Mappings keyed by `${Type}@${relative.path}`, where the relative path is the aliased field path
15
+ * from the walked field to the mapped field (`Post@edges.node.author`). A resolver beneath the
16
+ * walked field finds a mapping iff the plan that would have loaded its data was merged.
17
+ */
18
+ export type Mappings = Record<string, Mapping>;
19
+ /** The mapping of a static selection: nothing can ever be recorded beneath one. */
20
+ export declare const EMPTY_MAPPING: Mapping;
21
+ /**
22
+ * Adopts the first mapping recorded for a key; a later one deep-unions into a copy, so a recorded
23
+ * mapping is never changed after the fact (two plays may accept a different subset of the fields).
24
+ */
25
+ export declare function unionMappings(into: Mapping | undefined, from: Mapping): Mapping;
26
+ /** The string keys of a response path joined by `.`; list indices are dropped. */
27
+ export declare function responsePath(path: GraphQLResolveInfo['path'] | undefined): string;
28
+ export declare function cacheKey(type: string, path: GraphQLResolveInfo['path']): string;
29
+ /**
30
+ * Records the mappings of a plan rooted at the field `info` resolves, under that field's path.
31
+ * The plan loaded the whole field, so its mappings answer for every row of it: they go to the
32
+ * shared tier. Multiple plans can contribute to one field (Relay nodes of different model
33
+ * types share the list's path), so later contributions replace matching keys and retain others.
34
+ */
35
+ export declare function setLoaderMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
36
+ /**
37
+ * Records a row's mappings and scopes its descendants to this concrete field execution. A
38
+ * descendant's parent is a different object, so row identity alone cannot carry its plan through
39
+ * a relation, connection wrapper, or list. The execution path retains indices to isolate siblings.
40
+ */
41
+ export declare function setRowMappings(ctx: object, info: GraphQLResolveInfo, mappings: Mappings): void;
42
+ /**
43
+ * Records the mapping of the field `info` resolves (under its own parent type) along with the
44
+ * mappings beneath it, so both the field's resolver and the resolvers below it can look
45
+ * themselves up. `row` is the value the field is about to resolve with: the parent row when it
46
+ * was loaded by the planned query, and the reloaded row when the fallback loader fetched it.
47
+ */
48
+ export declare function setFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
49
+ /**
50
+ * `setFieldMapping` for a plan that loaded `row` alone: the field's own mapping is recorded
51
+ * against `row` rather than claimed for the whole field, so a sibling row the plan never loaded
52
+ * keeps falling back instead of reading the entry and resolving against data it does not carry.
53
+ *
54
+ * Descendants inherit the mapping through this field's execution scope, even when their parent
55
+ * is a child object or a connection wrapper rather than the row that was reloaded.
56
+ */
57
+ export declare function setRowFieldMapping(ctx: object, info: GraphQLResolveInfo, mapping: Mapping, row: unknown): void;
58
+ /**
59
+ * The mapping recorded for the field at `path` on `row`, preferring one recorded for that row
60
+ * over the plan's. `row` is the value whose data the mapping describes — the resolver's parent.
61
+ */
62
+ export declare function getLoaderMapping(ctx: object, path: GraphQLResolveInfo['path'], type: string, row?: unknown): Mapping | null;
63
+ //# sourceMappingURL=loader-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader-map.d.ts","sourceRoot":"","sources":["../src/loader-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,mFAAmF;AACnF,eAAO,MAAM,aAAa,EAAE,OAAkE,CAAC;AAE/F;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAY/E;AAgCD,kFAAkF;AAClF,wBAAgB,Y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