@wundergraph/protographic 0.11.0 → 0.12.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/README.md +34 -3
- package/dist/src/index.d.ts +15 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/operation-to-proto.d.ts +48 -0
- package/dist/src/operation-to-proto.js +378 -0
- package/dist/src/operation-to-proto.js.map +1 -0
- package/dist/src/operations/field-numbering.d.ts +73 -0
- package/dist/src/operations/field-numbering.js +134 -0
- package/dist/src/operations/field-numbering.js.map +1 -0
- package/dist/src/operations/list-type-utils.d.ts +28 -0
- package/dist/src/operations/list-type-utils.js +49 -0
- package/dist/src/operations/list-type-utils.js.map +1 -0
- package/dist/src/operations/message-builder.d.ts +58 -0
- package/dist/src/operations/message-builder.js +377 -0
- package/dist/src/operations/message-builder.js.map +1 -0
- package/dist/src/operations/proto-text-generator.d.ts +74 -0
- package/dist/src/operations/proto-text-generator.js +336 -0
- package/dist/src/operations/proto-text-generator.js.map +1 -0
- package/dist/src/operations/request-builder.d.ts +56 -0
- package/dist/src/operations/request-builder.js +194 -0
- package/dist/src/operations/request-builder.js.map +1 -0
- package/dist/src/operations/type-mapper.d.ts +66 -0
- package/dist/src/operations/type-mapper.js +236 -0
- package/dist/src/operations/type-mapper.js.map +1 -0
- package/dist/src/proto-options.d.ts +23 -0
- package/dist/src/proto-options.js +45 -0
- package/dist/src/proto-options.js.map +1 -0
- package/dist/src/sdl-to-proto-visitor.d.ts +2 -14
- package/dist/src/sdl-to-proto-visitor.js +25 -38
- package/dist/src/sdl-to-proto-visitor.js.map +1 -1
- package/dist/src/types.d.ts +12 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import protobuf from 'protobufjs';
|
|
2
|
+
import { typeFromAST, } from 'graphql';
|
|
3
|
+
import { mapGraphQLTypeToProto } from './type-mapper.js';
|
|
4
|
+
import { assignFieldNumbersFromLockData } from './field-numbering.js';
|
|
5
|
+
import { graphqlFieldToProtoField, graphqlArgumentToProtoField, createEnumUnspecifiedValue, graphqlEnumValueToProtoEnumValue, } from '../naming-conventions.js';
|
|
6
|
+
/**
|
|
7
|
+
* Builds a Protocol Buffer request message from GraphQL operation variables
|
|
8
|
+
*
|
|
9
|
+
* @param messageName - The name for the request message
|
|
10
|
+
* @param variables - Array of variable definitions from the operation
|
|
11
|
+
* @param schema - The GraphQL schema for type resolution
|
|
12
|
+
* @param options - Optional configuration
|
|
13
|
+
* @returns A protobuf Type object representing the request message
|
|
14
|
+
*/
|
|
15
|
+
export function buildRequestMessage(messageName, variables, schema, options) {
|
|
16
|
+
const message = new protobuf.Type(messageName);
|
|
17
|
+
const fieldNumberManager = options === null || options === void 0 ? void 0 : options.fieldNumberManager;
|
|
18
|
+
// Collect all variable names
|
|
19
|
+
const variableNames = variables.map((v) => graphqlArgumentToProtoField(v.variable.name.value));
|
|
20
|
+
// Reconcile field order using lock manager if available
|
|
21
|
+
let orderedVariableNames = variableNames;
|
|
22
|
+
if (fieldNumberManager && 'reconcileFieldOrder' in fieldNumberManager) {
|
|
23
|
+
orderedVariableNames = fieldNumberManager.reconcileFieldOrder(messageName, variableNames);
|
|
24
|
+
}
|
|
25
|
+
// Create a map for quick lookup
|
|
26
|
+
const variableMap = new Map();
|
|
27
|
+
for (const variable of variables) {
|
|
28
|
+
const protoName = graphqlArgumentToProtoField(variable.variable.name.value);
|
|
29
|
+
variableMap.set(protoName, variable);
|
|
30
|
+
}
|
|
31
|
+
// Pre-assign field numbers from lock data if available
|
|
32
|
+
assignFieldNumbersFromLockData(messageName, orderedVariableNames, fieldNumberManager);
|
|
33
|
+
// Process variables in reconciled order
|
|
34
|
+
let fieldNumber = 1;
|
|
35
|
+
for (const protoVariableName of orderedVariableNames) {
|
|
36
|
+
const variable = variableMap.get(protoVariableName);
|
|
37
|
+
if (!variable)
|
|
38
|
+
continue;
|
|
39
|
+
const variableName = variable.variable.name.value;
|
|
40
|
+
const field = buildVariableField(variableName, variable.type, schema, messageName, options, fieldNumber);
|
|
41
|
+
if (field) {
|
|
42
|
+
message.add(field);
|
|
43
|
+
fieldNumber++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return message;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Builds a proto field from a GraphQL variable definition
|
|
50
|
+
*
|
|
51
|
+
* @param variableName - The name of the variable
|
|
52
|
+
* @param typeNode - The GraphQL type node from the variable definition
|
|
53
|
+
* @param schema - The GraphQL schema for type resolution
|
|
54
|
+
* @param messageName - The name of the message this field belongs to
|
|
55
|
+
* @param options - Optional configuration
|
|
56
|
+
* @param defaultFieldNumber - Default field number if no manager is provided
|
|
57
|
+
* @returns A protobuf Field object
|
|
58
|
+
*/
|
|
59
|
+
export function buildVariableField(variableName, typeNode, schema, messageName, options, defaultFieldNumber = 1) {
|
|
60
|
+
const protoFieldName = graphqlArgumentToProtoField(variableName);
|
|
61
|
+
const fieldNumberManager = options === null || options === void 0 ? void 0 : options.fieldNumberManager;
|
|
62
|
+
// Convert TypeNode to GraphQLType for mapping
|
|
63
|
+
const graphqlType = typeNodeToGraphQLType(typeNode, schema);
|
|
64
|
+
if (!graphqlType) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const typeInfo = mapGraphQLTypeToProto(graphqlType, {
|
|
68
|
+
customScalarMappings: options === null || options === void 0 ? void 0 : options.customScalarMappings,
|
|
69
|
+
});
|
|
70
|
+
// Handle nested list wrappers
|
|
71
|
+
let finalTypeName = typeInfo.typeName;
|
|
72
|
+
let isRepeated = typeInfo.isRepeated;
|
|
73
|
+
if (typeInfo.requiresNestedWrapper && (options === null || options === void 0 ? void 0 : options.ensureNestedListWrapper)) {
|
|
74
|
+
// Create wrapper message and use its name
|
|
75
|
+
finalTypeName = options.ensureNestedListWrapper(graphqlType);
|
|
76
|
+
isRepeated = false; // Wrapper handles the repetition
|
|
77
|
+
}
|
|
78
|
+
// Get field number - check if already assigned from reconciliation
|
|
79
|
+
const existingFieldNumber = fieldNumberManager === null || fieldNumberManager === void 0 ? void 0 : fieldNumberManager.getFieldNumber(messageName, protoFieldName);
|
|
80
|
+
let fieldNumber;
|
|
81
|
+
if (existingFieldNumber !== undefined) {
|
|
82
|
+
// Use existing field number from reconciliation
|
|
83
|
+
fieldNumber = existingFieldNumber;
|
|
84
|
+
}
|
|
85
|
+
else if (fieldNumberManager) {
|
|
86
|
+
// Get next field number and assign it
|
|
87
|
+
fieldNumber = fieldNumberManager.getNextFieldNumber(messageName);
|
|
88
|
+
fieldNumberManager.assignFieldNumber(messageName, protoFieldName, fieldNumber);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// No field number manager, use default
|
|
92
|
+
fieldNumber = defaultFieldNumber;
|
|
93
|
+
}
|
|
94
|
+
const field = new protobuf.Field(protoFieldName, fieldNumber, finalTypeName);
|
|
95
|
+
if (isRepeated) {
|
|
96
|
+
field.repeated = true;
|
|
97
|
+
}
|
|
98
|
+
return field;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Builds an input object message type from a GraphQL input object type
|
|
102
|
+
*
|
|
103
|
+
* @param inputType - The GraphQL input object type
|
|
104
|
+
* @param options - Optional configuration
|
|
105
|
+
* @returns A protobuf Type object
|
|
106
|
+
*/
|
|
107
|
+
export function buildInputObjectMessage(inputType, options) {
|
|
108
|
+
const message = new protobuf.Type(inputType.name);
|
|
109
|
+
const fieldNumberManager = options === null || options === void 0 ? void 0 : options.fieldNumberManager;
|
|
110
|
+
const fields = inputType.getFields();
|
|
111
|
+
// Collect all field names
|
|
112
|
+
const fieldNames = Object.keys(fields).map((name) => graphqlFieldToProtoField(name));
|
|
113
|
+
// Reconcile field order using lock manager if available
|
|
114
|
+
let orderedFieldNames = fieldNames;
|
|
115
|
+
if (fieldNumberManager && 'reconcileFieldOrder' in fieldNumberManager) {
|
|
116
|
+
orderedFieldNames = fieldNumberManager.reconcileFieldOrder(message.name, fieldNames);
|
|
117
|
+
}
|
|
118
|
+
// Create a map for quick lookup
|
|
119
|
+
const fieldMap = new Map();
|
|
120
|
+
for (const [fieldName, inputField] of Object.entries(fields)) {
|
|
121
|
+
const protoFieldName = graphqlFieldToProtoField(fieldName);
|
|
122
|
+
fieldMap.set(protoFieldName, inputField);
|
|
123
|
+
}
|
|
124
|
+
// Pre-assign field numbers from lock data if available
|
|
125
|
+
assignFieldNumbersFromLockData(message.name, orderedFieldNames, fieldNumberManager);
|
|
126
|
+
// Process fields in reconciled order
|
|
127
|
+
for (const protoFieldName of orderedFieldNames) {
|
|
128
|
+
const inputField = fieldMap.get(protoFieldName);
|
|
129
|
+
if (!inputField)
|
|
130
|
+
continue;
|
|
131
|
+
const typeInfo = mapGraphQLTypeToProto(inputField.type, {
|
|
132
|
+
customScalarMappings: options === null || options === void 0 ? void 0 : options.customScalarMappings,
|
|
133
|
+
});
|
|
134
|
+
// Handle nested list wrappers
|
|
135
|
+
let finalTypeName = typeInfo.typeName;
|
|
136
|
+
let isRepeated = typeInfo.isRepeated;
|
|
137
|
+
if (typeInfo.requiresNestedWrapper && (options === null || options === void 0 ? void 0 : options.ensureNestedListWrapper)) {
|
|
138
|
+
// Create wrapper message and use its name
|
|
139
|
+
finalTypeName = options.ensureNestedListWrapper(inputField.type);
|
|
140
|
+
isRepeated = false; // Wrapper handles the repetition
|
|
141
|
+
}
|
|
142
|
+
// Get field number - check if already assigned from reconciliation
|
|
143
|
+
let fieldNumber = fieldNumberManager === null || fieldNumberManager === void 0 ? void 0 : fieldNumberManager.getFieldNumber(message.name, protoFieldName);
|
|
144
|
+
if (fieldNumber === undefined && fieldNumberManager) {
|
|
145
|
+
fieldNumber = fieldNumberManager.getNextFieldNumber(message.name);
|
|
146
|
+
fieldNumberManager.assignFieldNumber(message.name, protoFieldName, fieldNumber);
|
|
147
|
+
}
|
|
148
|
+
else if (fieldNumber === undefined) {
|
|
149
|
+
fieldNumber = orderedFieldNames.indexOf(protoFieldName) + 1;
|
|
150
|
+
}
|
|
151
|
+
const field = new protobuf.Field(protoFieldName, fieldNumber, finalTypeName);
|
|
152
|
+
if (isRepeated) {
|
|
153
|
+
field.repeated = true;
|
|
154
|
+
}
|
|
155
|
+
if ((options === null || options === void 0 ? void 0 : options.includeComments) && inputField.description) {
|
|
156
|
+
field.comment = inputField.description;
|
|
157
|
+
}
|
|
158
|
+
message.add(field);
|
|
159
|
+
}
|
|
160
|
+
return message;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Builds an enum type from a GraphQL enum type
|
|
164
|
+
*
|
|
165
|
+
* @param enumType - The GraphQL enum type
|
|
166
|
+
* @param options - Optional configuration
|
|
167
|
+
* @returns A protobuf Enum object
|
|
168
|
+
*/
|
|
169
|
+
export function buildEnumType(enumType, options) {
|
|
170
|
+
const protoEnum = new protobuf.Enum(enumType.name);
|
|
171
|
+
// Proto3 requires the first enum value to be 0 (unspecified)
|
|
172
|
+
// Use prefixed UNSPECIFIED to avoid collisions when multiple enums are in the same scope
|
|
173
|
+
const unspecifiedValue = createEnumUnspecifiedValue(enumType.name);
|
|
174
|
+
protoEnum.add(unspecifiedValue, 0);
|
|
175
|
+
let enumNumber = 1;
|
|
176
|
+
const enumValues = enumType.getValues();
|
|
177
|
+
for (const enumValue of enumValues) {
|
|
178
|
+
// Prefix enum values with the enum type name to avoid collisions
|
|
179
|
+
const protoEnumValue = graphqlEnumValueToProtoEnumValue(enumType.name, enumValue.name);
|
|
180
|
+
protoEnum.add(protoEnumValue, enumNumber);
|
|
181
|
+
// Note: protobufjs doesn't have direct comment support for enum values
|
|
182
|
+
// In a full implementation, you'd track these separately for text generation
|
|
183
|
+
enumNumber++;
|
|
184
|
+
}
|
|
185
|
+
return protoEnum;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Helper to convert a GraphQL TypeNode to a GraphQLType
|
|
189
|
+
* Uses GraphQL's built-in typeFromAST to properly handle NonNull and List wrappers
|
|
190
|
+
*/
|
|
191
|
+
function typeNodeToGraphQLType(typeNode, schema) {
|
|
192
|
+
return typeFromAST(schema, typeNode);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=request-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-builder.js","sourceRoot":"","sources":["../../../src/operations/request-builder.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAUL,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,8BAA8B,EAAsB,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,0BAA0B,EAC1B,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAkBlC;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,WAAmB,EACnB,SAAgD,EAChD,MAAqB,EACrB,OAA+B;IAE/B,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,kBAAkB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,CAAC;IAEvD,6BAA6B;IAC7B,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,2BAA2B,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAE/F,wDAAwD;IACxD,IAAI,oBAAoB,GAAG,aAAa,CAAC;IACzC,IAAI,kBAAkB,IAAI,qBAAqB,IAAI,kBAAkB,EAAE,CAAC;QACtE,oBAAoB,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC5F,CAAC;IAED,gCAAgC;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@@
|
|
|
1
|
+
import { GraphQLType } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the proto type information for a GraphQL type
|
|
4
|
+
*/
|
|
5
|
+
export interface ProtoTypeInfo {
|
|
6
|
+
/** The proto type name */
|
|
7
|
+
typeName: string;
|
|
8
|
+
/** Whether the field should be repeated (for lists) */
|
|
9
|
+
isRepeated: boolean;
|
|
10
|
+
/** Whether this is a wrapper type */
|
|
11
|
+
isWrapper: boolean;
|
|
12
|
+
/** Whether this is a scalar type */
|
|
13
|
+
isScalar: boolean;
|
|
14
|
+
/** Whether this requires a nested list wrapper message */
|
|
15
|
+
requiresNestedWrapper?: boolean;
|
|
16
|
+
/** The nesting level for nested lists (e.g., 2 for [[String]]) */
|
|
17
|
+
nestingLevel?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for mapping GraphQL types to Proto types
|
|
21
|
+
*/
|
|
22
|
+
export interface TypeMapperOptions {
|
|
23
|
+
/** Custom scalar type mappings (scalar name -> proto type) */
|
|
24
|
+
customScalarMappings?: Record<string, string>;
|
|
25
|
+
/** Whether to use wrapper types for nullable scalars (default: true) */
|
|
26
|
+
useWrapperTypes?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Maps a GraphQL type to its Protocol Buffer type representation
|
|
30
|
+
*
|
|
31
|
+
* @param type - The GraphQL type to map
|
|
32
|
+
* @param options - Optional type mapping configuration
|
|
33
|
+
* @returns Proto type information including type name, repeated flag, etc.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mapGraphQLTypeToProto(type: GraphQLType, options?: TypeMapperOptions): ProtoTypeInfo;
|
|
36
|
+
/**
|
|
37
|
+
* Gets the Protocol Buffer type name for a GraphQL type
|
|
38
|
+
*
|
|
39
|
+
* @param type - The GraphQL type
|
|
40
|
+
* @param options - Optional type mapping configuration
|
|
41
|
+
* @returns The proto type name as a string
|
|
42
|
+
*/
|
|
43
|
+
export declare function getProtoTypeName(type: GraphQLType, options?: TypeMapperOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a GraphQL type is a scalar type
|
|
46
|
+
*
|
|
47
|
+
* @param type - The GraphQL type to check
|
|
48
|
+
* @returns True if the type is a scalar
|
|
49
|
+
*/
|
|
50
|
+
export declare function isGraphQLScalarType(type: GraphQLType): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if a GraphQL type requires a wrapper type in proto
|
|
53
|
+
*
|
|
54
|
+
* @param type - The GraphQL type to check
|
|
55
|
+
* @param options - Optional type mapping configuration
|
|
56
|
+
* @returns True if the type needs a wrapper
|
|
57
|
+
*/
|
|
58
|
+
export declare function requiresWrapperType(type: GraphQLType, options?: TypeMapperOptions): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the list of required proto imports based on the types used
|
|
61
|
+
*
|
|
62
|
+
* @param types - Array of GraphQL types that will be mapped
|
|
63
|
+
* @param options - Optional type mapping configuration
|
|
64
|
+
* @returns Array of import statements needed
|
|
65
|
+
*/
|
|
66
|
+
export declare function getRequiredImports(types: GraphQLType[], options?: TypeMapperOptions): string[];
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { isScalarType, isEnumType, isObjectType, isInterfaceType, isUnionType, isInputObjectType, isListType, isNonNullType, getNamedType, } from 'graphql';
|
|
2
|
+
import { unwrapNonNullType, isNestedListType, calculateNestingLevel } from './list-type-utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Maps GraphQL scalar types to Protocol Buffer types
|
|
5
|
+
*/
|
|
6
|
+
const SCALAR_TYPE_MAP = {
|
|
7
|
+
ID: 'string',
|
|
8
|
+
String: 'string',
|
|
9
|
+
Int: 'int32',
|
|
10
|
+
Float: 'double',
|
|
11
|
+
Boolean: 'bool',
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Maps GraphQL scalar types to Protocol Buffer wrapper types for nullable fields
|
|
15
|
+
*/
|
|
16
|
+
const SCALAR_WRAPPER_TYPE_MAP = {
|
|
17
|
+
ID: 'google.protobuf.StringValue',
|
|
18
|
+
String: 'google.protobuf.StringValue',
|
|
19
|
+
Int: 'google.protobuf.Int32Value',
|
|
20
|
+
Float: 'google.protobuf.DoubleValue',
|
|
21
|
+
Boolean: 'google.protobuf.BoolValue',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Maps a GraphQL type to its Protocol Buffer type representation
|
|
25
|
+
*
|
|
26
|
+
* @param type - The GraphQL type to map
|
|
27
|
+
* @param options - Optional type mapping configuration
|
|
28
|
+
* @returns Proto type information including type name, repeated flag, etc.
|
|
29
|
+
*/
|
|
30
|
+
export function mapGraphQLTypeToProto(type, options) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
const useWrapperTypes = (_a = options === null || options === void 0 ? void 0 : options.useWrapperTypes) !== null && _a !== void 0 ? _a : true;
|
|
33
|
+
const customScalarMappings = (_b = options === null || options === void 0 ? void 0 : options.customScalarMappings) !== null && _b !== void 0 ? _b : {};
|
|
34
|
+
// Check for nested lists first (before handling non-null)
|
|
35
|
+
if (isListType(type) || (isNonNullType(type) && isListType(type.ofType))) {
|
|
36
|
+
return handleListType(type, options);
|
|
37
|
+
}
|
|
38
|
+
// Handle non-null types
|
|
39
|
+
if (isNonNullType(type)) {
|
|
40
|
+
const innerType = type.ofType;
|
|
41
|
+
const innerInfo = mapGraphQLTypeToProto(innerType, options);
|
|
42
|
+
// For non-null scalars, we don't use wrapper types
|
|
43
|
+
if (isScalarType(getNamedType(innerType))) {
|
|
44
|
+
const namedType = getNamedType(innerType);
|
|
45
|
+
const scalarName = namedType.name;
|
|
46
|
+
// Check custom mappings first
|
|
47
|
+
if (customScalarMappings[scalarName]) {
|
|
48
|
+
return {
|
|
49
|
+
typeName: customScalarMappings[scalarName],
|
|
50
|
+
isRepeated: innerInfo.isRepeated,
|
|
51
|
+
isWrapper: false,
|
|
52
|
+
isScalar: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Use direct scalar type for non-null fields
|
|
56
|
+
if (SCALAR_TYPE_MAP[scalarName]) {
|
|
57
|
+
return {
|
|
58
|
+
typeName: SCALAR_TYPE_MAP[scalarName],
|
|
59
|
+
isRepeated: innerInfo.isRepeated,
|
|
60
|
+
isWrapper: false,
|
|
61
|
+
isScalar: true,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return innerInfo;
|
|
66
|
+
}
|
|
67
|
+
// Get the named type
|
|
68
|
+
const namedType = getNamedType(type);
|
|
69
|
+
// Handle scalar types
|
|
70
|
+
if (isScalarType(namedType)) {
|
|
71
|
+
const scalarName = namedType.name;
|
|
72
|
+
// Check custom mappings first
|
|
73
|
+
if (customScalarMappings[scalarName]) {
|
|
74
|
+
return {
|
|
75
|
+
typeName: customScalarMappings[scalarName],
|
|
76
|
+
isRepeated: false,
|
|
77
|
+
isWrapper: false,
|
|
78
|
+
isScalar: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Use wrapper types for nullable scalars
|
|
82
|
+
if (useWrapperTypes && SCALAR_WRAPPER_TYPE_MAP[scalarName]) {
|
|
83
|
+
return {
|
|
84
|
+
typeName: SCALAR_WRAPPER_TYPE_MAP[scalarName],
|
|
85
|
+
isRepeated: false,
|
|
86
|
+
isWrapper: true,
|
|
87
|
+
isScalar: true,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// Fallback to direct mapping
|
|
91
|
+
const protoType = SCALAR_TYPE_MAP[scalarName] || 'string';
|
|
92
|
+
return {
|
|
93
|
+
typeName: protoType,
|
|
94
|
+
isRepeated: false,
|
|
95
|
+
isWrapper: false,
|
|
96
|
+
isScalar: true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Handle enum types
|
|
100
|
+
if (isEnumType(namedType)) {
|
|
101
|
+
return {
|
|
102
|
+
typeName: namedType.name,
|
|
103
|
+
isRepeated: false,
|
|
104
|
+
isWrapper: false,
|
|
105
|
+
isScalar: false,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Handle input object types
|
|
109
|
+
if (isInputObjectType(namedType)) {
|
|
110
|
+
return {
|
|
111
|
+
typeName: namedType.name,
|
|
112
|
+
isRepeated: false,
|
|
113
|
+
isWrapper: false,
|
|
114
|
+
isScalar: false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// Handle object, interface, and union types
|
|
118
|
+
if (isObjectType(namedType) || isInterfaceType(namedType) || isUnionType(namedType)) {
|
|
119
|
+
return {
|
|
120
|
+
typeName: namedType.name,
|
|
121
|
+
isRepeated: false,
|
|
122
|
+
isWrapper: false,
|
|
123
|
+
isScalar: false,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Fallback for unknown types
|
|
127
|
+
return {
|
|
128
|
+
typeName: 'string',
|
|
129
|
+
isRepeated: false,
|
|
130
|
+
isWrapper: false,
|
|
131
|
+
isScalar: true,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Handles GraphQL list types, including nested lists
|
|
136
|
+
* Similar to sdl-to-proto-visitor.ts handleListType
|
|
137
|
+
*/
|
|
138
|
+
function handleListType(graphqlType, options) {
|
|
139
|
+
const listType = unwrapNonNullType(graphqlType);
|
|
140
|
+
const isNullableList = !isNonNullType(graphqlType);
|
|
141
|
+
// Only check for nested lists if we have a list type
|
|
142
|
+
if (!isListType(listType)) {
|
|
143
|
+
// This shouldn't happen, but handle gracefully
|
|
144
|
+
return mapGraphQLTypeToProto(listType, options);
|
|
145
|
+
}
|
|
146
|
+
const isNestedList = isNestedListType(listType);
|
|
147
|
+
// Simple non-nullable lists can use repeated fields directly
|
|
148
|
+
if (!isNullableList && !isNestedList) {
|
|
149
|
+
const baseType = getNamedType(listType);
|
|
150
|
+
const baseTypeInfo = mapGraphQLTypeToProto(baseType, { ...options, useWrapperTypes: false });
|
|
151
|
+
return {
|
|
152
|
+
...baseTypeInfo,
|
|
153
|
+
isRepeated: true,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// Only nested lists need wrapper messages
|
|
157
|
+
// Single-level nullable lists use repeated + wrapper types for nullable items
|
|
158
|
+
if (isNestedList) {
|
|
159
|
+
const baseType = getNamedType(listType);
|
|
160
|
+
const nestingLevel = calculateNestingLevel(listType);
|
|
161
|
+
// Generate wrapper message name
|
|
162
|
+
const wrapperName = `${'ListOf'.repeat(nestingLevel)}${baseType.name}`;
|
|
163
|
+
// For nested lists, never use repeated at field level to preserve nullability
|
|
164
|
+
return {
|
|
165
|
+
typeName: wrapperName,
|
|
166
|
+
isRepeated: false,
|
|
167
|
+
isWrapper: false,
|
|
168
|
+
isScalar: false,
|
|
169
|
+
requiresNestedWrapper: true,
|
|
170
|
+
nestingLevel: nestingLevel,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// Single-level nullable lists: [String], [String!], etc.
|
|
174
|
+
// Use repeated with appropriate item type (wrapper type for nullable items)
|
|
175
|
+
if (!isListType(listType)) {
|
|
176
|
+
// Safety check - shouldn't happen
|
|
177
|
+
return mapGraphQLTypeToProto(listType, options);
|
|
178
|
+
}
|
|
179
|
+
const itemType = listType.ofType;
|
|
180
|
+
const itemTypeInfo = mapGraphQLTypeToProto(itemType, options);
|
|
181
|
+
return {
|
|
182
|
+
typeName: itemTypeInfo.typeName,
|
|
183
|
+
isRepeated: true,
|
|
184
|
+
isWrapper: itemTypeInfo.isWrapper,
|
|
185
|
+
isScalar: itemTypeInfo.isScalar,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Gets the Protocol Buffer type name for a GraphQL type
|
|
190
|
+
*
|
|
191
|
+
* @param type - The GraphQL type
|
|
192
|
+
* @param options - Optional type mapping configuration
|
|
193
|
+
* @returns The proto type name as a string
|
|
194
|
+
*/
|
|
195
|
+
export function getProtoTypeName(type, options) {
|
|
196
|
+
const typeInfo = mapGraphQLTypeToProto(type, options);
|
|
197
|
+
return typeInfo.typeName;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Checks if a GraphQL type is a scalar type
|
|
201
|
+
*
|
|
202
|
+
* @param type - The GraphQL type to check
|
|
203
|
+
* @returns True if the type is a scalar
|
|
204
|
+
*/
|
|
205
|
+
export function isGraphQLScalarType(type) {
|
|
206
|
+
return isScalarType(getNamedType(type));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Checks if a GraphQL type requires a wrapper type in proto
|
|
210
|
+
*
|
|
211
|
+
* @param type - The GraphQL type to check
|
|
212
|
+
* @param options - Optional type mapping configuration
|
|
213
|
+
* @returns True if the type needs a wrapper
|
|
214
|
+
*/
|
|
215
|
+
export function requiresWrapperType(type, options) {
|
|
216
|
+
const typeInfo = mapGraphQLTypeToProto(type, options);
|
|
217
|
+
return typeInfo.isWrapper;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Gets the list of required proto imports based on the types used
|
|
221
|
+
*
|
|
222
|
+
* @param types - Array of GraphQL types that will be mapped
|
|
223
|
+
* @param options - Optional type mapping configuration
|
|
224
|
+
* @returns Array of import statements needed
|
|
225
|
+
*/
|
|
226
|
+
export function getRequiredImports(types, options) {
|
|
227
|
+
const imports = new Set();
|
|
228
|
+
for (const type of types) {
|
|
229
|
+
const typeInfo = mapGraphQLTypeToProto(type, options);
|
|
230
|
+
if (typeInfo.isWrapper) {
|
|
231
|
+
imports.add('google/protobuf/wrappers.proto');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return Array.from(imports);
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=type-mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-mapper.js","sourceRoot":"","sources":["../../../src/operations/type-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,YAAY,GAEb,MAAM,SAAS,CAAC;AACjB,OAA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/
|
|
4
|
+
export interface ProtoOptions {
|
|
5
|
+
goPackage?: string;
|
|
6
|
+
javaPackage?: string;
|
|
7
|
+
javaOuterClassname?: string;
|
|
8
|
+
javaMultipleFiles?: boolean;
|
|
9
|
+
csharpNamespace?: string;
|
|
10
|
+
rubyPackage?: string;
|
|
11
|
+
phpNamespace?: string;
|
|
12
|
+
phpMetadataNamespace?: string;
|
|
13
|
+
objcClassPrefix?: string;
|
|
14
|
+
swiftPrefix?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Builds an array of proto option statements from the provided options
|
|
18
|
+
*
|
|
19
|
+
* @param options - The proto options to convert to statements
|
|
20
|
+
* @param packageName - Optional package name for generating default go_package
|
|
21
|
+
* @returns Array of proto option statements (e.g., 'option go_package = "...";')
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildProtoOptions(options: ProtoOptions, packageName?: string): string[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an array of proto option statements from the provided options
|
|
3
|
+
*
|
|
4
|
+
* @param options - The proto options to convert to statements
|
|
5
|
+
* @param packageName - Optional package name for generating default go_package
|
|
6
|
+
* @returns Array of proto option statements (e.g., 'option go_package = "...";')
|
|
7
|
+
*/
|
|
8
|
+
export function buildProtoOptions(options, packageName) {
|
|
9
|
+
const optionStatements = [];
|
|
10
|
+
if (options.goPackage && options.goPackage !== '') {
|
|
11
|
+
// Generate default go_package if not provided
|
|
12
|
+
const defaultGoPackage = packageName ? `cosmo/pkg/proto/${packageName};${packageName.replace('.', '')}` : undefined;
|
|
13
|
+
const goPackageOption = options.goPackage || defaultGoPackage;
|
|
14
|
+
optionStatements.push(`option go_package = "${goPackageOption}";`);
|
|
15
|
+
}
|
|
16
|
+
if (options.javaPackage) {
|
|
17
|
+
optionStatements.push(`option java_package = "${options.javaPackage}";`);
|
|
18
|
+
}
|
|
19
|
+
if (options.javaOuterClassname) {
|
|
20
|
+
optionStatements.push(`option java_outer_classname = "${options.javaOuterClassname}";`);
|
|
21
|
+
}
|
|
22
|
+
if (options.javaMultipleFiles) {
|
|
23
|
+
optionStatements.push(`option java_multiple_files = true;`);
|
|
24
|
+
}
|
|
25
|
+
if (options.csharpNamespace) {
|
|
26
|
+
optionStatements.push(`option csharp_namespace = "${options.csharpNamespace}";`);
|
|
27
|
+
}
|
|
28
|
+
if (options.rubyPackage) {
|
|
29
|
+
optionStatements.push(`option ruby_package = "${options.rubyPackage}";`);
|
|
30
|
+
}
|
|
31
|
+
if (options.phpNamespace) {
|
|
32
|
+
optionStatements.push(`option php_namespace = "${options.phpNamespace}";`);
|
|
33
|
+
}
|
|
34
|
+
if (options.phpMetadataNamespace) {
|
|
35
|
+
optionStatements.push(`option php_metadata_namespace = "${options.phpMetadataNamespace}";`);
|
|
36
|
+
}
|
|
37
|
+
if (options.objcClassPrefix) {
|
|
38
|
+
optionStatements.push(`option objc_class_prefix = "${options.objcClassPrefix}";`);
|
|
39
|
+
}
|
|
40
|
+
if (options.swiftPrefix) {
|
|
41
|
+
optionStatements.push(`option swift_prefix = "${options.swiftPrefix}";`);
|
|
42
|
+
}
|
|
43
|
+
return optionStatements;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=proto-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto-options.js","sourceRoot":"","sources":["../../src/proto-options.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAqB,EAAE,WAAoB;IAC3E,MAAM,gBAAgB,GAAa,EAAE,CAAC;IAEtC,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,KAAK,EAAE,EAAE,CAAC;QAClD,8CAA8C;QAC9C,MAAM,gBAAgB,GAAG,WAAW,CAAC,CAAC,CAAC,mBAAmB,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;Q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B,CAAC,IAAI,CAAC,0BAA0B,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ProtoLock } from './proto-lock.js';
|
|
3
|
+
import { type ProtoOptions } from './proto-options.js';
|
|
3
4
|
/**
|
|
4
5
|
* Options for GraphQLToProtoTextVisitor
|
|
5
6
|
*/
|
|
6
|
-
export interface GraphQLToProtoTextVisitorOptions {
|
|
7
|
+
export interface GraphQLToProtoTextVisitorOptions extends ProtoOptions {
|
|
7
8
|
serviceName?: string;
|
|
8
9
|
packageName?: string;
|
|
9
10
|
lockData?: ProtoLock;
|
|
@@ -363,19 +364,6 @@ export declare class GraphQLToProtoTextVisitor {
|
|
|
363
364
|
* @returns ProtoType object containing the type name and whether it should be repeated
|
|
364
365
|
*/
|
|
365
366
|
private handleListType;
|
|
366
|
-
/**
|
|
367
|
-
* Unwraps a GraphQL type from a GraphQLNonNull type
|
|
368
|
-
*/
|
|
369
|
-
private unwrapNonNullType;
|
|
370
|
-
/**
|
|
371
|
-
* Checks if a GraphQL list type contains nested lists
|
|
372
|
-
* Type guard that narrows the input type when nested lists are detected
|
|
373
|
-
*/
|
|
374
|
-
private isNestedListType;
|
|
375
|
-
/**
|
|
376
|
-
* Calculates the nesting level of a GraphQL list type
|
|
377
|
-
*/
|
|
378
|
-
private calculateNestingLevel;
|
|
379
367
|
/**
|
|
380
368
|
* Creates wrapper messages for nullable or nested GraphQL lists.
|
|
381
369
|
*
|