@wundergraph/protographic 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.
- package/LICENSE +201 -0
- package/README.md +162 -0
- package/dist/src/index.d.ts +37 -0
- package/dist/src/index.js +53 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/naming-conventions.d.ts +50 -0
- package/dist/src/naming-conventions.js +62 -0
- package/dist/src/naming-conventions.js.map +1 -0
- package/dist/src/proto-lock.d.ts +66 -0
- package/dist/src/proto-lock.js +150 -0
- package/dist/src/proto-lock.js.map +1 -0
- package/dist/src/sdl-to-mapping-visitor.d.ts +172 -0
- package/dist/src/sdl-to-mapping-visitor.js +365 -0
- package/dist/src/sdl-to-mapping-visitor.js.map +1 -0
- package/dist/src/sdl-to-proto-visitor.d.ts +278 -0
- package/dist/src/sdl-to-proto-visitor.js +1200 -0
- package/dist/src/sdl-to-proto-visitor.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdl-to-mapping-visitor.js","sourceRoot":"","sources":["../../src/sdl-to-mapping-visitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,IAAI,GACL,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC7B,8BAA8B,EAC9B,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,gCAAgC,EAChC,wBAAwB,GAEzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,gBAAgB,GACjB,MAAM,iDAAiD,CAAC;AAGzD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,qBAAqB;IAIhC;;;;;OAKG;IACH,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C,IAAI,CAAC;QAC7B,yDAAyD;QACzD,MAAM,eAAe,GAAG,wBAAwB,CAAC,SAAS,CAAC,CAAC;QAC5D,MAAM,gBAAgB,GAAsB,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAE/E,OAAO,IAAI,YAAY,CAAC;YACtB,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,eAAe;YACvB,gBAAgB;SACjB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACK,sBAAsB,CAAC,KAA6B;QAC1D,MAAM,gBAAgB,GAAsB,EAAE,CAAC;QAE/C,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxC,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;gBAC7B,gBAAgB,CAAC,IAAI,CACnB,IAAI,eAAe,CAAC;oBAClB,QAAQ,EAAE,GAAG,CAAC,IAAI;oBAClB,4DAA4D;oBAC5D,MAAM,EAAE,2BAA2B,CAAC,GAAG,CAAC,IAAI,CAAC;iBAC9C,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
2
|
+
import { ProtoLock } from './proto-lock.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for GraphQLToProtoTextVisitor
|
|
5
|
+
*/
|
|
6
|
+
export interface GraphQLToProtoTextVisitorOptions {
|
|
7
|
+
serviceName?: string;
|
|
8
|
+
packageName?: string;
|
|
9
|
+
goPackage?: string;
|
|
10
|
+
lockData?: ProtoLock;
|
|
11
|
+
/** Whether to include descriptions/comments from GraphQL schema */
|
|
12
|
+
includeComments?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Visitor that converts GraphQL SDL to Protocol Buffer text definition
|
|
16
|
+
*
|
|
17
|
+
* This visitor traverses a GraphQL schema and generates a Protocol Buffer
|
|
18
|
+
* service and message definitions. It handles:
|
|
19
|
+
*
|
|
20
|
+
* 1. GraphQL scalars, objects, interfaces, unions, and enums
|
|
21
|
+
* 2. Federation entity types with @key directives
|
|
22
|
+
* 3. Query and Mutation operations as RPC methods
|
|
23
|
+
* 4. Field and argument mappings with proper naming conventions
|
|
24
|
+
* 5. Comments/descriptions from GraphQL types and fields
|
|
25
|
+
*
|
|
26
|
+
* The visitor uses a queue-based approach to resolve dependencies between
|
|
27
|
+
* types and ensure all referenced types are processed.
|
|
28
|
+
*/
|
|
29
|
+
export declare class GraphQLToProtoTextVisitor {
|
|
30
|
+
/** The GraphQL schema being converted */
|
|
31
|
+
private readonly schema;
|
|
32
|
+
/** The name of the Protocol Buffer service */
|
|
33
|
+
private readonly serviceName;
|
|
34
|
+
/** The lock manager for deterministic ordering */
|
|
35
|
+
private readonly lockManager;
|
|
36
|
+
/** Generated proto lock data */
|
|
37
|
+
private generatedLockData;
|
|
38
|
+
/** Accumulates the Protocol Buffer definition text */
|
|
39
|
+
private protoText;
|
|
40
|
+
/** Current indentation level for formatted output */
|
|
41
|
+
private indent;
|
|
42
|
+
/** Whether to include descriptions/comments from GraphQL schema */
|
|
43
|
+
private includeComments;
|
|
44
|
+
/** Tracks types that have already been processed to avoid duplication */
|
|
45
|
+
private processedTypes;
|
|
46
|
+
/** Queue of types that need to be converted to Proto messages */
|
|
47
|
+
private messageQueue;
|
|
48
|
+
/** Track generated nested list wrapper messages */
|
|
49
|
+
private nestedListWrappers;
|
|
50
|
+
/**
|
|
51
|
+
* Map of message names to their field numbers for tracking deleted fields
|
|
52
|
+
* This maintains field numbers even when fields are removed from the schema
|
|
53
|
+
*/
|
|
54
|
+
private fieldNumbersMap;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new visitor to convert a GraphQL schema to Protocol Buffers
|
|
57
|
+
*
|
|
58
|
+
* @param schema - The GraphQL schema to convert
|
|
59
|
+
* @param options - Configuration options for the visitor
|
|
60
|
+
*/
|
|
61
|
+
constructor(schema: GraphQLSchema, options?: GraphQLToProtoTextVisitorOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Initialize the field numbers map from the lock data to preserve field numbers
|
|
64
|
+
* even when fields are removed and later re-added
|
|
65
|
+
*/
|
|
66
|
+
private initializeFieldNumbersMap;
|
|
67
|
+
/**
|
|
68
|
+
* Track removed fields for a given message type between schema updates.
|
|
69
|
+
* This ensures that when fields are removed within a single operation,
|
|
70
|
+
* their numbers are properly reserved.
|
|
71
|
+
*
|
|
72
|
+
* @param typeName - The message type name
|
|
73
|
+
* @param originalFieldNames - Original field names from the lock data
|
|
74
|
+
* @param currentFieldNames - Current field names from the schema
|
|
75
|
+
*/
|
|
76
|
+
private trackRemovedFields;
|
|
77
|
+
/**
|
|
78
|
+
* Track removed enum values for a given enum type.
|
|
79
|
+
*
|
|
80
|
+
* @param enumName - The enum type name
|
|
81
|
+
* @param originalValueNames - Original enum value names from the lock data
|
|
82
|
+
* @param currentValueNames - Current enum value names from the schema
|
|
83
|
+
*/
|
|
84
|
+
private trackRemovedEnumValues;
|
|
85
|
+
/**
|
|
86
|
+
* Get the proper field number for a field in a message, respecting the lock.
|
|
87
|
+
* This preserves field numbers for fields that were removed and later re-added.
|
|
88
|
+
*/
|
|
89
|
+
private getFieldNumber;
|
|
90
|
+
/**
|
|
91
|
+
* Get the next available field number for a message, taking care to avoid
|
|
92
|
+
* collisions with existing field numbers, including for fields that were
|
|
93
|
+
* removed from the schema but may be re-added in the future.
|
|
94
|
+
*/
|
|
95
|
+
private getNextAvailableFieldNumber;
|
|
96
|
+
/**
|
|
97
|
+
* Visit the GraphQL schema to generate Proto buffer definition
|
|
98
|
+
*
|
|
99
|
+
* @returns The complete Protocol Buffer definition as a string
|
|
100
|
+
*/
|
|
101
|
+
visit(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Collects RPC methods for entity types (types with @key directive)
|
|
104
|
+
*
|
|
105
|
+
* This method identifies entity types and creates lookup RPC methods
|
|
106
|
+
* for them without generating the request/response messages yet.
|
|
107
|
+
*
|
|
108
|
+
* @returns Object containing RPC methods and message definitions
|
|
109
|
+
*/
|
|
110
|
+
private collectEntityRpcMethods;
|
|
111
|
+
/**
|
|
112
|
+
* Collects RPC methods for query operations
|
|
113
|
+
*
|
|
114
|
+
* @returns Object containing RPC methods and message definitions
|
|
115
|
+
*/
|
|
116
|
+
private collectQueryRpcMethods;
|
|
117
|
+
/**
|
|
118
|
+
* Collects RPC methods for mutation operations
|
|
119
|
+
*
|
|
120
|
+
* @returns Object containing RPC methods and message definitions
|
|
121
|
+
*/
|
|
122
|
+
private collectMutationRpcMethods;
|
|
123
|
+
/**
|
|
124
|
+
* Shared method to collect RPC methods for query or mutation operations
|
|
125
|
+
*/
|
|
126
|
+
private collectOperationRpcMethods;
|
|
127
|
+
/**
|
|
128
|
+
* Queue a type for processing if not already processed
|
|
129
|
+
*/
|
|
130
|
+
private queueTypeForProcessing;
|
|
131
|
+
/**
|
|
132
|
+
* Queue a field's return type for processing if it's a complex type
|
|
133
|
+
*/
|
|
134
|
+
private queueFieldTypeForProcessing;
|
|
135
|
+
/**
|
|
136
|
+
* Create an RPC method definition with optional comment
|
|
137
|
+
*
|
|
138
|
+
* @param methodName - The name of the RPC method
|
|
139
|
+
* @param requestName - The request message name
|
|
140
|
+
* @param responseName - The response message name
|
|
141
|
+
* @param description - Optional description for the method
|
|
142
|
+
* @returns The RPC method definition with or without comment
|
|
143
|
+
*/
|
|
144
|
+
private createRpcMethod;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a request message for entity lookup without adding to protoText
|
|
147
|
+
*/
|
|
148
|
+
private createKeyRequestMessage;
|
|
149
|
+
/**
|
|
150
|
+
* Creates a response message for entity lookup without adding to protoText
|
|
151
|
+
*/
|
|
152
|
+
private createKeyResponseMessage;
|
|
153
|
+
/**
|
|
154
|
+
* Creates a request message for a query/mutation field
|
|
155
|
+
*/
|
|
156
|
+
private createFieldRequestMessage;
|
|
157
|
+
/**
|
|
158
|
+
* Creates a response message for a query/mutation field
|
|
159
|
+
*/
|
|
160
|
+
private createFieldResponseMessage;
|
|
161
|
+
/**
|
|
162
|
+
* Extract key fields from a directive
|
|
163
|
+
*
|
|
164
|
+
* The @key directive specifies which fields form the entity's primary key.
|
|
165
|
+
* We extract these for creating appropriate lookup methods.
|
|
166
|
+
*
|
|
167
|
+
* @param directive - The @key directive from the GraphQL AST
|
|
168
|
+
* @returns Array of field names that form the key
|
|
169
|
+
*/
|
|
170
|
+
private getKeyFieldsFromDirective;
|
|
171
|
+
/**
|
|
172
|
+
* Queue all types from the schema that need processing
|
|
173
|
+
*/
|
|
174
|
+
private queueAllSchemaTypes;
|
|
175
|
+
/**
|
|
176
|
+
* Process all queued complex types for message generation
|
|
177
|
+
*
|
|
178
|
+
* This is a key method that processes the message queue to generate
|
|
179
|
+
* Protocol Buffer messages for all complex types. The queue approach ensures:
|
|
180
|
+
*
|
|
181
|
+
* 1. All referenced types are eventually processed
|
|
182
|
+
* 2. Types are only processed once (avoids duplication)
|
|
183
|
+
* 3. Circular references are handled properly
|
|
184
|
+
* 4. Dependencies between types are resolved correctly
|
|
185
|
+
*/
|
|
186
|
+
private processMessageQueue;
|
|
187
|
+
/**
|
|
188
|
+
* Process a GraphQL object type to a Proto message
|
|
189
|
+
*
|
|
190
|
+
* Converts a GraphQL object type to a Protocol Buffer message with
|
|
191
|
+
* fields corresponding to the GraphQL object fields.
|
|
192
|
+
*
|
|
193
|
+
* @param type - The GraphQL object type
|
|
194
|
+
*/
|
|
195
|
+
private processObjectType;
|
|
196
|
+
/**
|
|
197
|
+
* Process a GraphQL input object type to a Proto message
|
|
198
|
+
*
|
|
199
|
+
* Converts a GraphQL input object type to a Protocol Buffer message
|
|
200
|
+
* with fields corresponding to the GraphQL input object fields.
|
|
201
|
+
*
|
|
202
|
+
* @param type - The GraphQL input object type
|
|
203
|
+
*/
|
|
204
|
+
private processInputObjectType;
|
|
205
|
+
/**
|
|
206
|
+
* Process a GraphQL interface type
|
|
207
|
+
*
|
|
208
|
+
* In Protocol Buffers, we handle interfaces using the 'oneof' feature
|
|
209
|
+
* with all implementing types as options. This allows for polymorphic
|
|
210
|
+
* behavior similar to GraphQL interfaces.
|
|
211
|
+
*
|
|
212
|
+
* @param type - The GraphQL interface type
|
|
213
|
+
*/
|
|
214
|
+
private processInterfaceType;
|
|
215
|
+
/**
|
|
216
|
+
* Process a GraphQL union type
|
|
217
|
+
*
|
|
218
|
+
* Similar to interfaces, we handle GraphQL unions using Protocol Buffer's
|
|
219
|
+
* 'oneof' feature with all member types as options.
|
|
220
|
+
*
|
|
221
|
+
* @param type - The GraphQL union type
|
|
222
|
+
*/
|
|
223
|
+
private processUnionType;
|
|
224
|
+
/**
|
|
225
|
+
* Process a GraphQL enum type to a Proto enum
|
|
226
|
+
*
|
|
227
|
+
* Converts a GraphQL enum to a Protocol Buffer enum. Note that Proto3
|
|
228
|
+
* requires the first enum value to be zero, so we add an UNSPECIFIED value.
|
|
229
|
+
*
|
|
230
|
+
* @param type - The GraphQL enum type
|
|
231
|
+
*/
|
|
232
|
+
private processEnumType;
|
|
233
|
+
/**
|
|
234
|
+
* Map GraphQL type to Protocol Buffer type
|
|
235
|
+
*
|
|
236
|
+
* Determines the appropriate Protocol Buffer type for a given GraphQL type,
|
|
237
|
+
* handling all GraphQL type wrappers (NonNull, List) correctly.
|
|
238
|
+
*
|
|
239
|
+
* @param graphqlType - The GraphQL type to convert
|
|
240
|
+
* @returns The corresponding Protocol Buffer type name
|
|
241
|
+
*/
|
|
242
|
+
private getProtoTypeFromGraphQL;
|
|
243
|
+
/**
|
|
244
|
+
* Create a nested list wrapper message for the given base type
|
|
245
|
+
*/
|
|
246
|
+
private createNestedListWrapper;
|
|
247
|
+
/**
|
|
248
|
+
* Get indentation based on the current level
|
|
249
|
+
*
|
|
250
|
+
* Helper method to maintain consistent indentation in the output.
|
|
251
|
+
*
|
|
252
|
+
* @returns String with spaces for the current indentation level
|
|
253
|
+
*/
|
|
254
|
+
private getIndent;
|
|
255
|
+
/**
|
|
256
|
+
* Get the generated lock data after visiting
|
|
257
|
+
*
|
|
258
|
+
* @returns The generated ProtoLock data, or null if visit() hasn't been called
|
|
259
|
+
*/
|
|
260
|
+
getGeneratedLockData(): ProtoLock | null;
|
|
261
|
+
/**
|
|
262
|
+
* Format reserved numbers for Proto syntax
|
|
263
|
+
*
|
|
264
|
+
* Formats a list of reserved field numbers for inclusion in a Proto message.
|
|
265
|
+
* This handles both individual numbers and ranges.
|
|
266
|
+
*
|
|
267
|
+
* @param numbers - The field numbers to be reserved
|
|
268
|
+
* @returns A formatted string for the reserved statement
|
|
269
|
+
*/
|
|
270
|
+
private formatReservedNumbers;
|
|
271
|
+
/**
|
|
272
|
+
* Convert a GraphQL description to Protocol Buffer comment
|
|
273
|
+
* @param description - The GraphQL description text
|
|
274
|
+
* @param indentLevel - The level of indentation for the comment (in number of 2-space blocks)
|
|
275
|
+
* @returns Array of comment lines with proper indentation
|
|
276
|
+
*/
|
|
277
|
+
private formatComment;
|
|
278
|
+
}
|