@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.
- package/dist/src/abstract-selection-rewriter.d.ts +265 -0
- package/dist/src/abstract-selection-rewriter.js +585 -0
- package/dist/src/abstract-selection-rewriter.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +4 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/naming-conventions.d.ts +59 -0
- package/dist/src/naming-conventions.js +82 -7
- package/dist/src/naming-conventions.js.map +1 -1
- package/dist/src/operation-to-proto.js +9 -6
- package/dist/src/operation-to-proto.js.map +1 -1
- package/dist/src/operations/field-numbering.js +6 -3
- package/dist/src/operations/field-numbering.js.map +1 -1
- package/dist/src/operations/message-builder.js +38 -23
- package/dist/src/operations/message-builder.js.map +1 -1
- package/dist/src/operations/proto-field-options.js.map +1 -1
- package/dist/src/operations/proto-text-generator.js +16 -27
- package/dist/src/operations/proto-text-generator.js.map +1 -1
- package/dist/src/operations/request-builder.d.ts +5 -0
- package/dist/src/operations/request-builder.js +14 -3
- package/dist/src/operations/request-builder.js.map +1 -1
- package/dist/src/operations/type-mapper.js +3 -22
- package/dist/src/operations/type-mapper.js.map +1 -1
- package/dist/src/proto-lock.js +19 -19
- package/dist/src/proto-lock.js.map +1 -1
- package/dist/src/proto-utils.d.ts +74 -0
- package/dist/src/proto-utils.js +286 -0
- package/dist/src/proto-utils.js.map +1 -0
- package/dist/src/required-fields-visitor.d.ts +230 -0
- package/dist/src/required-fields-visitor.js +513 -0
- package/dist/src/required-fields-visitor.js.map +1 -0
- package/dist/src/sdl-to-mapping-visitor.d.ts +9 -1
- package/dist/src/sdl-to-mapping-visitor.js +72 -12
- package/dist/src/sdl-to-mapping-visitor.js.map +1 -1
- package/dist/src/sdl-to-proto-visitor.d.ts +20 -66
- package/dist/src/sdl-to-proto-visitor.js +279 -398
- package/dist/src/sdl-to-proto-visitor.js.map +1 -1
- package/dist/src/sdl-validation-visitor.d.ts +2 -0
- package/dist/src/sdl-validation-visitor.js +85 -29
- package/dist/src/sdl-validation-visitor.js.map +1 -1
- package/dist/src/selection-set-validation-visitor.d.ts +112 -0
- package/dist/src/selection-set-validation-visitor.js +199 -0
- package/dist/src/selection-set-validation-visitor.js.map +1 -0
- package/dist/src/string-constants.d.ts +4 -0
- package/dist/src/string-constants.js +4 -0
- package/dist/src/string-constants.js.map +1 -1
- package/dist/src/types.d.ts +102 -0
- package/dist/src/types.js +37 -1
- package/dist/src/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -5
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { getNamedType, isInterfaceType, isObjectType, isUnionType, Kind, parse, visit, } from 'graphql';
|
|
2
|
+
import { FieldMapping } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
|
|
3
|
+
import { CompositeMessageKind } from './types.js';
|
|
4
|
+
import { KEY_DIRECTIVE_NAME } from './string-constants.js';
|
|
5
|
+
import { createEntityLookupRequestKeyMessageName, createRequestMessageName, createRequiredFieldsMethodName, createResponseMessageName, graphqlFieldToProtoField, formatKeyElements, } from './naming-conventions.js';
|
|
6
|
+
import { getProtoTypeFromGraphQL } from './proto-utils.js';
|
|
7
|
+
import { AbstractSelectionRewriter } from './abstract-selection-rewriter.js';
|
|
8
|
+
/**
|
|
9
|
+
* Generates protobuf messages and RPC methods for @requires directive field sets.
|
|
10
|
+
*
|
|
11
|
+
* This visitor processes the field set defined in a @requires directive and generates:
|
|
12
|
+
* - RPC method definitions for fetching required fields
|
|
13
|
+
* - Request/response message definitions
|
|
14
|
+
* - Field mappings between GraphQL and protobuf
|
|
15
|
+
*
|
|
16
|
+
* The visitor handles each @key directive on the entity separately, creating
|
|
17
|
+
* distinct RPC methods for each key since required fields may need to be
|
|
18
|
+
* fetched using different entity keys.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const visitor = new RequiredFieldsVisitor(
|
|
23
|
+
* schema,
|
|
24
|
+
* ProductType,
|
|
25
|
+
* weightField,
|
|
26
|
+
* 'dimensions { width height }'
|
|
27
|
+
* );
|
|
28
|
+
* visitor.visit();
|
|
29
|
+
*
|
|
30
|
+
* const messages = visitor.getMessageDefinitions();
|
|
31
|
+
* const rpcs = visitor.getRPCMethods();
|
|
32
|
+
* const mappings = visitor.getMapping();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class RequiredFieldsVisitor {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new RequiredFieldsVisitor.
|
|
38
|
+
*
|
|
39
|
+
* @param schema - The GraphQL schema containing type definitions
|
|
40
|
+
* @param objectType - The entity type that has the @requires directive
|
|
41
|
+
* @param requiredField - The field with the @requires directive
|
|
42
|
+
* @param fieldSet - The field set string from the @requires directive (e.g., "dimensions { width height }")
|
|
43
|
+
* @param options - Optional configuration options
|
|
44
|
+
* @throws Error if the object type is not an entity (has no @key directive)
|
|
45
|
+
*/
|
|
46
|
+
constructor(schema, objectType, requiredField, fieldSet) {
|
|
47
|
+
this.schema = schema;
|
|
48
|
+
this.objectType = objectType;
|
|
49
|
+
this.requiredField = requiredField;
|
|
50
|
+
this.ancestors = [];
|
|
51
|
+
this.currentType = this.objectType;
|
|
52
|
+
this.keyDirectives = [];
|
|
53
|
+
this.currentKeyFieldsString = '';
|
|
54
|
+
/** Collected RPC methods for the required fields */
|
|
55
|
+
this.rpcMethods = [];
|
|
56
|
+
/** All generated protobuf message definitions */
|
|
57
|
+
this.messageDefinitions = [];
|
|
58
|
+
/** Stack for tracking nested message contexts */
|
|
59
|
+
this.stack = [];
|
|
60
|
+
this.inlineFragmentStack = [];
|
|
61
|
+
/** Mappings keyed by @key directive fields string */
|
|
62
|
+
this.mapping = {};
|
|
63
|
+
this.resolveKeyDirectives();
|
|
64
|
+
this.fieldSetDoc = parse(`{ ${fieldSet} }`);
|
|
65
|
+
this.normalizeSelectionSet();
|
|
66
|
+
this.visitor = this.createASTVisitor();
|
|
67
|
+
this.mapping = {};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Executes the visitor, processing the field set for each @key directive.
|
|
71
|
+
* Creates separate RPC methods and mappings for each entity key.
|
|
72
|
+
*/
|
|
73
|
+
visit() {
|
|
74
|
+
for (const keyDirective of this.keyDirectives) {
|
|
75
|
+
const rawFieldSet = this.getKeyFieldsString(keyDirective);
|
|
76
|
+
if (rawFieldSet.length === 0) {
|
|
77
|
+
throw new Error(`Required field set is empty for key directive ${keyDirective.name.value}`);
|
|
78
|
+
}
|
|
79
|
+
this.currentKeyFieldsString = formatKeyElements(rawFieldSet).join(' ');
|
|
80
|
+
if (this.mapping[this.currentKeyFieldsString]) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
this.mapping[this.currentKeyFieldsString] = {
|
|
84
|
+
requiredFieldMapping: new FieldMapping({
|
|
85
|
+
original: this.requiredField.name,
|
|
86
|
+
mapped: graphqlFieldToProtoField(this.requiredField.name),
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
visit(this.fieldSetDoc, this.visitor);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Normalizes the parsed field set operation by rewriting abstract selections.
|
|
94
|
+
* This ensures consistent handling of interface and union type selections.
|
|
95
|
+
*/
|
|
96
|
+
normalizeSelectionSet() {
|
|
97
|
+
const visitor = new AbstractSelectionRewriter(this.fieldSetDoc, this.schema, this.objectType);
|
|
98
|
+
visitor.normalize();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns all generated protobuf message definitions.
|
|
102
|
+
*
|
|
103
|
+
* @returns Array of ProtoMessage definitions for request, response, and nested messages
|
|
104
|
+
*/
|
|
105
|
+
getMessageDefinitions() {
|
|
106
|
+
return this.messageDefinitions;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the generated RPC method definitions.
|
|
110
|
+
*
|
|
111
|
+
* @returns Array of RPCMethod definitions for fetching required fields
|
|
112
|
+
*/
|
|
113
|
+
getRPCMethods() {
|
|
114
|
+
return this.rpcMethods;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns the field mappings keyed by @key directive fields string.
|
|
118
|
+
*
|
|
119
|
+
* @returns Record mapping key strings to their RequiredFieldMapping configurations
|
|
120
|
+
*/
|
|
121
|
+
getMapping() {
|
|
122
|
+
return this.mapping;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolves all @key directives from the object type.
|
|
126
|
+
* Each key directive will result in a separate RPC method.
|
|
127
|
+
*
|
|
128
|
+
* @throws Error if the object type has no @key directives
|
|
129
|
+
*/
|
|
130
|
+
resolveKeyDirectives() {
|
|
131
|
+
var _a, _b, _c;
|
|
132
|
+
this.keyDirectives = (_c = (_b = (_a = this.objectType.astNode) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.filter((d) => d.name.value === KEY_DIRECTIVE_NAME)) !== null && _c !== void 0 ? _c : [];
|
|
133
|
+
if (this.keyDirectives.length === 0) {
|
|
134
|
+
throw new Error('Object type has to be an entity type to make use of the @requires directive');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates the AST visitor configuration for traversing the field set document.
|
|
139
|
+
*
|
|
140
|
+
* @returns An ASTVisitor with handlers for Document, Field, InlineFragment, and SelectionSet nodes
|
|
141
|
+
*/
|
|
142
|
+
createASTVisitor() {
|
|
143
|
+
return {
|
|
144
|
+
Document: {
|
|
145
|
+
enter: (node) => {
|
|
146
|
+
this.onEnterDocument(node);
|
|
147
|
+
},
|
|
148
|
+
leave: () => {
|
|
149
|
+
this.onLeaveDocument();
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
Field: {
|
|
153
|
+
enter: (node, key, parent, path, ancestors) => {
|
|
154
|
+
this.onEnterField({ node, key, parent, path, ancestors });
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
InlineFragment: {
|
|
158
|
+
enter: (node, key, parent, path, ancestors) => {
|
|
159
|
+
this.onEnterInlineFragment({ node, key, parent, path, ancestors });
|
|
160
|
+
},
|
|
161
|
+
leave: (node, key, parent, path, ancestors) => {
|
|
162
|
+
this.onLeaveInlineFragment({ node, key, parent, path, ancestors });
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
SelectionSet: {
|
|
166
|
+
enter: (node, key, parent, path, ancestors) => {
|
|
167
|
+
this.onEnterSelectionSet({ node, key, parent, path, ancestors });
|
|
168
|
+
},
|
|
169
|
+
leave: (node, key, parent, path, ancestors) => {
|
|
170
|
+
this.onLeaveSelectionSet({ node, key, parent, path, ancestors });
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Handles leaving the document node.
|
|
177
|
+
* Finalizes the required field message and generates type field mappings.
|
|
178
|
+
*/
|
|
179
|
+
onLeaveDocument() {
|
|
180
|
+
if (this.requiredFieldMessage) {
|
|
181
|
+
this.messageDefinitions.push(this.requiredFieldMessage);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Handles entering the document node.
|
|
186
|
+
* Creates the RPC method definition and all request/response message structures
|
|
187
|
+
* for fetching the required fields.
|
|
188
|
+
*
|
|
189
|
+
* @param node - The document node being entered
|
|
190
|
+
*/
|
|
191
|
+
onEnterDocument(node) {
|
|
192
|
+
const requiredFieldsMethodName = createRequiredFieldsMethodName(this.objectType.name, this.requiredField.name, this.currentKeyFieldsString);
|
|
193
|
+
const requestMessageName = createRequestMessageName(requiredFieldsMethodName);
|
|
194
|
+
const responseMessageName = createResponseMessageName(requiredFieldsMethodName);
|
|
195
|
+
this.mapping[this.currentKeyFieldsString].rpc = {
|
|
196
|
+
name: requiredFieldsMethodName,
|
|
197
|
+
request: requestMessageName,
|
|
198
|
+
response: responseMessageName,
|
|
199
|
+
};
|
|
200
|
+
this.rpcMethods.push({
|
|
201
|
+
name: requiredFieldsMethodName,
|
|
202
|
+
request: requestMessageName,
|
|
203
|
+
response: responseMessageName,
|
|
204
|
+
});
|
|
205
|
+
// Request messages
|
|
206
|
+
const contextMessageName = `${requiredFieldsMethodName}Context`;
|
|
207
|
+
this.messageDefinitions.push({
|
|
208
|
+
messageName: requestMessageName,
|
|
209
|
+
fields: [
|
|
210
|
+
{
|
|
211
|
+
fieldName: 'context',
|
|
212
|
+
typeName: contextMessageName,
|
|
213
|
+
fieldNumber: 1,
|
|
214
|
+
isRepeated: true,
|
|
215
|
+
description: `${contextMessageName} provides the context for the required fields method ${requiredFieldsMethodName}.`,
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
});
|
|
219
|
+
const fieldsMessageName = `${requiredFieldsMethodName}Fields`;
|
|
220
|
+
const entityKeyRequestMessageName = createEntityLookupRequestKeyMessageName(this.objectType.name, this.currentKeyFieldsString);
|
|
221
|
+
this.messageDefinitions.push({
|
|
222
|
+
messageName: contextMessageName,
|
|
223
|
+
fields: [
|
|
224
|
+
{
|
|
225
|
+
fieldName: 'key',
|
|
226
|
+
typeName: entityKeyRequestMessageName,
|
|
227
|
+
fieldNumber: 1,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
fieldName: 'fields',
|
|
231
|
+
typeName: fieldsMessageName,
|
|
232
|
+
fieldNumber: 2,
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
});
|
|
236
|
+
// Define the prototype for the required fields message.
|
|
237
|
+
// This will be added to the message definitions when the document is left.
|
|
238
|
+
this.requiredFieldMessage = {
|
|
239
|
+
messageName: fieldsMessageName,
|
|
240
|
+
fields: [],
|
|
241
|
+
};
|
|
242
|
+
// Response messages
|
|
243
|
+
const resultMessageName = `${requiredFieldsMethodName}Result`;
|
|
244
|
+
this.messageDefinitions.push({
|
|
245
|
+
messageName: responseMessageName,
|
|
246
|
+
fields: [
|
|
247
|
+
{
|
|
248
|
+
fieldName: 'result',
|
|
249
|
+
typeName: resultMessageName,
|
|
250
|
+
fieldNumber: 1,
|
|
251
|
+
isRepeated: true,
|
|
252
|
+
description: `${resultMessageName} provides the result for the required fields method ${requiredFieldsMethodName}.`,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
// Get the type name from the required field
|
|
257
|
+
const typeInfo = getProtoTypeFromGraphQL(false, this.requiredField.type);
|
|
258
|
+
this.messageDefinitions.push({
|
|
259
|
+
messageName: resultMessageName,
|
|
260
|
+
fields: [
|
|
261
|
+
{
|
|
262
|
+
fieldName: graphqlFieldToProtoField(this.requiredField.name),
|
|
263
|
+
typeName: typeInfo.typeName,
|
|
264
|
+
fieldNumber: 1,
|
|
265
|
+
isRepeated: typeInfo.isRepeated,
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
});
|
|
269
|
+
this.stack.push(this.requiredFieldMessage);
|
|
270
|
+
this.current = this.requiredFieldMessage;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Handles entering a field node during traversal.
|
|
274
|
+
* Adds the field to the current proto message with appropriate type mapping.
|
|
275
|
+
*
|
|
276
|
+
* @param ctx - The visit context containing the field node and its ancestors
|
|
277
|
+
* @throws Error if the field definition is not found on the current type
|
|
278
|
+
*/
|
|
279
|
+
onEnterField(ctx) {
|
|
280
|
+
var _a;
|
|
281
|
+
if (!this.current) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const fieldDefinition = this.fieldDefinition(ctx.node.name.value);
|
|
285
|
+
if (!fieldDefinition) {
|
|
286
|
+
throw new Error(`Field definition not found for field ${ctx.node.name.value}`);
|
|
287
|
+
}
|
|
288
|
+
let compositeType;
|
|
289
|
+
if (this.isCompositeType(fieldDefinition.type)) {
|
|
290
|
+
compositeType = this.handleCompositeType(fieldDefinition);
|
|
291
|
+
}
|
|
292
|
+
const protoFieldName = graphqlFieldToProtoField(fieldDefinition.name);
|
|
293
|
+
// Check if field already exists to avoid duplicates when reusing nested messages
|
|
294
|
+
if (this.current.fields.some((f) => f.fieldName === protoFieldName)) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const typeInfo = getProtoTypeFromGraphQL(false, fieldDefinition.type);
|
|
298
|
+
this.current.fields.push({
|
|
299
|
+
fieldName: protoFieldName,
|
|
300
|
+
typeName: typeInfo.typeName,
|
|
301
|
+
fieldNumber: ((_a = this.current) === null || _a === void 0 ? void 0 : _a.fields.length) + 1,
|
|
302
|
+
isRepeated: typeInfo.isRepeated,
|
|
303
|
+
graphqlName: fieldDefinition.name,
|
|
304
|
+
compositeType,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Handles entering an inline fragment node.
|
|
309
|
+
* Pushes the current inline fragment onto the stack for nested fragment handling.
|
|
310
|
+
*
|
|
311
|
+
* @param ctx - The visit context containing the inline fragment node
|
|
312
|
+
*/
|
|
313
|
+
onEnterInlineFragment(ctx) {
|
|
314
|
+
if (this.currentInlineFragment) {
|
|
315
|
+
this.inlineFragmentStack.push(this.currentInlineFragment);
|
|
316
|
+
}
|
|
317
|
+
this.currentInlineFragment = ctx.node;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Handles leaving an inline fragment node.
|
|
321
|
+
* Records union member types when processing union type fragments.
|
|
322
|
+
*
|
|
323
|
+
* @param ctx - The visit context containing the inline fragment node
|
|
324
|
+
*/
|
|
325
|
+
onLeaveInlineFragment(ctx) {
|
|
326
|
+
var _a;
|
|
327
|
+
this.currentInlineFragment = (_a = this.inlineFragmentStack.pop()) !== null && _a !== void 0 ? _a : undefined;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Handles entering a selection set node.
|
|
331
|
+
* Creates a new nested proto message for object type selections and updates
|
|
332
|
+
* the current type context for proper field resolution.
|
|
333
|
+
*
|
|
334
|
+
* @param ctx - The visit context containing the selection set node and its parent
|
|
335
|
+
*/
|
|
336
|
+
onEnterSelectionSet(ctx) {
|
|
337
|
+
var _a, _b, _c, _d;
|
|
338
|
+
if (!ctx.parent || !this.current) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
let currentType;
|
|
342
|
+
if (this.isFieldNode(ctx.parent)) {
|
|
343
|
+
currentType = (_a = this.findObjectTypeForField(ctx.parent.name.value)) !== null && _a !== void 0 ? _a : undefined;
|
|
344
|
+
}
|
|
345
|
+
else if (this.isInlineFragmentNode(ctx.parent)) {
|
|
346
|
+
const typeName = (_b = ctx.parent.typeCondition) === null || _b === void 0 ? void 0 : _b.name.value;
|
|
347
|
+
if (typeName) {
|
|
348
|
+
currentType = this.findObjectType(typeName);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
if (!this.currentType || !currentType) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
this.ancestors.push(this.currentType);
|
|
358
|
+
this.currentType = currentType;
|
|
359
|
+
if (!this.current.nestedMessages) {
|
|
360
|
+
this.current.nestedMessages = [];
|
|
361
|
+
}
|
|
362
|
+
// Check if a nested message with the same name already exists
|
|
363
|
+
const existingNested = this.current.nestedMessages.find((msg) => { var _a; return msg.messageName === ((_a = this.currentType) === null || _a === void 0 ? void 0 : _a.name); });
|
|
364
|
+
let nested;
|
|
365
|
+
if (existingNested) {
|
|
366
|
+
// Reuse the existing nested message to avoid duplicates
|
|
367
|
+
nested = existingNested;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
// Create a new nested message for the current type
|
|
371
|
+
nested = {
|
|
372
|
+
messageName: (_d = (_c = this.currentType) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : '',
|
|
373
|
+
fields: [],
|
|
374
|
+
};
|
|
375
|
+
this.current.nestedMessages.push(nested);
|
|
376
|
+
}
|
|
377
|
+
this.stack.push(this.current);
|
|
378
|
+
this.current = nested;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Handles leaving a selection set node.
|
|
382
|
+
* Restores the previous type and message context when ascending the tree,
|
|
383
|
+
* but only if onEnterSelectionSet actually pushed state.
|
|
384
|
+
*
|
|
385
|
+
* @param ctx - The visit context containing the selection set node
|
|
386
|
+
*/
|
|
387
|
+
onLeaveSelectionSet(ctx) {
|
|
388
|
+
var _a;
|
|
389
|
+
this.currentType = (_a = this.ancestors.pop()) !== null && _a !== void 0 ? _a : this.currentType;
|
|
390
|
+
this.current = this.stack.pop();
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Handles composite types (interfaces and unions) by setting up the
|
|
394
|
+
* appropriate composite type metadata on the current message.
|
|
395
|
+
*
|
|
396
|
+
* @param fieldDefinition - The field definition with a composite type
|
|
397
|
+
*/
|
|
398
|
+
handleCompositeType(fieldDefinition) {
|
|
399
|
+
if (!this.current) {
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
const compositeType = getNamedType(fieldDefinition.type);
|
|
403
|
+
if (isInterfaceType(compositeType)) {
|
|
404
|
+
return {
|
|
405
|
+
kind: CompositeMessageKind.INTERFACE,
|
|
406
|
+
implementingTypes: this.schema.getImplementations(compositeType).objects.map((o) => o.name),
|
|
407
|
+
typeName: compositeType.name,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
if (isUnionType(compositeType)) {
|
|
411
|
+
return {
|
|
412
|
+
kind: CompositeMessageKind.UNION,
|
|
413
|
+
memberTypes: this.schema.getPossibleTypes(compositeType).map((t) => t.name),
|
|
414
|
+
typeName: compositeType.name,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Type guard to check if a node is a FieldNode.
|
|
421
|
+
*
|
|
422
|
+
* @param node - The AST node or array of nodes to check
|
|
423
|
+
* @returns True if the node is a FieldNode
|
|
424
|
+
*/
|
|
425
|
+
isFieldNode(node) {
|
|
426
|
+
if (Array.isArray(node)) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
return node.kind === Kind.FIELD;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Type guard to check if a node is an InlineFragmentNode.
|
|
433
|
+
*
|
|
434
|
+
* @param node - The AST node or array of nodes to check
|
|
435
|
+
* @returns True if the node is an InlineFragmentNode
|
|
436
|
+
*/
|
|
437
|
+
isInlineFragmentNode(node) {
|
|
438
|
+
if (Array.isArray(node)) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
return node.kind === Kind.INLINE_FRAGMENT;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Finds the GraphQL object type for a field by looking up the field's return type.
|
|
445
|
+
*
|
|
446
|
+
* @param fieldName - The name of the field to look up
|
|
447
|
+
* @returns The GraphQL object type if the field returns an object type, undefined otherwise
|
|
448
|
+
*/
|
|
449
|
+
findObjectTypeForField(fieldName) {
|
|
450
|
+
var _a, _b;
|
|
451
|
+
const fields = (_b = (_a = this.currentType) === null || _a === void 0 ? void 0 : _a.getFields()) !== null && _b !== void 0 ? _b : {};
|
|
452
|
+
const field = fields[fieldName];
|
|
453
|
+
if (!field) {
|
|
454
|
+
return undefined;
|
|
455
|
+
}
|
|
456
|
+
const namedType = getNamedType(field.type);
|
|
457
|
+
if (isObjectType(namedType)) {
|
|
458
|
+
return namedType;
|
|
459
|
+
}
|
|
460
|
+
return undefined;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Retrieves the field definition for a field name from the current type.
|
|
464
|
+
*
|
|
465
|
+
* @param fieldName - The name of the field to look up
|
|
466
|
+
* @returns The GraphQL field definition, or undefined if not found
|
|
467
|
+
*/
|
|
468
|
+
fieldDefinition(fieldName) {
|
|
469
|
+
var _a;
|
|
470
|
+
return (_a = this.currentType) === null || _a === void 0 ? void 0 : _a.getFields()[fieldName];
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Finds a GraphQL object type by name from the schema's type map.
|
|
474
|
+
*
|
|
475
|
+
* @param typeName - The name of the type to find
|
|
476
|
+
* @returns The GraphQL object type if found and is an object type, undefined otherwise
|
|
477
|
+
*/
|
|
478
|
+
findObjectType(typeName) {
|
|
479
|
+
const type = this.schema.getTypeMap()[typeName];
|
|
480
|
+
if (!type) {
|
|
481
|
+
return undefined;
|
|
482
|
+
}
|
|
483
|
+
if (!isObjectType(type)) {
|
|
484
|
+
return undefined;
|
|
485
|
+
}
|
|
486
|
+
return type;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Extracts the fields string from a @key directive's fields argument.
|
|
490
|
+
*
|
|
491
|
+
* @param directive - The @key directive node
|
|
492
|
+
* @returns The fields string value, or empty string if not found
|
|
493
|
+
*/
|
|
494
|
+
getKeyFieldsString(directive) {
|
|
495
|
+
var _a;
|
|
496
|
+
const fieldsArg = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find((arg) => arg.name.value === 'fields');
|
|
497
|
+
if (!fieldsArg) {
|
|
498
|
+
return '';
|
|
499
|
+
}
|
|
500
|
+
return fieldsArg.value.kind === Kind.STRING ? fieldsArg.value.value : '';
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Checks if a GraphQL type is a composite type (interface or union).
|
|
504
|
+
*
|
|
505
|
+
* @param type - The GraphQL type to check
|
|
506
|
+
* @returns True if the type is an interface or union type
|
|
507
|
+
*/
|
|
508
|
+
isCompositeType(type) {
|
|
509
|
+
const namedType = getNamedType(type);
|
|
510
|
+
return isInterfaceType(namedType) || isUnionType(namedType);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
//# sourceMappingURL=required-fields-visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required-fields-visitor.js","sourceRoot":"","sources":["../../src/required-fields-visitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,YAAY,EAMZ,eAAe,EACf,YAAY,EACZ,WAAW,EACX,IAAI,EACJ,KA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C;IACnB,CAAC;IAED;;;;;OAKG;IACK,eAAe,CAAC,SAAiB;;QACvC,OAAO,MAAA,IAAI,CAAC,WAAW,0CAAE,SAAS,GAAG,SAAS,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,QAAgB;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACK,kBAAkB,CAAC,SAAwB;;QACjD,MAAM,SAAS,GAAG,MAAA,SAAS,CAAC,SAAS,0CAAE,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC;QAClF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,CAAC;IAED;;;;;OAKG;IACK,eAAe,CAAC,IAAiB;QACvC,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACrC,OAAO,eAAe,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -12,7 +12,7 @@ import { GRPCMapping } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
|
|
|
12
12
|
* The generated mappings are used to translate between GraphQL and Protocol Buffer
|
|
13
13
|
* representations in a consistent manner.
|
|
14
14
|
*/
|
|
15
|
-
export declare class
|
|
15
|
+
export declare class GraphQLToMappingVisitor {
|
|
16
16
|
private readonly mapping;
|
|
17
17
|
private readonly schema;
|
|
18
18
|
/**
|
|
@@ -40,6 +40,14 @@ export declare class GraphQLToProtoVisitor {
|
|
|
40
40
|
* lookup RPC methods and entity mappings.
|
|
41
41
|
*/
|
|
42
42
|
private processEntityTypes;
|
|
43
|
+
private createRequiredFieldsMapping;
|
|
44
|
+
/**
|
|
45
|
+
* Extracts the required field set from a field's requires directive
|
|
46
|
+
* @param field - The GraphQL field to get the required field set from
|
|
47
|
+
* @returns The required field set string
|
|
48
|
+
* @throws Error if the required field set is not found or is not a string
|
|
49
|
+
*/
|
|
50
|
+
private getRequiredFieldSet;
|
|
43
51
|
/**
|
|
44
52
|
* Extract all key directives from a GraphQL object type
|
|
45
53
|
*
|