@wundergraph/protographic 0.15.6 → 0.16.1
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.js +5 -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 +270 -390
- 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,112 @@
|
|
|
1
|
+
import { DocumentNode, GraphQLObjectType } from 'graphql';
|
|
2
|
+
import { ValidationResult } from './sdl-validation-visitor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validates selection sets within @requires directive field sets.
|
|
5
|
+
*
|
|
6
|
+
* This visitor traverses a parsed field set document and enforces constraints
|
|
7
|
+
* specific to @requires directives:
|
|
8
|
+
* - Abstract types (interfaces, unions) are not allowed
|
|
9
|
+
* - Inline fragments are not allowed
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const doc = parse('{ address { street city } }');
|
|
14
|
+
* const visitor = new SelectionSetValidationVisitor(doc, ProductType);
|
|
15
|
+
* visitor.visit();
|
|
16
|
+
* const result = visitor.getValidationResult();
|
|
17
|
+
* if (result.errors.length > 0) {
|
|
18
|
+
* console.error('Validation failed:', result.errors);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class SelectionSetValidationVisitor {
|
|
23
|
+
private currentType;
|
|
24
|
+
private ancestors;
|
|
25
|
+
private readonly operationDocument;
|
|
26
|
+
private validationResult;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new SelectionSetValidationVisitor.
|
|
29
|
+
*
|
|
30
|
+
* @param operationDocument - The parsed GraphQL document representing the field set
|
|
31
|
+
* @param objectType - The root GraphQL object type to validate against
|
|
32
|
+
*/
|
|
33
|
+
constructor(operationDocument: DocumentNode, objectType: GraphQLObjectType);
|
|
34
|
+
/**
|
|
35
|
+
* Executes the validation by traversing the operation document.
|
|
36
|
+
* After calling this method, use `getValidationResult()` to retrieve any errors or warnings.
|
|
37
|
+
*/
|
|
38
|
+
visit(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the validation result containing any errors and warnings found during traversal.
|
|
41
|
+
*
|
|
42
|
+
* @returns The validation result with errors and warnings arrays
|
|
43
|
+
*/
|
|
44
|
+
getValidationResult(): ValidationResult;
|
|
45
|
+
/**
|
|
46
|
+
* Creates the AST visitor configuration for traversing the document.
|
|
47
|
+
*
|
|
48
|
+
* @returns An ASTVisitor object with handlers for Field and SelectionSet nodes
|
|
49
|
+
*/
|
|
50
|
+
private createASTVisitor;
|
|
51
|
+
/**
|
|
52
|
+
* Handles entering a field node during traversal.
|
|
53
|
+
* Validates that the field's type is not an abstract type (interface or union).
|
|
54
|
+
*
|
|
55
|
+
* @param ctx - The visit context containing the field node and its ancestors
|
|
56
|
+
* @returns BREAK if validation fails to stop traversal, undefined otherwise
|
|
57
|
+
*/
|
|
58
|
+
private onEnterField;
|
|
59
|
+
/**
|
|
60
|
+
* Unwraps a GraphQL type to get its underlying named type.
|
|
61
|
+
* Strips NonNull and List wrappers to get the base type.
|
|
62
|
+
*
|
|
63
|
+
* @param type - The GraphQL type to unwrap
|
|
64
|
+
* @returns The underlying named type
|
|
65
|
+
*/
|
|
66
|
+
private getUnderlyingType;
|
|
67
|
+
/**
|
|
68
|
+
* Retrieves the field definition for a field node from the current type.
|
|
69
|
+
* If the field is not found, a validation error is recorded and null is returned.
|
|
70
|
+
*
|
|
71
|
+
* @param node - The field node to look up
|
|
72
|
+
* @returns The GraphQL field definition, or null if not found
|
|
73
|
+
*/
|
|
74
|
+
private getFieldDefinition;
|
|
75
|
+
/**
|
|
76
|
+
* Handles entering a selection set node during traversal.
|
|
77
|
+
* Validates that inline fragments are not used and updates the current type
|
|
78
|
+
* context when descending into nested object types.
|
|
79
|
+
*
|
|
80
|
+
* @param ctx - The visit context containing the selection set node and its parent
|
|
81
|
+
* @returns BREAK if validation fails to stop traversal, undefined otherwise
|
|
82
|
+
*/
|
|
83
|
+
private onEnterSelectionSet;
|
|
84
|
+
/**
|
|
85
|
+
* Handles leaving a selection set node during traversal.
|
|
86
|
+
* Restores the previous type context when ascending back up the tree.
|
|
87
|
+
*
|
|
88
|
+
* @param ctx - The visit context containing the selection set node and its parent
|
|
89
|
+
*/
|
|
90
|
+
private onLeaveSelectionSet;
|
|
91
|
+
/**
|
|
92
|
+
* Type guard to check if a node is an InlineFragmentNode.
|
|
93
|
+
*
|
|
94
|
+
* @param node - The AST node or array of nodes to check
|
|
95
|
+
* @returns True if the node is an InlineFragmentNode
|
|
96
|
+
*/
|
|
97
|
+
private isInlineFragment;
|
|
98
|
+
/**
|
|
99
|
+
* Type guard to check if a node is a FieldNode.
|
|
100
|
+
*
|
|
101
|
+
* @param node - The AST node or array of nodes to check
|
|
102
|
+
* @returns True if the node is a FieldNode
|
|
103
|
+
*/
|
|
104
|
+
private isFieldNode;
|
|
105
|
+
/**
|
|
106
|
+
* Checks if a named type is an abstract type (interface or union).
|
|
107
|
+
*
|
|
108
|
+
* @param node - The GraphQL named type to check
|
|
109
|
+
* @returns True if the type is an interface or union type
|
|
110
|
+
*/
|
|
111
|
+
private isAbstractType;
|
|
112
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { BREAK, isInterfaceType, isNamedType, isObjectType, isUnionType, Kind, visit, } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Validates selection sets within @requires directive field sets.
|
|
4
|
+
*
|
|
5
|
+
* This visitor traverses a parsed field set document and enforces constraints
|
|
6
|
+
* specific to @requires directives:
|
|
7
|
+
* - Abstract types (interfaces, unions) are not allowed
|
|
8
|
+
* - Inline fragments are not allowed
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const doc = parse('{ address { street city } }');
|
|
13
|
+
* const visitor = new SelectionSetValidationVisitor(doc, ProductType);
|
|
14
|
+
* visitor.visit();
|
|
15
|
+
* const result = visitor.getValidationResult();
|
|
16
|
+
* if (result.errors.length > 0) {
|
|
17
|
+
* console.error('Validation failed:', result.errors);
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class SelectionSetValidationVisitor {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new SelectionSetValidationVisitor.
|
|
24
|
+
*
|
|
25
|
+
* @param operationDocument - The parsed GraphQL document representing the field set
|
|
26
|
+
* @param objectType - The root GraphQL object type to validate against
|
|
27
|
+
*/
|
|
28
|
+
constructor(operationDocument, objectType) {
|
|
29
|
+
this.ancestors = [];
|
|
30
|
+
this.validationResult = {
|
|
31
|
+
errors: [],
|
|
32
|
+
warnings: [],
|
|
33
|
+
};
|
|
34
|
+
this.operationDocument = operationDocument;
|
|
35
|
+
this.currentType = objectType;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Executes the validation by traversing the operation document.
|
|
39
|
+
* After calling this method, use `getValidationResult()` to retrieve any errors or warnings.
|
|
40
|
+
*/
|
|
41
|
+
visit() {
|
|
42
|
+
visit(this.operationDocument, this.createASTVisitor());
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns the validation result containing any errors and warnings found during traversal.
|
|
46
|
+
*
|
|
47
|
+
* @returns The validation result with errors and warnings arrays
|
|
48
|
+
*/
|
|
49
|
+
getValidationResult() {
|
|
50
|
+
return this.validationResult;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates the AST visitor configuration for traversing the document.
|
|
54
|
+
*
|
|
55
|
+
* @returns An ASTVisitor object with handlers for Field and SelectionSet nodes
|
|
56
|
+
*/
|
|
57
|
+
createASTVisitor() {
|
|
58
|
+
return {
|
|
59
|
+
Field: {
|
|
60
|
+
enter: (node, key, parent, path, ancestors) => {
|
|
61
|
+
return this.onEnterField({ node, key, parent, path, ancestors });
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
SelectionSet: {
|
|
65
|
+
enter: (node, key, parent, path, ancestors) => {
|
|
66
|
+
return this.onEnterSelectionSet({ node, key, parent, path, ancestors });
|
|
67
|
+
},
|
|
68
|
+
leave: (node, key, parent, path, ancestors) => {
|
|
69
|
+
this.onLeaveSelectionSet({ node, key, parent, path, ancestors });
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Handles entering a field node during traversal.
|
|
76
|
+
* Validates that the field's type is not an abstract type (interface or union).
|
|
77
|
+
*
|
|
78
|
+
* @param ctx - The visit context containing the field node and its ancestors
|
|
79
|
+
* @returns BREAK if validation fails to stop traversal, undefined otherwise
|
|
80
|
+
*/
|
|
81
|
+
onEnterField(ctx) {
|
|
82
|
+
const fieldDefinition = this.getFieldDefinition(ctx.node);
|
|
83
|
+
if (!fieldDefinition) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const namedType = this.getUnderlyingType(fieldDefinition.type);
|
|
87
|
+
if (this.isAbstractType(namedType)) {
|
|
88
|
+
this.validationResult.errors.push(`Abstract types are not allowed in requires directives. Found ${namedType.name} in ${this.currentType.name}.${ctx.node.name.value}`);
|
|
89
|
+
return BREAK;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Unwraps a GraphQL type to get its underlying named type.
|
|
94
|
+
* Strips NonNull and List wrappers to get the base type.
|
|
95
|
+
*
|
|
96
|
+
* @param type - The GraphQL type to unwrap
|
|
97
|
+
* @returns The underlying named type
|
|
98
|
+
*/
|
|
99
|
+
getUnderlyingType(type) {
|
|
100
|
+
while (!isNamedType(type)) {
|
|
101
|
+
type = type.ofType;
|
|
102
|
+
}
|
|
103
|
+
return type;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the field definition for a field node from the current type.
|
|
107
|
+
* If the field is not found, a validation error is recorded and null is returned.
|
|
108
|
+
*
|
|
109
|
+
* @param node - The field node to look up
|
|
110
|
+
* @returns The GraphQL field definition, or null if not found
|
|
111
|
+
*/
|
|
112
|
+
getFieldDefinition(node) {
|
|
113
|
+
const fieldDef = this.currentType.getFields()[node.name.value];
|
|
114
|
+
if (!fieldDef) {
|
|
115
|
+
this.validationResult.errors.push(`Field '${node.name.value}' not found on type '${this.currentType.name}'`);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return fieldDef;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Handles entering a selection set node during traversal.
|
|
122
|
+
* Validates that inline fragments are not used and updates the current type
|
|
123
|
+
* context when descending into nested object types.
|
|
124
|
+
*
|
|
125
|
+
* @param ctx - The visit context containing the selection set node and its parent
|
|
126
|
+
* @returns BREAK if validation fails to stop traversal, undefined otherwise
|
|
127
|
+
*/
|
|
128
|
+
onEnterSelectionSet(ctx) {
|
|
129
|
+
if (!ctx.parent) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (this.isInlineFragment(ctx.parent)) {
|
|
133
|
+
this.validationResult.errors.push('Inline fragments are not allowed in requires directives');
|
|
134
|
+
return BREAK;
|
|
135
|
+
}
|
|
136
|
+
if (!this.isFieldNode(ctx.parent)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const fieldDefinition = this.getFieldDefinition(ctx.parent);
|
|
140
|
+
if (!fieldDefinition) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const namedType = this.getUnderlyingType(fieldDefinition.type);
|
|
144
|
+
if (isObjectType(namedType)) {
|
|
145
|
+
this.ancestors.push(this.currentType);
|
|
146
|
+
this.currentType = namedType;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Handles leaving a selection set node during traversal.
|
|
151
|
+
* Restores the previous type context when ascending back up the tree.
|
|
152
|
+
*
|
|
153
|
+
* @param ctx - The visit context containing the selection set node and its parent
|
|
154
|
+
*/
|
|
155
|
+
onLeaveSelectionSet(ctx) {
|
|
156
|
+
var _a;
|
|
157
|
+
if (!ctx.parent) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!this.isFieldNode(ctx.parent)) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
this.currentType = (_a = this.ancestors.pop()) !== null && _a !== void 0 ? _a : this.currentType;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Type guard to check if a node is an InlineFragmentNode.
|
|
167
|
+
*
|
|
168
|
+
* @param node - The AST node or array of nodes to check
|
|
169
|
+
* @returns True if the node is an InlineFragmentNode
|
|
170
|
+
*/
|
|
171
|
+
isInlineFragment(node) {
|
|
172
|
+
if (Array.isArray(node)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return node.kind === Kind.INLINE_FRAGMENT;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Type guard to check if a node is a FieldNode.
|
|
179
|
+
*
|
|
180
|
+
* @param node - The AST node or array of nodes to check
|
|
181
|
+
* @returns True if the node is a FieldNode
|
|
182
|
+
*/
|
|
183
|
+
isFieldNode(node) {
|
|
184
|
+
if (Array.isArray(node)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return node.kind === Kind.FIELD;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Checks if a named type is an abstract type (interface or union).
|
|
191
|
+
*
|
|
192
|
+
* @param node - The GraphQL named type to check
|
|
193
|
+
* @returns True if the type is an interface or union type
|
|
194
|
+
*/
|
|
195
|
+
isAbstractType(node) {
|
|
196
|
+
return isInterfaceType(node) || isUnionType(node);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=selection-set-validation-visitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-set-validation-visitor.js","sourceRoot":"","sources":["../../src/selection-set-validation-visitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,EAQL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,WAAW,EACX,IAAI,EAEJ,KAAK,GACN,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,6BAA6B;IAUxC;;;;;OAKG;IACH,YAAY,iBAA+B,EAAE,UAA6B;QAdlE,cAAS,GAAwB,EAAE,CAAC;QAGpC,qBAAgB,GAAqB;YAC3C,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACb,CAAC;QASA,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,KAAK;QACV,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;;;OAIG;IACI,mBAAmB;QACxB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACK,gBAAgB;QACtB,OAAO;YACL,KAAK,EAAE;gBACL,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;oBAC5C,OAAO,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;gBACnE,CAAC;aACF;YACD,YAAY,EAAE;gBACZ,KAAK,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;oBAC5C,OAAO,IAAI,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;gBAC1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,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,mCAAI,IAAI,CAAC,WAAW,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACK,gBAAgB,CAAC,IAAkC;QACzD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAQ,IAAgB,CAAC,IAAI,KAAK,IAAI,CAAC,eAAe,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACK,WAAW,CAAC,IAAsC;QACxD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAQ,IAAgB,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,IAAsB;QAC3C,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export declare const KEY_DIRECTIVE_NAME = "key";
|
|
2
|
+
export declare const EXTERNAL_DIRECTIVE_NAME = "external";
|
|
3
|
+
export declare const REQUIRES_DIRECTIVE_NAME = "requires";
|
|
4
|
+
export declare const FIELDS = "fields";
|
|
1
5
|
export declare const CONNECT_FIELD_RESOLVER = "connect__fieldResolver";
|
|
2
6
|
export declare const CONTEXT = "context";
|
|
3
7
|
export declare const FIELD_ARGS = "field_args";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export const KEY_DIRECTIVE_NAME = 'key';
|
|
2
|
+
export const EXTERNAL_DIRECTIVE_NAME = 'external';
|
|
3
|
+
export const REQUIRES_DIRECTIVE_NAME = 'requires';
|
|
4
|
+
export const FIELDS = 'fields';
|
|
1
5
|
export const CONNECT_FIELD_RESOLVER = 'connect__fieldResolver';
|
|
2
6
|
export const CONTEXT = 'context';
|
|
3
7
|
export const FIELD_ARGS = 'field_args';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-constants.js","sourceRoot":"","sources":["../../src/string-constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"string-constants.js","sourceRoot":"","sources":["../../src/string-constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACxC,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AAClD,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AAClD,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;AAC/B,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAC/D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
import { ASTNode, GraphQLNamedType } from 'graphql';
|
|
1
2
|
import protobuf from 'protobufjs';
|
|
3
|
+
export type VisitContext<T extends ASTNode> = {
|
|
4
|
+
node: T;
|
|
5
|
+
key: string | number | undefined;
|
|
6
|
+
parent: ASTNode | ReadonlyArray<ASTNode> | undefined;
|
|
7
|
+
path: ReadonlyArray<string | number>;
|
|
8
|
+
ancestors: ReadonlyArray<ASTNode | ReadonlyArray<ASTNode>>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Maps GraphQL scalar types to Protocol Buffer types
|
|
12
|
+
*
|
|
13
|
+
* GraphQL has a smaller set of primitive types compared to Protocol Buffers.
|
|
14
|
+
* This mapping ensures consistent representation between the two type systems.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SCALAR_TYPE_MAP: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Maps GraphQL scalar types to Protocol Buffer wrapper types for nullable fields
|
|
19
|
+
*
|
|
20
|
+
* These wrapper types allow distinguishing between unset fields and zero values
|
|
21
|
+
* in Protocol Buffers, which is important for GraphQL nullable semantics.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SCALAR_WRAPPER_TYPE_MAP: Record<string, string>;
|
|
2
24
|
/**
|
|
3
25
|
* Protocol Buffer idempotency levels for RPC methods
|
|
4
26
|
* @see https://protobuf.dev/reference/protobuf/google.protobuf/#idempotency-level
|
|
@@ -10,3 +32,83 @@ export type IdempotencyLevel = 'NO_SIDE_EFFECTS' | 'DEFAULT';
|
|
|
10
32
|
export interface MethodWithIdempotency extends protobuf.Method {
|
|
11
33
|
idempotencyLevel?: IdempotencyLevel;
|
|
12
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Represents a gRPC method definition
|
|
37
|
+
*
|
|
38
|
+
* example: rpc GetUser(GetUserRequest) returns (GetUserResponse) {}
|
|
39
|
+
*/
|
|
40
|
+
export type RPCMethod = {
|
|
41
|
+
name: string;
|
|
42
|
+
request: string;
|
|
43
|
+
response: string;
|
|
44
|
+
description?: string | null;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Represents a field in a proto message
|
|
48
|
+
*/
|
|
49
|
+
export interface ProtoMessageField {
|
|
50
|
+
fieldName: string;
|
|
51
|
+
typeName: string;
|
|
52
|
+
fieldNumber: number;
|
|
53
|
+
isRepeated?: boolean;
|
|
54
|
+
description?: string;
|
|
55
|
+
graphqlName?: string;
|
|
56
|
+
/**
|
|
57
|
+
* The composite type of the field. When building a proto message
|
|
58
|
+
* this is used to create the composite type messages as nested messages.
|
|
59
|
+
*/
|
|
60
|
+
compositeType?: CompositeMessageDefinition;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Represents a proto message
|
|
64
|
+
*/
|
|
65
|
+
export interface ProtoMessage {
|
|
66
|
+
messageName: string;
|
|
67
|
+
reservedNumbers?: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
fields: ProtoMessageField[];
|
|
70
|
+
/**
|
|
71
|
+
* Nested messages within this message (if any)
|
|
72
|
+
* Example: message User {
|
|
73
|
+
* message Address {
|
|
74
|
+
* string street = 1;
|
|
75
|
+
* string city = 2;
|
|
76
|
+
* string state = 3;
|
|
77
|
+
* string zip = 4;
|
|
78
|
+
* }
|
|
79
|
+
* Address address = 1;
|
|
80
|
+
*/
|
|
81
|
+
nestedMessages?: ProtoMessage[];
|
|
82
|
+
}
|
|
83
|
+
export interface ListWrapper {
|
|
84
|
+
baseType: GraphQLNamedType;
|
|
85
|
+
nestingLevel: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Data structure for formatting message fields
|
|
89
|
+
*/
|
|
90
|
+
export type ProtoFieldType = {
|
|
91
|
+
typeName: string;
|
|
92
|
+
isWrapper: boolean;
|
|
93
|
+
isRepeated: boolean;
|
|
94
|
+
listWrapper?: ListWrapper;
|
|
95
|
+
};
|
|
96
|
+
export declare enum CompositeMessageKind {
|
|
97
|
+
INTERFACE = 0,
|
|
98
|
+
UNION = 1
|
|
99
|
+
}
|
|
100
|
+
export type CompositeMessageDefinition = InterfaceMessageDefinition | UnionMessageDefinition;
|
|
101
|
+
export type InterfaceMessageDefinition = {
|
|
102
|
+
kind: CompositeMessageKind.INTERFACE;
|
|
103
|
+
description?: string;
|
|
104
|
+
typeName: string;
|
|
105
|
+
implementingTypes: string[];
|
|
106
|
+
};
|
|
107
|
+
export type UnionMessageDefinition = {
|
|
108
|
+
kind: CompositeMessageKind.UNION;
|
|
109
|
+
description?: string;
|
|
110
|
+
typeName: string;
|
|
111
|
+
memberTypes: string[];
|
|
112
|
+
};
|
|
113
|
+
export declare function isInterfaceMessageDefinition(message: CompositeMessageDefinition): message is InterfaceMessageDefinition;
|
|
114
|
+
export declare function isUnionMessageDefinition(message: CompositeMessageDefinition): message is UnionMessageDefinition;
|
package/dist/src/types.js
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Maps GraphQL scalar types to Protocol Buffer types
|
|
3
|
+
*
|
|
4
|
+
* GraphQL has a smaller set of primitive types compared to Protocol Buffers.
|
|
5
|
+
* This mapping ensures consistent representation between the two type systems.
|
|
6
|
+
*/
|
|
7
|
+
export const SCALAR_TYPE_MAP = {
|
|
8
|
+
ID: 'string', // GraphQL IDs map to Proto strings
|
|
9
|
+
String: 'string', // Direct mapping
|
|
10
|
+
Int: 'int32', // GraphQL Int is 32-bit signed
|
|
11
|
+
Float: 'double', // Using double for GraphQL Float gives better precision
|
|
12
|
+
Boolean: 'bool', // Direct mapping
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Maps GraphQL scalar types to Protocol Buffer wrapper types for nullable fields
|
|
16
|
+
*
|
|
17
|
+
* These wrapper types allow distinguishing between unset fields and zero values
|
|
18
|
+
* in Protocol Buffers, which is important for GraphQL nullable semantics.
|
|
19
|
+
*/
|
|
20
|
+
export const SCALAR_WRAPPER_TYPE_MAP = {
|
|
21
|
+
ID: 'google.protobuf.StringValue',
|
|
22
|
+
String: 'google.protobuf.StringValue',
|
|
23
|
+
Int: 'google.protobuf.Int32Value',
|
|
24
|
+
Float: 'google.protobuf.DoubleValue',
|
|
25
|
+
Boolean: 'google.protobuf.BoolValue',
|
|
26
|
+
};
|
|
27
|
+
export var CompositeMessageKind;
|
|
28
|
+
(function (CompositeMessageKind) {
|
|
29
|
+
CompositeMessageKind[CompositeMessageKind["INTERFACE"] = 0] = "INTERFACE";
|
|
30
|
+
CompositeMessageKind[CompositeMessageKind["UNION"] = 1] = "UNION";
|
|
31
|
+
})(CompositeMessageKind || (CompositeMessageKind = {}));
|
|
32
|
+
export function isInterfaceMessageDefinition(message) {
|
|
33
|
+
return message.kind === CompositeMessageKind.INTERFACE;
|
|
34
|
+
}
|
|
35
|
+
export function isUnionMessageDefinition(message) {
|
|
36
|
+
return message.kind === CompositeMessageKind.UNION;
|
|
37
|
+
}
|
|
2
38
|
//# sourceMappingURL=types.js.map
|
package/dist/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD,EAAE,EAAE,QAAQ,EAAE,mCAAmC;IACjD,MAAM,EAAE,QAAQ,EAAE,iBAAiB;IACnC,GAAG,EAAE,OAAO,EAAE,+BAA+B;IAC7C,KAAK,EAAE,QAAQ,EAAE,wDAAwD;IACzE,OAAO,EAAE,MAAM,EAAE,iBAAiB;CACnC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA2B;IAC7D,EAAE,EAAE,6BAA6B;IACjC,MAAM,EAAE,6BAA6B;IACrC,GAAG,EAAE,4BAA4B;IACjC,KAAK,EAAE,6BAA6B;IACpC,OAAO,EAAE,2BAA2B;CACrC,CAAC;AAoFF,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,yEAAS,CAAA;IACT,iEAAK,CAAA;AACP,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAkBD,MAAM,UAAU,4BAA4B,CAC1C,OAAmC;IAEnC,OAAO,OAAO,CAAC,IAAI,KAAK,oBAAoB,CAAC,SAAS,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAmC;IAC1E,OAAO,OAAO,CAAC,IAAI,KAAK,oBAAoB,CAAC,KAAK,CAAC;AACrD,CAAC"}
|