@wundergraph/protographic 0.7.1 → 0.8.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/index.d.ts +11 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/naming-conventions.d.ts +1 -9
- package/dist/src/naming-conventions.js +8 -14
- package/dist/src/naming-conventions.js.map +1 -1
- package/dist/src/sdl-to-mapping-visitor.d.ts +7 -7
- package/dist/src/sdl-to-mapping-visitor.js +24 -20
- package/dist/src/sdl-to-mapping-visitor.js.map +1 -1
- package/dist/src/sdl-to-proto-visitor.d.ts +8 -1
- package/dist/src/sdl-to-proto-visitor.js +60 -36
- package/dist/src/sdl-to-proto-visitor.js.map +1 -1
- package/dist/src/sdl-validation-visitor.d.ts +155 -0
- package/dist/src/sdl-validation-visitor.js +299 -0
- package/dist/src/sdl-validation-visitor.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { GraphQLSchema } from 'graphql';
|
|
|
2
2
|
import { GRPCMapping } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
|
|
3
3
|
import type { GraphQLToProtoTextVisitorOptions } from './sdl-to-proto-visitor.js';
|
|
4
4
|
import type { ProtoLock } from './proto-lock.js';
|
|
5
|
+
import { type ValidationResult } from './sdl-validation-visitor.js';
|
|
5
6
|
/**
|
|
6
7
|
* Compiles a GraphQL schema to a mapping structure
|
|
7
8
|
*
|
|
@@ -29,9 +30,19 @@ export interface CompileGraphQLToProtoResult {
|
|
|
29
30
|
* @returns Protocol Buffer text definition and lock data
|
|
30
31
|
*/
|
|
31
32
|
export declare function compileGraphQLToProto(schemaOrSDL: GraphQLSchema | string, options?: GraphQLToProtoTextVisitorOptions): CompileGraphQLToProtoResult;
|
|
33
|
+
/**
|
|
34
|
+
* Validates a GraphQL SDL schema against specific rules and constraints
|
|
35
|
+
*
|
|
36
|
+
* @param sdl - The GraphQL SDL string to validate
|
|
37
|
+
* @returns ValidationResult containing any errors and warnings found during validation
|
|
38
|
+
* @throws Error if the SDL cannot be parsed as valid GraphQL
|
|
39
|
+
*/
|
|
40
|
+
export declare function validateGraphQLSDL(sdl: string): ValidationResult;
|
|
32
41
|
export * from './sdl-to-mapping-visitor.js';
|
|
33
42
|
export { GraphQLToProtoTextVisitor } from './sdl-to-proto-visitor.js';
|
|
34
43
|
export { ProtoLockManager } from './proto-lock.js';
|
|
44
|
+
export { SDLValidationVisitor } from './sdl-validation-visitor.js';
|
|
35
45
|
export type { GraphQLToProtoTextVisitorOptions } from './sdl-to-proto-visitor.js';
|
|
36
46
|
export type { ProtoLock } from './proto-lock.js';
|
|
47
|
+
export type { ValidationResult } from './sdl-validation-visitor.js';
|
|
37
48
|
export { GRPCMapping, OperationMapping, EntityMapping, TypeFieldMapping, FieldMapping, ArgumentMapping, EnumMapping, EnumValueMapping, OperationType, } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
|
package/dist/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { buildSchema } from 'graphql';
|
|
2
2
|
import { GraphQLToProtoVisitor } from './sdl-to-mapping-visitor.js';
|
|
3
3
|
import { GraphQLToProtoTextVisitor } from './sdl-to-proto-visitor.js';
|
|
4
|
+
import { SDLValidationVisitor } from './sdl-validation-visitor.js';
|
|
4
5
|
/**
|
|
5
6
|
* Compiles a GraphQL schema to a mapping structure
|
|
6
7
|
*
|
|
@@ -46,8 +47,20 @@ export function compileGraphQLToProto(schemaOrSDL, options) {
|
|
|
46
47
|
lockData: generatedLockData,
|
|
47
48
|
};
|
|
48
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates a GraphQL SDL schema against specific rules and constraints
|
|
52
|
+
*
|
|
53
|
+
* @param sdl - The GraphQL SDL string to validate
|
|
54
|
+
* @returns ValidationResult containing any errors and warnings found during validation
|
|
55
|
+
* @throws Error if the SDL cannot be parsed as valid GraphQL
|
|
56
|
+
*/
|
|
57
|
+
export function validateGraphQLSDL(sdl) {
|
|
58
|
+
const visitor = new SDLValidationVisitor(sdl);
|
|
59
|
+
return visitor.visit();
|
|
60
|
+
}
|
|
49
61
|
export * from './sdl-to-mapping-visitor.js';
|
|
50
62
|
export { GraphQLToProtoTextVisitor } from './sdl-to-proto-visitor.js';
|
|
51
63
|
export { ProtoLockManager } from './proto-lock.js';
|
|
64
|
+
export { SDLValidationVisitor } from './sdl-validation-visitor.js';
|
|
52
65
|
export { GRPCMapping, OperationMapping, EntityMapping, TypeFieldMapping, FieldMapping, ArgumentMapping, EnumMapping, EnumValueMapping, OperationType, } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
|
|
53
66
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAyB,MAAM,6BAA6B,CAAC;AAE1F;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,WAAmC,EACnC,cAAsB,gBAAgB;IAEtC,6CAA6C;IAC7C,MAAM,MAAM,GACV,OAAO,WAAW,KAAK,QAAQ;QAC7B,CAAC,CAAC,WAAW,CAAC,W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AA6B,CAAC;AAKnE,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,aAAa,GACd,MAAM,iDAAiD,CAAC"}
|
|
@@ -31,15 +31,7 @@ export declare function createResponseMessageName(methodName: string): string;
|
|
|
31
31
|
/**
|
|
32
32
|
* Creates an entity lookup method name for an entity type
|
|
33
33
|
*/
|
|
34
|
-
export declare function createEntityLookupMethodName(typeName: string,
|
|
35
|
-
/**
|
|
36
|
-
* Creates a request message name for an entity lookup
|
|
37
|
-
*/
|
|
38
|
-
export declare function createEntityLookupRequestName(typeName: string, keyField?: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a response message name for an entity lookup
|
|
41
|
-
*/
|
|
42
|
-
export declare function createEntityLookupResponseName(typeName: string, keyField?: string): string;
|
|
34
|
+
export declare function createEntityLookupMethodName(typeName: string, keyString?: string): string;
|
|
43
35
|
/**
|
|
44
36
|
* Converts a GraphQL enum value to a Protocol Buffer enum value
|
|
45
37
|
*/
|
|
@@ -32,20 +32,14 @@ export function createResponseMessageName(methodName) {
|
|
|
32
32
|
/**
|
|
33
33
|
* Creates an entity lookup method name for an entity type
|
|
34
34
|
*/
|
|
35
|
-
export function createEntityLookupMethodName(typeName,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return `Lookup${typeName}By${
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates a response message name for an entity lookup
|
|
46
|
-
*/
|
|
47
|
-
export function createEntityLookupResponseName(typeName, keyField = 'id') {
|
|
48
|
-
return `Lookup${typeName}By${upperFirst(camelCase(keyField))}Response`;
|
|
35
|
+
export function createEntityLookupMethodName(typeName, keyString = 'id') {
|
|
36
|
+
const normalizedKey = keyString
|
|
37
|
+
.split(/[,\s]+/)
|
|
38
|
+
.filter((field) => field.length > 0)
|
|
39
|
+
.map((field) => upperFirst(camelCase(field)))
|
|
40
|
+
.sort()
|
|
41
|
+
.join('And');
|
|
42
|
+
return `Lookup${typeName}By${normalizedKey}`;
|
|
49
43
|
}
|
|
50
44
|
/**
|
|
51
45
|
* Converts a GraphQL enum value to a Protocol Buffer enum value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"naming-conventions.js","sourceRoot":"","sources":["../../src/naming-conventions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAc7D;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAiB;IACxD,OAAO,SAAS,CAAC,SAAS,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAe;IACzD,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,aAAgC,EAAE,SAAiB;IAC3F,OAAO,GAAG,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IACzD,OAAO,GAAG,UAAU,SAAS,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,OAAO,GAAG,UAAU,UAAU,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAAC,QAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"naming-conventions.js","sourceRoot":"","sources":["../../src/naming-conventions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAc7D;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,SAAiB;IACxD,OAAO,SAAS,CAAC,SAAS,CAAC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 @@ export declare class GraphQLToProtoVisitor {
|
|
|
41
41
|
*/
|
|
42
42
|
private processEntityTypes;
|
|
43
43
|
/**
|
|
44
|
-
* Extract
|
|
44
|
+
* Extract all key directives from a GraphQL object type
|
|
45
45
|
*
|
|
46
|
-
* @param type - The GraphQL object type to check for key
|
|
47
|
-
* @returns
|
|
46
|
+
* @param type - The GraphQL object type to check for key directives
|
|
47
|
+
* @returns Array of all key directives found
|
|
48
48
|
*/
|
|
49
|
-
private
|
|
49
|
+
private getKeyDirectives;
|
|
50
50
|
/**
|
|
51
51
|
* Creates an entity mapping for a federated entity type
|
|
52
52
|
*
|
|
@@ -61,12 +61,12 @@ export declare class GraphQLToProtoVisitor {
|
|
|
61
61
|
* Extract key fields from a @key directive
|
|
62
62
|
*
|
|
63
63
|
* The @key directive specifies which fields form the entity's primary key
|
|
64
|
-
* in Federation. This method extracts
|
|
64
|
+
* in Federation. This method extracts the key string as-is.
|
|
65
65
|
*
|
|
66
66
|
* @param directive - The @key directive from the GraphQL AST
|
|
67
|
-
* @returns
|
|
67
|
+
* @returns The key string (e.g. "id" or "id upc")
|
|
68
68
|
*/
|
|
69
|
-
private
|
|
69
|
+
private getKeyFromDirective;
|
|
70
70
|
/**
|
|
71
71
|
* Process the GraphQL Query type to generate query operation mappings
|
|
72
72
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isEnumType, isInputObjectType, isObjectType, Kind, } from 'graphql';
|
|
2
|
-
import { createEntityLookupMethodName,
|
|
2
|
+
import { createEntityLookupMethodName, createOperationMethodName, createRequestMessageName, createResponseMessageName, graphqlArgumentToProtoField, graphqlEnumValueToProtoEnumValue, graphqlFieldToProtoField, } from './naming-conventions.js';
|
|
3
3
|
import { ArgumentMapping, EntityMapping, EnumMapping, EnumValueMapping, FieldMapping, GRPCMapping, OperationMapping, OperationType, TypeFieldMapping, } from '@wundergraph/cosmo-connect/dist/node/v1/node_pb';
|
|
4
4
|
/**
|
|
5
5
|
* Visitor that converts a GraphQL schema to gRPC mapping definitions
|
|
@@ -69,26 +69,29 @@ export class GraphQLToProtoVisitor {
|
|
|
69
69
|
continue;
|
|
70
70
|
// Check if this is an entity type (has @key directive)
|
|
71
71
|
if (isObjectType(type)) {
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
72
|
+
const keyDirectives = this.getKeyDirectives(type);
|
|
73
|
+
if (keyDirectives.length === 0)
|
|
74
74
|
continue;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
// Process each @key directive separately
|
|
76
|
+
for (const keyDirective of keyDirectives) {
|
|
77
|
+
const key = this.getKeyFromDirective(keyDirective);
|
|
78
|
+
if (key) {
|
|
79
|
+
// Create entity mapping for each key combination
|
|
80
|
+
this.createEntityMapping(typeName, key);
|
|
81
|
+
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
|
-
* Extract
|
|
87
|
+
* Extract all key directives from a GraphQL object type
|
|
85
88
|
*
|
|
86
|
-
* @param type - The GraphQL object type to check for key
|
|
87
|
-
* @returns
|
|
89
|
+
* @param type - The GraphQL object type to check for key directives
|
|
90
|
+
* @returns Array of all key directives found
|
|
88
91
|
*/
|
|
89
|
-
|
|
92
|
+
getKeyDirectives(type) {
|
|
90
93
|
var _a, _b;
|
|
91
|
-
return (_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.
|
|
94
|
+
return ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.filter((d) => d.name.value === 'key')) || [];
|
|
92
95
|
}
|
|
93
96
|
/**
|
|
94
97
|
* Creates an entity mapping for a federated entity type
|
|
@@ -100,13 +103,14 @@ export class GraphQLToProtoVisitor {
|
|
|
100
103
|
* @param keyField - The field that serves as the entity's key
|
|
101
104
|
*/
|
|
102
105
|
createEntityMapping(typeName, keyField) {
|
|
106
|
+
const rpc = createEntityLookupMethodName(typeName, keyField);
|
|
103
107
|
const entityMapping = new EntityMapping({
|
|
104
108
|
typeName,
|
|
105
109
|
kind: 'entity',
|
|
106
110
|
key: keyField,
|
|
107
|
-
rpc:
|
|
108
|
-
request:
|
|
109
|
-
response:
|
|
111
|
+
rpc: rpc,
|
|
112
|
+
request: createRequestMessageName(rpc),
|
|
113
|
+
response: createResponseMessageName(rpc),
|
|
110
114
|
});
|
|
111
115
|
this.mapping.entityMappings.push(entityMapping);
|
|
112
116
|
}
|
|
@@ -114,19 +118,19 @@ export class GraphQLToProtoVisitor {
|
|
|
114
118
|
* Extract key fields from a @key directive
|
|
115
119
|
*
|
|
116
120
|
* The @key directive specifies which fields form the entity's primary key
|
|
117
|
-
* in Federation. This method extracts
|
|
121
|
+
* in Federation. This method extracts the key string as-is.
|
|
118
122
|
*
|
|
119
123
|
* @param directive - The @key directive from the GraphQL AST
|
|
120
|
-
* @returns
|
|
124
|
+
* @returns The key string (e.g. "id" or "id upc")
|
|
121
125
|
*/
|
|
122
|
-
|
|
126
|
+
getKeyFromDirective(directive) {
|
|
123
127
|
var _a;
|
|
124
128
|
// Extract fields argument from the key directive
|
|
125
129
|
const fieldsArg = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find((arg) => arg.name.value === 'fields');
|
|
126
130
|
if (fieldsArg && fieldsArg.value.kind === Kind.STRING) {
|
|
127
|
-
return fieldsArg.value.value
|
|
131
|
+
return fieldsArg.value.value;
|
|
128
132
|
}
|
|
129
|
-
return
|
|
133
|
+
return null;
|
|
130
134
|
}
|
|
131
135
|
/**
|
|
132
136
|
* Process the GraphQL Query type to generate query operation mappings
|
|
@@ -1 +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,
|
|
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,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,YAAY,MAAqB,EAAE,cAAsB,gBAAgB;QACvE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC;YAC7B,OAAO,EAAE,CAAC;YACV,OAAO,EAAE,WAAW;YACpB,iBAAiB,EAAE,EAAE;YACrB,cAAc,EAAE,EAAE;YAClB,iBAAiB,EAAE,EAAE;YACrB,YAAY,EAAE,EAAE;SACjB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK;QACV,yDAAyD;QACzD,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAE1B,qBAAqB;QACrB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAExB,wBAAwB;QACxB,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAE3B,4BAA4B;QAC5B,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAE/B,6CAA6C;QAC7C,IAAI,CAAC,eAAe,EAAE,CAAC;QAEvB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;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,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"}
|
|
@@ -178,6 +178,13 @@ export declare class GraphQLToProtoTextVisitor {
|
|
|
178
178
|
* Creates a response message for a query/mutation field
|
|
179
179
|
*/
|
|
180
180
|
private createFieldResponseMessage;
|
|
181
|
+
/**
|
|
182
|
+
* Extract all key directives from a GraphQL object type
|
|
183
|
+
*
|
|
184
|
+
* @param type - The GraphQL object type to check for key directives
|
|
185
|
+
* @returns Array of all key directives found
|
|
186
|
+
*/
|
|
187
|
+
private getKeyDirectives;
|
|
181
188
|
/**
|
|
182
189
|
* Extract key fields from a directive
|
|
183
190
|
*
|
|
@@ -187,7 +194,7 @@ export declare class GraphQLToProtoTextVisitor {
|
|
|
187
194
|
* @param directive - The @key directive from the GraphQL AST
|
|
188
195
|
* @returns Array of field names that form the key
|
|
189
196
|
*/
|
|
190
|
-
private
|
|
197
|
+
private getKeyFromDirective;
|
|
191
198
|
/**
|
|
192
199
|
* Queue all types from the schema that need processing
|
|
193
200
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getNamedType, isEnumType, isInputObjectType, isInterfaceType, isListType, isNonNullType, isObjectType, isScalarType, isUnionType, } from 'graphql';
|
|
2
|
-
import { createEntityLookupMethodName,
|
|
2
|
+
import { createEntityLookupMethodName, createEnumUnspecifiedValue, createOperationMethodName, createRequestMessageName, createResponseMessageName, graphqlEnumValueToProtoEnumValue, graphqlFieldToProtoField, } from './naming-conventions.js';
|
|
3
3
|
import { camelCase } from 'lodash-es';
|
|
4
4
|
import { ProtoLockManager } from './proto-lock.js';
|
|
5
5
|
/**
|
|
@@ -381,7 +381,7 @@ export class GraphQLToProtoTextVisitor {
|
|
|
381
381
|
* @returns Object containing RPC methods and message definitions
|
|
382
382
|
*/
|
|
383
383
|
collectEntityRpcMethods() {
|
|
384
|
-
var _a, _b, _c
|
|
384
|
+
var _a, _b, _c;
|
|
385
385
|
const result = { rpcMethods: [], methodNames: [], messageDefinitions: [] };
|
|
386
386
|
const typeMap = this.schema.getTypeMap();
|
|
387
387
|
for (const typeName in typeMap) {
|
|
@@ -395,23 +395,36 @@ export class GraphQLToProtoTextVisitor {
|
|
|
395
395
|
}
|
|
396
396
|
// Check if this is an entity type (has @key directive)
|
|
397
397
|
if (isObjectType(type)) {
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
// Queue this type for message generation
|
|
398
|
+
const keyDirectives = this.getKeyDirectives(type);
|
|
399
|
+
if (keyDirectives.length > 0) {
|
|
400
|
+
// Queue this type for message generation (only once)
|
|
402
401
|
this.queueTypeForProcessing(type);
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
402
|
+
// Normalize keys by sorting fields alphabetically and deduplicating
|
|
403
|
+
const normalizedKeysSet = new Set();
|
|
404
|
+
for (const keyDirective of keyDirectives) {
|
|
405
|
+
const keyString = this.getKeyFromDirective(keyDirective);
|
|
406
|
+
if (!keyString)
|
|
407
|
+
continue;
|
|
408
|
+
const normalizedKey = keyString
|
|
409
|
+
.split(/[,\s]+/)
|
|
410
|
+
.filter((field) => field.length > 0)
|
|
411
|
+
.sort()
|
|
412
|
+
.join(' ');
|
|
413
|
+
normalizedKeysSet.add(normalizedKey);
|
|
414
|
+
}
|
|
415
|
+
// Process each normalized key
|
|
416
|
+
for (const normalizedKeyString of normalizedKeysSet) {
|
|
417
|
+
const methodName = createEntityLookupMethodName(typeName, normalizedKeyString);
|
|
418
|
+
const requestName = createRequestMessageName(methodName);
|
|
419
|
+
const responseName = createResponseMessageName(methodName);
|
|
409
420
|
// Add method name and RPC method with description from the entity type
|
|
410
421
|
result.methodNames.push(methodName);
|
|
411
|
-
const
|
|
422
|
+
const keyFields = normalizedKeyString.split(' ');
|
|
423
|
+
const keyDescription = keyFields.length === 1 ? keyFields[0] : keyFields.join(' and ');
|
|
424
|
+
const description = `Lookup ${typeName} entity by ${keyDescription}${type.description ? ': ' + type.description : ''}`;
|
|
412
425
|
result.rpcMethods.push(this.createRpcMethod(methodName, requestName, responseName, description));
|
|
413
|
-
// Create request and response messages
|
|
414
|
-
result.messageDefinitions.push(...this.createKeyRequestMessage(typeName, requestName,
|
|
426
|
+
// Create request and response messages for this key combination
|
|
427
|
+
result.messageDefinitions.push(...this.createKeyRequestMessage(typeName, requestName, normalizedKeyString, responseName));
|
|
415
428
|
result.messageDefinitions.push(...this.createKeyResponseMessage(typeName, responseName, requestName));
|
|
416
429
|
}
|
|
417
430
|
}
|
|
@@ -507,7 +520,7 @@ export class GraphQLToProtoTextVisitor {
|
|
|
507
520
|
/**
|
|
508
521
|
* Creates a request message for entity lookup without adding to protoText
|
|
509
522
|
*/
|
|
510
|
-
createKeyRequestMessage(typeName, requestName,
|
|
523
|
+
createKeyRequestMessage(typeName, requestName, keyString, responseName) {
|
|
511
524
|
const messageLines = [];
|
|
512
525
|
const keyMessageName = `${requestName}Key`;
|
|
513
526
|
const lockData = this.lockManager.getLockData();
|
|
@@ -522,24 +535,30 @@ export class GraphQLToProtoTextVisitor {
|
|
|
522
535
|
if ((keyMessageLock === null || keyMessageLock === void 0 ? void 0 : keyMessageLock.reservedNumbers) && keyMessageLock.reservedNumbers.length > 0) {
|
|
523
536
|
messageLines.push(` reserved ${this.formatReservedNumbers(keyMessageLock.reservedNumbers)};`);
|
|
524
537
|
}
|
|
538
|
+
const keyFields = keyString.split(' ');
|
|
525
539
|
// Check for field removals in the key message
|
|
526
540
|
if (lockData.messages[keyMessageName]) {
|
|
527
541
|
const originalKeyFieldNames = Object.keys(lockData.messages[keyMessageName].fields);
|
|
528
|
-
const currentKeyFieldNames =
|
|
542
|
+
const currentKeyFieldNames = keyFields.map((field) => graphqlFieldToProtoField(field));
|
|
529
543
|
this.trackRemovedFields(keyMessageName, originalKeyFieldNames, currentKeyFieldNames);
|
|
530
544
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
545
|
+
// Add all key fields to the key message
|
|
546
|
+
const protoKeyFields = [];
|
|
547
|
+
keyFields.forEach((keyField, index) => {
|
|
548
|
+
const protoKeyField = graphqlFieldToProtoField(keyField);
|
|
549
|
+
protoKeyFields.push(protoKeyField);
|
|
550
|
+
// Get the appropriate field number for this key field
|
|
551
|
+
const keyFieldNumber = this.getFieldNumber(keyMessageName, protoKeyField, index + 1);
|
|
552
|
+
if (this.includeComments) {
|
|
553
|
+
const keyFieldComment = `Key field for ${typeName} entity lookup.`;
|
|
554
|
+
messageLines.push(...this.formatComment(keyFieldComment, 1)); // Field comment, indent 1 level
|
|
555
|
+
}
|
|
556
|
+
messageLines.push(` string ${protoKeyField} = ${keyFieldNumber};`);
|
|
557
|
+
});
|
|
539
558
|
messageLines.push('}');
|
|
540
559
|
messageLines.push('');
|
|
541
560
|
// Ensure the key message is registered in the lock manager data
|
|
542
|
-
this.lockManager.reconcileMessageFieldOrder(keyMessageName,
|
|
561
|
+
this.lockManager.reconcileMessageFieldOrder(keyMessageName, protoKeyFields);
|
|
543
562
|
// Now create the main request message with a repeated key field
|
|
544
563
|
// Check for field removals in the request message
|
|
545
564
|
if (lockData.messages[requestName]) {
|
|
@@ -623,15 +642,11 @@ Example:
|
|
|
623
642
|
* Creates a request message for a query/mutation field
|
|
624
643
|
*/
|
|
625
644
|
createFieldRequestMessage(requestName, field) {
|
|
626
|
-
var _a;
|
|
627
645
|
const messageLines = [];
|
|
628
646
|
// Get current field names and check for removals
|
|
629
647
|
const lockData = this.lockManager.getLockData();
|
|
630
648
|
const argNames = field.args.map((arg) => graphqlFieldToProtoField(arg.name));
|
|
631
|
-
|
|
632
|
-
const originalFieldNames = Object.keys(lockData.messages[requestName].fields);
|
|
633
|
-
this.trackRemovedFields(requestName, originalFieldNames, argNames);
|
|
634
|
-
}
|
|
649
|
+
this.lockManager.reconcileMessageFieldOrder(requestName, argNames);
|
|
635
650
|
// Add a description comment for the request message
|
|
636
651
|
if (this.includeComments) {
|
|
637
652
|
const description = field.description
|
|
@@ -658,8 +673,7 @@ Example:
|
|
|
658
673
|
continue;
|
|
659
674
|
const argType = this.getProtoTypeFromGraphQL(arg.type);
|
|
660
675
|
const argProtoName = graphqlFieldToProtoField(arg.name);
|
|
661
|
-
|
|
662
|
-
const fieldNumber = (_a = lockData.messages[operationName]) === null || _a === void 0 ? void 0 : _a.fields[argName];
|
|
676
|
+
const fieldNumber = this.getFieldNumber(requestName, argProtoName, this.getNextAvailableFieldNumber(requestName));
|
|
663
677
|
// Add argument description as comment
|
|
664
678
|
if (arg.description) {
|
|
665
679
|
// Use 1 level indent for field comments
|
|
@@ -731,6 +745,16 @@ Example:
|
|
|
731
745
|
this.lockManager.reconcileMessageFieldOrder(responseName, [protoFieldName]);
|
|
732
746
|
return messageLines;
|
|
733
747
|
}
|
|
748
|
+
/**
|
|
749
|
+
* Extract all key directives from a GraphQL object type
|
|
750
|
+
*
|
|
751
|
+
* @param type - The GraphQL object type to check for key directives
|
|
752
|
+
* @returns Array of all key directives found
|
|
753
|
+
*/
|
|
754
|
+
getKeyDirectives(type) {
|
|
755
|
+
var _a, _b;
|
|
756
|
+
return ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.directives) === null || _b === void 0 ? void 0 : _b.filter((d) => d.name.value === 'key')) || [];
|
|
757
|
+
}
|
|
734
758
|
/**
|
|
735
759
|
* Extract key fields from a directive
|
|
736
760
|
*
|
|
@@ -740,14 +764,14 @@ Example:
|
|
|
740
764
|
* @param directive - The @key directive from the GraphQL AST
|
|
741
765
|
* @returns Array of field names that form the key
|
|
742
766
|
*/
|
|
743
|
-
|
|
767
|
+
getKeyFromDirective(directive) {
|
|
744
768
|
var _a;
|
|
745
769
|
const fieldsArg = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find((arg) => arg.name.value === 'fields');
|
|
746
770
|
if (fieldsArg && fieldsArg.value.kind === 'StringValue') {
|
|
747
771
|
const stringValue = fieldsArg.value;
|
|
748
|
-
return stringValue.value
|
|
772
|
+
return stringValue.value;
|
|
749
773
|
}
|
|
750
|
-
return
|
|
774
|
+
return null;
|
|
751
775
|
}
|
|
752
776
|
/**
|
|
753
777
|
* Queue all types from the schema that need processing
|