@wundergraph/protographic 0.15.5 → 0.16.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 (51) hide show
  1. package/dist/src/abstract-selection-rewriter.d.ts +265 -0
  2. package/dist/src/abstract-selection-rewriter.js +585 -0
  3. package/dist/src/abstract-selection-rewriter.js.map +1 -0
  4. package/dist/src/index.d.ts +2 -0
  5. package/dist/src/index.js +4 -2
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/naming-conventions.d.ts +59 -0
  8. package/dist/src/naming-conventions.js +82 -7
  9. package/dist/src/naming-conventions.js.map +1 -1
  10. package/dist/src/operation-to-proto.js +9 -6
  11. package/dist/src/operation-to-proto.js.map +1 -1
  12. package/dist/src/operations/field-numbering.js +6 -3
  13. package/dist/src/operations/field-numbering.js.map +1 -1
  14. package/dist/src/operations/message-builder.js +38 -23
  15. package/dist/src/operations/message-builder.js.map +1 -1
  16. package/dist/src/operations/proto-field-options.js.map +1 -1
  17. package/dist/src/operations/proto-text-generator.js +16 -27
  18. package/dist/src/operations/proto-text-generator.js.map +1 -1
  19. package/dist/src/operations/request-builder.d.ts +5 -0
  20. package/dist/src/operations/request-builder.js +14 -3
  21. package/dist/src/operations/request-builder.js.map +1 -1
  22. package/dist/src/operations/type-mapper.js +3 -22
  23. package/dist/src/operations/type-mapper.js.map +1 -1
  24. package/dist/src/proto-lock.js +19 -19
  25. package/dist/src/proto-lock.js.map +1 -1
  26. package/dist/src/proto-utils.d.ts +74 -0
  27. package/dist/src/proto-utils.js +286 -0
  28. package/dist/src/proto-utils.js.map +1 -0
  29. package/dist/src/required-fields-visitor.d.ts +230 -0
  30. package/dist/src/required-fields-visitor.js +513 -0
  31. package/dist/src/required-fields-visitor.js.map +1 -0
  32. package/dist/src/sdl-to-mapping-visitor.d.ts +9 -1
  33. package/dist/src/sdl-to-mapping-visitor.js +72 -12
  34. package/dist/src/sdl-to-mapping-visitor.js.map +1 -1
  35. package/dist/src/sdl-to-proto-visitor.d.ts +20 -66
  36. package/dist/src/sdl-to-proto-visitor.js +279 -398
  37. package/dist/src/sdl-to-proto-visitor.js.map +1 -1
  38. package/dist/src/sdl-validation-visitor.d.ts +2 -0
  39. package/dist/src/sdl-validation-visitor.js +85 -29
  40. package/dist/src/sdl-validation-visitor.js.map +1 -1
  41. package/dist/src/selection-set-validation-visitor.d.ts +112 -0
  42. package/dist/src/selection-set-validation-visitor.js +199 -0
  43. package/dist/src/selection-set-validation-visitor.js.map +1 -0
  44. package/dist/src/string-constants.d.ts +4 -0
  45. package/dist/src/string-constants.js +4 -0
  46. package/dist/src/string-constants.js.map +1 -1
  47. package/dist/src/types.d.ts +102 -0
  48. package/dist/src/types.js +37 -1
  49. package/dist/src/types.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +9 -5
@@ -0,0 +1,585 @@
1
+ /**
2
+ * @file abstract-selection-rewriter.ts
3
+ *
4
+ * This module provides functionality to normalize GraphQL field set selections
5
+ * when dealing with abstract types (interfaces and unions). It ensures that fields selected
6
+ * at the interface level are properly distributed into each inline fragment,
7
+ * maintaining correct selection semantics for proto mapping generation.
8
+ */
9
+ import { visit, isInterfaceType, Kind, getNamedType, isObjectType, isUnionType, isAbstractType, isCompositeType, } from 'graphql';
10
+ /**
11
+ * Rewrites GraphQL selection sets to normalize abstract type selections.
12
+ *
13
+ * When a field returns an interface type, selections can be made both at the
14
+ * interface level and within inline fragments for concrete types. This class
15
+ * normalizes such selections by moving interface-level fields into each inline
16
+ * fragment, ensuring consistent selection structure for downstream processing.
17
+ * This is required to generate the proper proto message definitions as in protobuf
18
+ * we define abstract types as oneof fields in in a message definition, which defines
19
+ * the possible concrete types that can be selected.
20
+ *
21
+ * As we can select on Interfaces and Unions directly, we need to normalize the selection set
22
+ * to determine the allowed concrete types that can be selected.
23
+ *
24
+ *
25
+ * @example
26
+ * Input selection:
27
+ * ```graphql
28
+ * media {
29
+ * id # interface-level field
30
+ * ... on Book { title }
31
+ * ... on Movie { duration }
32
+ * }
33
+ * ```
34
+ *
35
+ * Output after normalization:
36
+ * ```graphql
37
+ * media {
38
+ * ... on Book { id title }
39
+ * ... on Movie { id duration }
40
+ * }
41
+ * ```
42
+ */
43
+ export class AbstractSelectionRewriter {
44
+ /**
45
+ * Creates a new AbstractSelectionRewriter instance.
46
+ *
47
+ * @param fieldSetDoc - The parsed GraphQL document containing the field set to rewrite
48
+ * @param schema - The GraphQL schema used for type resolution
49
+ * @param objectType - The root object type where the field set originates
50
+ */
51
+ constructor(fieldSetDoc, schema, objectType) {
52
+ this.compositeTypeStack = [];
53
+ this.ancestorStacks = [];
54
+ /** Stack for tracking parent types during nested field traversal */
55
+ this.typeStack = [];
56
+ /** Boolean stack indicating whether to restore type/selection context when leaving a selection set */
57
+ this.rebalanceStack = [];
58
+ /** Stack for preserving parent selection set context during nested traversal */
59
+ this.selectionSetStack = [];
60
+ this.inlineFragmentStack = [];
61
+ /** Stack tracking enclosing concrete type inline fragments for correct parent resolution
62
+ * when unfolding unions/abstracts nested inside concrete type fragments */
63
+ this.concreteFragmentStack = [];
64
+ this.fieldSetDoc = fieldSetDoc;
65
+ this.schema = schema;
66
+ this.currentType = objectType;
67
+ this.visitor = this.createASTVisitor();
68
+ }
69
+ /**
70
+ * Creates the AST visitor that processes selection sets during traversal.
71
+ *
72
+ * @returns An ASTVisitor configured to handle SelectionSet nodes
73
+ */
74
+ createASTVisitor() {
75
+ return {
76
+ SelectionSet: {
77
+ enter: (node, key, parent, path, ancestors) => this.onEnterSelectionSet({ node, key, parent, path, ancestors }),
78
+ leave: (node, key, parent, path, ancestors) => this.onLeaveSelectionSet({ node, key, parent, path, ancestors }),
79
+ },
80
+ InlineFragment: {
81
+ enter: (node, key, parent, path, ancestors) => this.onEnterInlineFragment({ node, key, parent, path, ancestors }),
82
+ leave: (node, key, parent, path, ancestors) => this.onLeaveInlineFragment({ node, key, parent, path, ancestors }),
83
+ },
84
+ };
85
+ }
86
+ /**
87
+ * Executes the normalization process on the field set document.
88
+ *
89
+ * This method traverses the AST and rewrites any selection sets that target
90
+ * interface types, distributing interface-level fields into inline fragments.
91
+ * The modification is performed in-place on the provided document.
92
+ */
93
+ normalize() {
94
+ visit(this.fieldSetDoc, this.visitor);
95
+ }
96
+ /**
97
+ * Handles the entry into a SelectionSet node during AST traversal.
98
+ *
99
+ * If the selection set's parent field returns an interface type, this method:
100
+ * 1. Extracts all direct field selections (interface-level fields)
101
+ * 2. Removes them from the selection set, leaving only inline fragments
102
+ * 3. Prepends the interface-level fields to each inline fragment's selections
103
+ * (unless the fragment already contains that field)
104
+ *
105
+ * @param ctx - The visitor context containing the current node and its position in the AST
106
+ */
107
+ onEnterSelectionSet(ctx) {
108
+ if (!ctx.parent) {
109
+ return;
110
+ }
111
+ if (!this.isFieldNode(ctx.parent)) {
112
+ this.rebalanceStack.push(false);
113
+ return;
114
+ }
115
+ const fieldType = this.findNamedTypeForField(ctx.parent.name.value);
116
+ if (!fieldType) {
117
+ this.rebalanceStack.push(false);
118
+ return;
119
+ }
120
+ if (!this.isTypeWithFields(fieldType)) {
121
+ this.rebalanceStack.push(false);
122
+ return;
123
+ }
124
+ this.typeStack.push(this.currentType);
125
+ this.rebalanceStack.push(true);
126
+ this.currentType = fieldType;
127
+ if (this.currentSelectionSet) {
128
+ this.selectionSetStack.push(this.currentSelectionSet);
129
+ }
130
+ this.currentSelectionSet = ctx.node;
131
+ if (this.compositeTypeStack.length > 0) {
132
+ this.ancestorStacks.push([...this.compositeTypeStack]);
133
+ this.compositeTypeStack = [];
134
+ }
135
+ this.currentCompositeRoot = fieldType;
136
+ this.compositeTypeStack.push(this.currentCompositeRoot);
137
+ // Only process selection sets for interface and union types
138
+ if (isAbstractType(fieldType)) {
139
+ this.appendValidInlineFragments(ctx.node);
140
+ this.distributeFieldsIntoInlineFragments(ctx.node);
141
+ }
142
+ }
143
+ /**
144
+ * Handles leaving a SelectionSet node during AST traversal.
145
+ *
146
+ * This method performs cleanup operations:
147
+ * 1. Merges duplicate inline fragments with the same type condition
148
+ * 2. Removes empty inline fragments (those with no selections)
149
+ * 3. Restores the previous type and selection set context from stacks
150
+ *
151
+ * @param ctx - The visitor context containing the current node and its position in the AST
152
+ */
153
+ onLeaveSelectionSet(ctx) {
154
+ var _a, _b, _c, _d;
155
+ if (!ctx.parent) {
156
+ return;
157
+ }
158
+ this.collapseRedundantFragments(ctx.node, ctx.parent);
159
+ this.mergeInlineFragments(ctx.node);
160
+ this.removeEmptyInlineFragments(ctx.node);
161
+ if ((_a = this.rebalanceStack.pop()) !== null && _a !== void 0 ? _a : false) {
162
+ this.currentType = (_b = this.typeStack.pop()) !== null && _b !== void 0 ? _b : this.currentType;
163
+ this.currentSelectionSet = this.selectionSetStack.pop();
164
+ }
165
+ if (!this.isFieldNode(ctx.parent)) {
166
+ return;
167
+ }
168
+ const fieldType = this.findNamedTypeForField(ctx.parent.name.value);
169
+ if (!fieldType || !this.isTypeWithFields(fieldType)) {
170
+ return;
171
+ }
172
+ if (isCompositeType(fieldType) &&
173
+ fieldType.name === ((_c = this.currentCompositeRoot) === null || _c === void 0 ? void 0 : _c.name) &&
174
+ this.compositeTypeStack.length === 1) {
175
+ this.compositeTypeStack = (_d = this.ancestorStacks.pop()) !== null && _d !== void 0 ? _d : [];
176
+ if (this.compositeTypeStack.length > 0) {
177
+ this.currentCompositeRoot = this.compositeTypeStack[0];
178
+ }
179
+ }
180
+ }
181
+ /**
182
+ * Handles entering an InlineFragment node during AST traversal.
183
+ *
184
+ * This method processes inline fragments in two ways:
185
+ *
186
+ * 1. For concrete type fragments (e.g., `... on Book`):
187
+ * - Validates if the fragment type implements the current interface
188
+ * - Removes invalid fragments (those targeting types that don't implement the interface)
189
+ * - Tracks the fragment for nested union/abstract type resolution
190
+ *
191
+ * 2. For interface type conditions (e.g., `... on Employee`):
192
+ * - Recursively processes nested interface selections
193
+ * - Distributes interface-level fields into concrete type fragments
194
+ * - Unwraps the inline fragment by replacing it with its selections
195
+ * - Ensures nested interface fields are properly distributed
196
+ *
197
+ * @param ctx - The visitor context containing the current inline fragment node
198
+ * @returns undefined to continue traversal, or nothing to skip
199
+ */
200
+ onEnterInlineFragment(ctx) {
201
+ var _a, _b;
202
+ if (!ctx.parent || !this.currentSelectionSet) {
203
+ return;
204
+ }
205
+ this.inlineFragmentStack.push(ctx.node);
206
+ const type = this.schema.getType((_b = (_a = ctx.node.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) !== null && _b !== void 0 ? _b : '');
207
+ if (isUnionType(type)) {
208
+ this.unfoldUnionType(ctx);
209
+ this.compositeTypeStack.push(type);
210
+ this.rebalanceStack.push(false);
211
+ return;
212
+ }
213
+ if (!type || !this.isTypeWithFields(type)) {
214
+ return;
215
+ }
216
+ if (!this.inlineFragmentIsAbstractType(ctx.node)) {
217
+ this.rebalanceStack.push(true);
218
+ this.typeStack.push(this.currentType);
219
+ this.compositeTypeStack.push(type);
220
+ this.currentType = type;
221
+ // Returning undefined continues traversal without deleting the node.
222
+ // If the inline fragment targets a type that doesn't implement the current interface,
223
+ // we remove it from the selections.
224
+ if (!this.inlineFragmentIsValidForCurrentAbstractRoot(ctx.node)) {
225
+ let parent = this.currentSelectionSet;
226
+ if (this.inlineFragmentStack.length > 1) {
227
+ const inlineFragment = this.inlineFragmentStack.at(-2);
228
+ if (!inlineFragment) {
229
+ return;
230
+ }
231
+ parent = inlineFragment.selectionSet;
232
+ }
233
+ parent.selections = parent.selections.filter((s) => { var _a, _b; return s.kind !== Kind.INLINE_FRAGMENT || ((_a = s.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) !== ((_b = ctx.node.typeCondition) === null || _b === void 0 ? void 0 : _b.name.value); });
234
+ }
235
+ // Track this concrete fragment so nested union/abstract processing can find
236
+ // the correct parent selection set when unfolding.
237
+ this.concreteFragmentStack.push(ctx.node);
238
+ this.inlineFragmentStack.pop();
239
+ return;
240
+ }
241
+ this.rebalanceStack.push(false);
242
+ if (!isAbstractType(type)) {
243
+ return;
244
+ }
245
+ this.compositeTypeStack.push(type);
246
+ this.appendValidInlineFragments(ctx.node.selectionSet);
247
+ this.distributeFieldsIntoInlineFragments(ctx.node.selectionSet);
248
+ const parent = this.getEnclosingSelectionSet(ctx.node);
249
+ if (!parent) {
250
+ this.inlineFragmentStack.pop();
251
+ return;
252
+ }
253
+ this.unfoldSelectionNodeToParent(ctx.node, parent);
254
+ this.inlineFragmentStack.pop();
255
+ }
256
+ onLeaveInlineFragment(ctx) {
257
+ var _a, _b;
258
+ if (!ctx.parent || !this.currentSelectionSet) {
259
+ return;
260
+ }
261
+ this.inlineFragmentStack.pop();
262
+ if ((_a = this.rebalanceStack.pop()) !== null && _a !== void 0 ? _a : false) {
263
+ this.currentType = (_b = this.typeStack.pop()) !== null && _b !== void 0 ? _b : this.currentType;
264
+ this.compositeTypeStack.pop();
265
+ // Pop the concrete fragment stack (pushed during enter for concrete types)
266
+ this.concreteFragmentStack.pop();
267
+ }
268
+ else {
269
+ this.compositeTypeStack.pop();
270
+ }
271
+ }
272
+ unfoldUnionType(ctx) {
273
+ const parent = this.getEnclosingSelectionSet(ctx.node);
274
+ if (!parent) {
275
+ return;
276
+ }
277
+ this.unfoldSelectionNodeToParent(ctx.node, parent);
278
+ this.inlineFragmentStack.pop();
279
+ }
280
+ unfoldSelectionNodeToParent(node, parent) {
281
+ const index = parent.selections.findIndex((s) => { var _a, _b; return s.kind === Kind.INLINE_FRAGMENT && ((_a = s.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) === ((_b = node.typeCondition) === null || _b === void 0 ? void 0 : _b.name.value); });
282
+ if (index < 0) {
283
+ return;
284
+ }
285
+ parent.selections = [
286
+ ...parent.selections.slice(0, index),
287
+ ...node.selectionSet.selections,
288
+ ...parent.selections.slice(index + 1),
289
+ ];
290
+ }
291
+ /**
292
+ * Resolves the correct enclosing selection set for union/abstract type unfolding.
293
+ *
294
+ * The resolution order is:
295
+ * 1. If `inlineFragmentStack` has depth > 1, use the parent fragment's selection set
296
+ * 2. If the node can be found in `currentSelectionSet`, use it
297
+ * 3. If inside a concrete type inline fragment (tracked by concreteFragmentStack)
298
+ * and the node can be found there, use that fragment's selection set
299
+ * 4. Fall back to `currentSelectionSet`
300
+ */
301
+ getEnclosingSelectionSet(node) {
302
+ var _a, _b, _c, _d, _e, _f, _g;
303
+ if (this.inlineFragmentStack.length > 1) {
304
+ return (_a = this.inlineFragmentStack.at(-2)) === null || _a === void 0 ? void 0 : _a.selectionSet;
305
+ }
306
+ const typeName = (_c = (_b = node.typeCondition) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.value;
307
+ // Check if the node is a direct child of currentSelectionSet
308
+ if ((_e = (_d = this.currentSelectionSet) === null || _d === void 0 ? void 0 : _d.selections) === null || _e === void 0 ? void 0 : _e.some((s) => { var _a, _b; return s.kind === Kind.INLINE_FRAGMENT && ((_b = (_a = s.typeCondition) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) === typeName; })) {
309
+ return this.currentSelectionSet;
310
+ }
311
+ // Fall back to the enclosing concrete fragment's selection set
312
+ // (e.g., when a union is directly inside a concrete type inline fragment)
313
+ if (this.concreteFragmentStack.length > 0) {
314
+ const concreteFragment = this.concreteFragmentStack.at(-1);
315
+ if ((_g = (_f = concreteFragment === null || concreteFragment === void 0 ? void 0 : concreteFragment.selectionSet) === null || _f === void 0 ? void 0 : _f.selections) === null || _g === void 0 ? void 0 : _g.some((s) => { var _a, _b; return s.kind === Kind.INLINE_FRAGMENT && ((_b = (_a = s.typeCondition) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) === typeName; })) {
316
+ return concreteFragment.selectionSet;
317
+ }
318
+ }
319
+ return this.currentSelectionSet;
320
+ }
321
+ /**
322
+ * Merges duplicate inline fragments with the same type condition.
323
+ *
324
+ * When multiple inline fragments target the same concrete type, this method
325
+ * combines them into a single fragment with all selections merged together.
326
+ * The merged fragment replaces all duplicate fragments in the selection set.
327
+ *
328
+ * @param node - The selection set node containing inline fragments to merge
329
+ */
330
+ mergeInlineFragments(node) {
331
+ const selectedInlineFragments = node.selections.filter((s) => s.kind === Kind.INLINE_FRAGMENT);
332
+ if (selectedInlineFragments.length === 0) {
333
+ return;
334
+ }
335
+ const uniqueInlineFragments = [];
336
+ for (const selectedFragment of selectedInlineFragments) {
337
+ const uniqueFragment = uniqueInlineFragments.find((f) => { var _a, _b; return ((_a = f.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) === ((_b = selectedFragment.typeCondition) === null || _b === void 0 ? void 0 : _b.name.value); });
338
+ if (!uniqueFragment) {
339
+ uniqueInlineFragments.push(selectedFragment);
340
+ continue;
341
+ }
342
+ const existingFieldNames = new Set(uniqueFragment.selectionSet.selections.filter((s) => s.kind === Kind.FIELD).map((s) => s.name.value));
343
+ const missingFields = selectedFragment.selectionSet.selections.filter((s) => s.kind === Kind.FIELD && !existingFieldNames.has(s.name.value));
344
+ uniqueFragment.selectionSet.selections = [...uniqueFragment.selectionSet.selections, ...missingFields];
345
+ }
346
+ // Put the fields back in the selection set. If there are any fields that were not included in the inline fragments.
347
+ const fields = node.selections.filter((s) => s.kind === Kind.FIELD);
348
+ node.selections = [...fields, ...uniqueInlineFragments];
349
+ }
350
+ /**
351
+ * Collapses redundant nested inline fragments whose type condition matches
352
+ * the enclosing inline fragment's type condition.
353
+ *
354
+ * When processing abstract types inside a concrete type inline fragment,
355
+ * the normalization may produce nested fragments like:
356
+ * `... on Intern { ... on Intern { scope } }`
357
+ * This method unwraps the inner fragment, yielding:
358
+ * `... on Intern { scope }`
359
+ *
360
+ * @param node - The selection set node to clean up
361
+ * @param parent - The parent AST node (checked for InlineFragment type)
362
+ */
363
+ collapseRedundantFragments(node, parent) {
364
+ var _a, _b;
365
+ if (Array.isArray(parent) || parent.kind !== Kind.INLINE_FRAGMENT) {
366
+ return;
367
+ }
368
+ const parentFragment = parent;
369
+ const parentTypeName = (_b = (_a = parentFragment.typeCondition) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value;
370
+ if (!parentTypeName) {
371
+ return;
372
+ }
373
+ node.selections = node.selections.flatMap((s) => {
374
+ var _a, _b;
375
+ return s.kind === Kind.INLINE_FRAGMENT && ((_b = (_a = s.typeCondition) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.value) === parentTypeName
376
+ ? s.selectionSet.selections
377
+ : [s];
378
+ });
379
+ }
380
+ /**
381
+ * Removes empty inline fragments from a selection set.
382
+ *
383
+ * Filters out any inline fragment that has no selections in its selection set.
384
+ * This cleanup step is performed after field distribution and merging operations
385
+ * to ensure only meaningful fragments remain in the AST.
386
+ *
387
+ * @param node - The selection set node to clean up
388
+ */
389
+ removeEmptyInlineFragments(node) {
390
+ node.selections = node.selections.filter((s) => s.kind !== Kind.INLINE_FRAGMENT || s.selectionSet.selections.length > 0);
391
+ }
392
+ /**
393
+ * Appends inline fragments for all possible types that implement the current interface.
394
+ *
395
+ * When processing an interface type selection with interface-level fields, this method
396
+ * ensures that every concrete type implementing the interface has a corresponding
397
+ * inline fragment. Creates new fragments only for types that don't already have one.
398
+ *
399
+ * This guarantees that interface-level fields can be distributed to all implementing
400
+ * types, even if the original query didn't explicitly include fragments for them.
401
+ *
402
+ * @param node - The selection set node to append inline fragments to
403
+ */
404
+ appendValidInlineFragments(node) {
405
+ if (this.compositeTypeStack.length === 0) {
406
+ return;
407
+ }
408
+ const fields = node.selections.filter((s) => s.kind === Kind.FIELD);
409
+ if (fields.length === 0) {
410
+ return;
411
+ }
412
+ const currentStack = [...this.compositeTypeStack];
413
+ const currentInterface = currentStack.pop();
414
+ if (!currentInterface) {
415
+ return;
416
+ }
417
+ const selectedInlineFragments = node.selections.filter((s) => s.kind === Kind.INLINE_FRAGMENT);
418
+ const possibleTypes = this.getPossibleIntersectingTypes(currentInterface, currentStack);
419
+ const newInlineFragments = [];
420
+ for (const possibleType of possibleTypes) {
421
+ if (!selectedInlineFragments.some((s) => { var _a; return ((_a = s.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) === possibleType.name; })) {
422
+ newInlineFragments.push(this.createInlineFragment(possibleType, fields));
423
+ }
424
+ }
425
+ node.selections = [...fields, ...newInlineFragments, ...selectedInlineFragments];
426
+ }
427
+ getPossibleIntersectingTypes(currentCompositeRoot, ancestors) {
428
+ let possibleTypes = [];
429
+ possibleTypes = isObjectType(currentCompositeRoot)
430
+ ? [currentCompositeRoot]
431
+ : this.schema.getPossibleTypes(currentCompositeRoot);
432
+ const lastAncestor = ancestors.pop();
433
+ if (!lastAncestor) {
434
+ return possibleTypes;
435
+ }
436
+ const parentPossibleTypes = this.getPossibleIntersectingTypes(lastAncestor, ancestors);
437
+ return possibleTypes.filter((t) => parentPossibleTypes.some((p) => p.name === t.name));
438
+ }
439
+ /**
440
+ * Creates an inline fragment AST node for a specific concrete type.
441
+ *
442
+ * Constructs a minimal InlineFragmentNode with:
443
+ * - Type condition targeting the specified object type
444
+ * - Filtered field selections (only includes fields that exist on the target type)
445
+ * - Simple field nodes with name only (no aliases, arguments, or directives)
446
+ *
447
+ * @param type - The concrete object type to create a fragment for
448
+ * @param fields - The interface-level fields to include in the fragment
449
+ * @returns A new InlineFragmentNode with the filtered field selections
450
+ */
451
+ createInlineFragment(type, fields) {
452
+ return {
453
+ kind: Kind.INLINE_FRAGMENT,
454
+ directives: [],
455
+ typeCondition: {
456
+ kind: Kind.NAMED_TYPE,
457
+ name: { kind: Kind.NAME, value: type.name },
458
+ },
459
+ selectionSet: {
460
+ kind: Kind.SELECTION_SET,
461
+ selections: fields.filter((f) => type.getFields()[f.name.value]),
462
+ },
463
+ };
464
+ }
465
+ /**
466
+ * Distributes interface-level fields into all inline fragments.
467
+ *
468
+ * This is the core normalization logic that:
469
+ * 1. Extracts all direct field selections from the selection set
470
+ * 2. Removes those fields from the parent selection set
471
+ * 3. Adds each field to the inline fragments where it doesn't already exist
472
+ * 4. Validates that each field exists on the fragment's concrete type
473
+ *
474
+ * Fields are prepended to maintain their original order relative to fragment-specific fields.
475
+ * Duplicate fields within a fragment are avoided by checking existing selections.
476
+ *
477
+ * @param node - The selection set node containing fields and inline fragments
478
+ */
479
+ distributeFieldsIntoInlineFragments(node) {
480
+ var _a, _b, _c;
481
+ const fields = node.selections.filter((s) => s.kind === Kind.FIELD);
482
+ if (fields.length === 0) {
483
+ return;
484
+ }
485
+ const inlineFragments = node.selections.filter((s) => s.kind === Kind.INLINE_FRAGMENT);
486
+ // Keep only the inline fragments in the selection set.
487
+ node.selections = [...inlineFragments];
488
+ for (const fragment of inlineFragments) {
489
+ const inlineFragmentType = this.schema.getType((_b = (_a = fragment.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) !== null && _b !== void 0 ? _b : '');
490
+ if (!inlineFragmentType || !this.isTypeWithFields(inlineFragmentType)) {
491
+ continue;
492
+ }
493
+ const existingFields = new Set((_c = fragment.selectionSet.selections.filter((s) => s.kind === Kind.FIELD).map((s) => s.name.value)) !== null && _c !== void 0 ? _c : []);
494
+ // Add interface fields to the inline fragment, but only if the fragment type defines the field.
495
+ // During normalization we might have parent inline fragments that include fields that would be added to
496
+ // the wrong inline fragments.
497
+ const fieldsToAdd = fields
498
+ .filter((field) => !existingFields.has(field.name.value))
499
+ .filter((field) => inlineFragmentType.getFields()[field.name.value]);
500
+ // Add the interface fields to the fragment. We always prepend them for now.
501
+ // TODO: Check if fields should be inserted in the order of appearance in the selection set.
502
+ fragment.selectionSet.selections = [...fieldsToAdd, ...fragment.selectionSet.selections];
503
+ }
504
+ }
505
+ /**
506
+ * Checks if an inline fragment's type condition targets an interface type.
507
+ *
508
+ * @param node - The inline fragment node to check
509
+ * @returns true if the fragment targets an interface type, false otherwise
510
+ */
511
+ inlineFragmentIsAbstractType(node) {
512
+ var _a, _b;
513
+ const type = this.schema.getType((_b = (_a = node.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) !== null && _b !== void 0 ? _b : '');
514
+ return isInterfaceType(type) || isUnionType(type);
515
+ }
516
+ /**
517
+ * Validates whether an inline fragment is valid for the current interface type.
518
+ *
519
+ * An inline fragment is considered valid if:
520
+ * - The current type is not an interface (always valid)
521
+ * - The fragment's type is an object type that implements the current interface
522
+ *
523
+ * Invalid fragments (those targeting types that don't implement the interface)
524
+ * should be removed from the selection set.
525
+ *
526
+ * @param node - The inline fragment node to validate
527
+ * @returns true if the fragment is valid for the current interface root context, false otherwise
528
+ */
529
+ inlineFragmentIsValidForCurrentAbstractRoot(node) {
530
+ var _a, _b, _c;
531
+ const type = this.schema.getType((_b = (_a = node.typeCondition) === null || _a === void 0 ? void 0 : _a.name.value) !== null && _b !== void 0 ? _b : '');
532
+ if (!type) {
533
+ // Type not found in schema - invalid fragment
534
+ return false;
535
+ }
536
+ // TODO: Check if we need to check for interface types as well because interfaces can also implement interfaces.
537
+ if (!isObjectType(type)) {
538
+ // Non-object types cannot implement interfaces
539
+ return false;
540
+ }
541
+ if (isObjectType(this.currentCompositeRoot)) {
542
+ return type.name === ((_c = this.currentCompositeRoot) === null || _c === void 0 ? void 0 : _c.name);
543
+ }
544
+ return type.getInterfaces().some((i) => { var _a; return i.name === ((_a = this.currentCompositeRoot) === null || _a === void 0 ? void 0 : _a.name); });
545
+ }
546
+ /**
547
+ * Type guard to check if an AST node is a FieldNode.
548
+ *
549
+ * @param node - The AST node or array of nodes to check
550
+ * @returns true if the node is a FieldNode, false otherwise
551
+ */
552
+ isFieldNode(node) {
553
+ if (Array.isArray(node)) {
554
+ return false;
555
+ }
556
+ return node.kind === Kind.FIELD;
557
+ }
558
+ /**
559
+ * Finds the named (unwrapped) type for a field by its name.
560
+ *
561
+ * This method looks up the field in the current type's fields and returns
562
+ * the named type (stripping away any List or NonNull wrappers).
563
+ *
564
+ * @param fieldName - The name of the field to look up
565
+ * @returns The named GraphQL type, or undefined if the field doesn't exist
566
+ */
567
+ findNamedTypeForField(fieldName) {
568
+ const fields = this.currentType.getFields();
569
+ const field = fields[fieldName];
570
+ if (!field) {
571
+ return undefined;
572
+ }
573
+ return getNamedType(field.type);
574
+ }
575
+ /**
576
+ * Type guard to check if a GraphQL type has fields.
577
+ *
578
+ * @param type - The GraphQL type to check
579
+ * @returns true if the type is an object type or interface type (both have getFields method)
580
+ */
581
+ isTypeWithFields(type) {
582
+ return isObjectType(type) || isInterfaceType(type);
583
+ }
584
+ }
585
+ //# sourceMappingURL=abstract-selection-rewriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-selection-rewriter.js","sourceRoot":"","sources":["../../src/abstract-selection-rewriter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAKL,KAAK,EAEL,eAAe,EACf,IAAI,EAIJ,YAAY,EAEZ,YAAY,EAEZ,WAAW,EAEX,cAAc,EAMd,eAAe,GAChB,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,OAAO,yBAAyB;IAsBpC;;;;;;OAMG;IACH,YAAY,WAAyB,EAAE,MAAqB,EAAE,UAAiC;QAvBvF,uBAAkB,GAA2B,EAAE,CAAC;QAChD,mBAAc,GAA6B,EAAE,CAAC;QACtD,oEAAoE;QAC5D,cAAS,GAA4B,EAAE,CAAC;QAChD,sGAAsG;QAC9F,mBAAc,GAAc,EAAE,CAAC;QAGvC,gFAAgF;QACxE,sBAAiB,GAAuB,EAAE,CAAC;QAE3C,wBAAmB,GAAyB,EAAE,CAAC;QACvD;mFAC2E;QACnE,0BAAqB,GAAyB,EAAE,CAAC;QAUvD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACK,gBAAgB;QACtB,OAAO;YACL,YAAY,EAAE;gBACZ,KAAK,EAAE,CAAC,I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,WAAW,CAAC,SAAS,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACK,gBAAgB,CAAC,IAAiB;QACxC,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;CACF"}
@@ -40,6 +40,7 @@ export declare function compileGraphQLToProto(schemaOrSDL: GraphQLSchema | strin
40
40
  export declare function validateGraphQLSDL(sdl: string): ValidationResult;
41
41
  export * from './sdl-to-mapping-visitor.js';
42
42
  export { GraphQLToProtoTextVisitor } from './sdl-to-proto-visitor.js';
43
+ export { RequiredFieldsVisitor } from './required-fields-visitor.js';
43
44
  export { ProtoLockManager } from './proto-lock.js';
44
45
  export { SDLValidationVisitor } from './sdl-validation-visitor.js';
45
46
  export { compileOperationsToProto } from './operation-to-proto.js';
@@ -60,4 +61,5 @@ export type { ProtoOptions } from './proto-options.js';
60
61
  export type { ProtoLock } from './proto-lock.js';
61
62
  export type { ValidationResult } from './sdl-validation-visitor.js';
62
63
  export { GRPCMapping, OperationMapping, EntityMapping, TypeFieldMapping, FieldMapping, ArgumentMapping, EnumMapping, EnumValueMapping, OperationType, } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
64
+ export { CONNECT_FIELD_RESOLVER, CONTEXT, EXTERNAL_DIRECTIVE_NAME, FIELDS, FIELD_ARGS, KEY_DIRECTIVE_NAME, REQUIRES_DIRECTIVE_NAME, RESULT, } from './string-constants.js';
63
65
  export { default as protobuf } from 'protobufjs';
package/dist/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { buildSchema } from 'graphql';
2
- import { GraphQLToProtoVisitor } from './sdl-to-mapping-visitor.js';
2
+ import { GraphQLToMappingVisitor } from './sdl-to-mapping-visitor.js';
3
3
  import { GraphQLToProtoTextVisitor } from './sdl-to-proto-visitor.js';
4
4
  import { SDLValidationVisitor } from './sdl-validation-visitor.js';
5
5
  /**
@@ -18,7 +18,7 @@ export function compileGraphQLToMapping(schemaOrSDL, serviceName = 'DefaultServi
18
18
  })
19
19
  : schemaOrSDL;
20
20
  // Create and run the visitor
21
- const visitor = new GraphQLToProtoVisitor(schema, serviceName);
21
+ const visitor = new GraphQLToMappingVisitor(schema, serviceName);
22
22
  return visitor.visit();
23
23
  }
24
24
  /**
@@ -60,6 +60,7 @@ export function validateGraphQLSDL(sdl) {
60
60
  }
61
61
  export * from './sdl-to-mapping-visitor.js';
62
62
  export { GraphQLToProtoTextVisitor } from './sdl-to-proto-visitor.js';
63
+ export { RequiredFieldsVisitor } from './required-fields-visitor.js';
63
64
  export { ProtoLockManager } from './proto-lock.js';
64
65
  export { SDLValidationVisitor } from './sdl-validation-visitor.js';
65
66
  // Export operation-to-proto functionality
@@ -71,6 +72,7 @@ export { buildMessageFromSelectionSet, buildFieldDefinition, buildNestedMessage,
71
72
  export { buildRequestMessage, buildInputObjectMessage, buildEnumType } from './operations/request-builder.js';
72
73
  export { rootToProtoText, serviceToProtoText, messageToProtoText, enumToProtoText, formatField, } from './operations/proto-text-generator.js';
73
74
  export { GRPCMapping, OperationMapping, EntityMapping, TypeFieldMapping, FieldMapping, ArgumentMapping, EnumMapping, EnumValueMapping, OperationType, } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
75
+ export { CONNECT_FIELD_RESOLVER, CONTEXT, EXTERNAL_DIRECTIVE_NAME, FIELDS, FIELD_ARGS, KEY_DIRECTIVE_NAME, REQUIRES_DIRECTIVE_NAME, RESULT, } from './string-constants.js';
74
76
  // Export protobufjs for AST manipulation
75
77
  export { default as protobuf } from 'protobufjs';
76
78
  //# sourceMappingURL=index.js.map