Skip to content

Commit 70e28e8

Browse files
committed
feat: add support for field resolvers in protographic
1 parent 6f93d40 commit 70e28e8

File tree

11 files changed

+2636
-1477
lines changed

11 files changed

+2636
-1477
lines changed

connect-go/gen/proto/wg/cosmo/node/v1/node.pb.go

Lines changed: 898 additions & 630 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

connect/src/wg/cosmo/node/v1/node_pb.ts

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,40 @@ proto3.util.setEnumType(DataSourceKind, "wg.cosmo.node.v1.DataSourceKind", [
7979
{ no: 2, name: "PUBSUB" },
8080
]);
8181

82+
/**
83+
* Defines the type of lookup operation
84+
*
85+
* @generated from enum wg.cosmo.node.v1.LookupType
86+
*/
87+
export enum LookupType {
88+
/**
89+
* Unspecified lookup type
90+
*
91+
* @generated from enum value: LOOKUP_TYPE_UNSPECIFIED = 0;
92+
*/
93+
UNSPECIFIED = 0,
94+
95+
/**
96+
* Lookup type for field resolution
97+
*
98+
* @generated from enum value: LOOKUP_TYPE_RESOLVE = 1;
99+
*/
100+
RESOLVE = 1,
101+
102+
/**
103+
* Lookup type for the @requires directive
104+
*
105+
* @generated from enum value: LOOKUP_TYPE_REQUIRES = 2;
106+
*/
107+
REQUIRES = 2,
108+
}
109+
// Retrieve enum metadata with: proto3.getEnumType(LookupType)
110+
proto3.util.setEnumType(LookupType, "wg.cosmo.node.v1.LookupType", [
111+
{ no: 0, name: "LOOKUP_TYPE_UNSPECIFIED" },
112+
{ no: 1, name: "LOOKUP_TYPE_RESOLVE" },
113+
{ no: 2, name: "LOOKUP_TYPE_REQUIRES" },
114+
]);
115+
82116
/**
83117
* Defines the type of GraphQL operation
84118
*
@@ -1730,6 +1764,8 @@ export class SSLConfiguration extends Message<SSLConfiguration> {
17301764
}
17311765

17321766
/**
1767+
* Defines mapping for a gRPC service
1768+
*
17331769
* @generated from message wg.cosmo.node.v1.GRPCMapping
17341770
*/
17351771
export class GRPCMapping extends Message<GRPCMapping> {
@@ -1775,6 +1811,13 @@ export class GRPCMapping extends Message<GRPCMapping> {
17751811
*/
17761812
enumMappings: EnumMapping[] = [];
17771813

1814+
/**
1815+
* Mappings for GraphQL resolve operations to gRPC service methods
1816+
*
1817+
* @generated from field: repeated wg.cosmo.node.v1.LookupMapping resolve_mappings = 7;
1818+
*/
1819+
resolveMappings: LookupMapping[] = [];
1820+
17781821
constructor(data?: PartialMessage<GRPCMapping>) {
17791822
super();
17801823
proto3.util.initPartial(data, this);
@@ -1789,6 +1832,7 @@ export class GRPCMapping extends Message<GRPCMapping> {
17891832
{ no: 4, name: "entity_mappings", kind: "message", T: EntityMapping, repeated: true },
17901833
{ no: 5, name: "type_field_mappings", kind: "message", T: TypeFieldMapping, repeated: true },
17911834
{ no: 6, name: "enum_mappings", kind: "message", T: EnumMapping, repeated: true },
1835+
{ no: 7, name: "resolve_mappings", kind: "message", T: LookupMapping, repeated: true },
17921836
]);
17931837

17941838
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GRPCMapping {
@@ -1808,6 +1852,128 @@ export class GRPCMapping extends Message<GRPCMapping> {
18081852
}
18091853
}
18101854

1855+
/**
1856+
* Defines mapping for a lookup operation
1857+
*
1858+
* @generated from message wg.cosmo.node.v1.LookupMapping
1859+
*/
1860+
export class LookupMapping extends Message<LookupMapping> {
1861+
/**
1862+
* Type of lookup operation
1863+
*
1864+
* @generated from field: wg.cosmo.node.v1.LookupType type = 1;
1865+
*/
1866+
type = LookupType.UNSPECIFIED;
1867+
1868+
/**
1869+
* Mappings for GraphQL type fields to gRPC message fields
1870+
*
1871+
* @generated from field: wg.cosmo.node.v1.LookupFieldMapping lookup_mapping = 2;
1872+
*/
1873+
lookupMapping?: LookupFieldMapping;
1874+
1875+
/**
1876+
* Mapped gRPC method name
1877+
*
1878+
* @generated from field: string rpc = 3;
1879+
*/
1880+
rpc = "";
1881+
1882+
/**
1883+
* Mapped gRPC request message type name
1884+
*
1885+
* @generated from field: string request = 4;
1886+
*/
1887+
request = "";
1888+
1889+
/**
1890+
* Mapped gRPC response message type name
1891+
*
1892+
* @generated from field: string response = 5;
1893+
*/
1894+
response = "";
1895+
1896+
constructor(data?: PartialMessage<LookupMapping>) {
1897+
super();
1898+
proto3.util.initPartial(data, this);
1899+
}
1900+
1901+
static readonly runtime: typeof proto3 = proto3;
1902+
static readonly typeName = "wg.cosmo.node.v1.LookupMapping";
1903+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
1904+
{ no: 1, name: "type", kind: "enum", T: proto3.getEnumType(LookupType) },
1905+
{ no: 2, name: "lookup_mapping", kind: "message", T: LookupFieldMapping },
1906+
{ no: 3, name: "rpc", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1907+
{ no: 4, name: "request", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1908+
{ no: 5, name: "response", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1909+
]);
1910+
1911+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): LookupMapping {
1912+
return new LookupMapping().fromBinary(bytes, options);
1913+
}
1914+
1915+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): LookupMapping {
1916+
return new LookupMapping().fromJson(jsonValue, options);
1917+
}
1918+
1919+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): LookupMapping {
1920+
return new LookupMapping().fromJsonString(jsonString, options);
1921+
}
1922+
1923+
static equals(a: LookupMapping | PlainMessage<LookupMapping> | undefined, b: LookupMapping | PlainMessage<LookupMapping> | undefined): boolean {
1924+
return proto3.util.equals(LookupMapping, a, b);
1925+
}
1926+
}
1927+
1928+
/**
1929+
* Defines mapping for a lookup field
1930+
*
1931+
* @generated from message wg.cosmo.node.v1.LookupFieldMapping
1932+
*/
1933+
export class LookupFieldMapping extends Message<LookupFieldMapping> {
1934+
/**
1935+
* GraphQL type name
1936+
*
1937+
* @generated from field: string type = 1;
1938+
*/
1939+
type = "";
1940+
1941+
/**
1942+
* Mapping for the lookup field
1943+
*
1944+
* @generated from field: wg.cosmo.node.v1.FieldMapping field_mapping = 2;
1945+
*/
1946+
fieldMapping?: FieldMapping;
1947+
1948+
constructor(data?: PartialMessage<LookupFieldMapping>) {
1949+
super();
1950+
proto3.util.initPartial(data, this);
1951+
}
1952+
1953+
static readonly runtime: typeof proto3 = proto3;
1954+
static readonly typeName = "wg.cosmo.node.v1.LookupFieldMapping";
1955+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
1956+
{ no: 1, name: "type", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1957+
{ no: 2, name: "field_mapping", kind: "message", T: FieldMapping },
1958+
]);
1959+
1960+
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): LookupFieldMapping {
1961+
return new LookupFieldMapping().fromBinary(bytes, options);
1962+
}
1963+
1964+
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): LookupFieldMapping {
1965+
return new LookupFieldMapping().fromJson(jsonValue, options);
1966+
}
1967+
1968+
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): LookupFieldMapping {
1969+
return new LookupFieldMapping().fromJsonString(jsonString, options);
1970+
}
1971+
1972+
static equals(a: LookupFieldMapping | PlainMessage<LookupFieldMapping> | undefined, b: LookupFieldMapping | PlainMessage<LookupFieldMapping> | undefined): boolean {
1973+
return proto3.util.equals(LookupFieldMapping, a, b);
1974+
}
1975+
}
1976+
18111977
/**
18121978
* Defines mapping between a GraphQL operation and a gRPC method
18131979
*

proto/wg/cosmo/node/v1/node.proto

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ message SSLConfiguration {
227227
bool enabled = 1;
228228
}
229229

230+
// Defines mapping for a gRPC service
230231
message GRPCMapping {
231232
// Version of the mapping format
232233
int32 version = 1;
@@ -240,6 +241,40 @@ message GRPCMapping {
240241
repeated TypeFieldMapping type_field_mappings = 5;
241242
// Mappings for GraphQL enum values to gRPC enum values
242243
repeated EnumMapping enum_mappings = 6;
244+
// Mappings for GraphQL resolve operations to gRPC service methods
245+
repeated LookupMapping resolve_mappings = 7;
246+
}
247+
248+
// Defines mapping for a lookup operation
249+
message LookupMapping {
250+
// Type of lookup operation
251+
LookupType type = 1;
252+
// Mappings for GraphQL type fields to gRPC message fields
253+
LookupFieldMapping lookup_mapping = 2;
254+
// Mapped gRPC method name
255+
string rpc = 3;
256+
// Mapped gRPC request message type name
257+
string request = 4;
258+
// Mapped gRPC response message type name
259+
string response = 5;
260+
}
261+
262+
// Defines mapping for a lookup field
263+
message LookupFieldMapping {
264+
// GraphQL type name
265+
string type = 1;
266+
// Mapping for the lookup field
267+
FieldMapping field_mapping = 2;
268+
}
269+
270+
// Defines the type of lookup operation
271+
enum LookupType {
272+
// Unspecified lookup type
273+
LOOKUP_TYPE_UNSPECIFIED = 0;
274+
// Lookup type for field resolution
275+
LOOKUP_TYPE_RESOLVE = 1;
276+
// Lookup type for the @requires directive
277+
LOOKUP_TYPE_REQUIRES = 2;
243278
}
244279

245280
// Defines the type of GraphQL operation

protographic/src/naming-conventions.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { camelCase, lowerFirst, snakeCase, upperFirst } from 'lodash-es';
1010
/**
1111
* The names of the GraphQL operation types
1212
*/
13-
export type OperationTypeName = 'Query' | 'Mutation' | 'Subscription';
13+
export type OperationTypeName = 'Query' | 'Mutation' | 'Subscription' | 'Resolve';
1414

1515
/**
1616
* Converts a GraphQL field name to a Protocol Buffer field name (snake_case)
@@ -79,23 +79,13 @@ export function createEnumUnspecifiedValue(enumTypeName: string): string {
7979
return `${snakeCase(enumTypeName).toUpperCase()}_UNSPECIFIED`;
8080
}
8181

82-
/**
83-
* Creates a operation arguments name for an operation
84-
* @param operationName - The name of the operation
85-
* @param fieldName - The name of the field
86-
* @returns The name of the operation arguments
87-
*/
88-
export function resolverRequestKeyName(requestName: string): string {
89-
return `${upperFirst(camelCase(requestName))}Key`;
90-
}
91-
9282
/**
9383
* Creates a response result name for a resolver response
9484
* @param responseName - The name of the response
9585
* @returns The name of the response result
9686
*/
97-
export function resolverResponseResultName(responseName: string): string {
98-
return `${upperFirst(camelCase(responseName))}Result`;
87+
export function resolverResponseResultName(methodName: string): string {
88+
return `${upperFirst(camelCase(methodName))}Result`;
9989
}
10090

10191
/**
@@ -104,16 +94,16 @@ export function resolverResponseResultName(responseName: string): string {
10494
* @param fieldName - The name of the field
10595
* @returns The name of the type field arguments
10696
*/
107-
export function typeFieldArgsName(typeName: string, fieldName: string): string {
108-
return `${upperFirst(camelCase(typeName))}${upperFirst(camelCase(fieldName))}Args`;
97+
export function typeFieldArgsName(methodName: string): string {
98+
return `${methodName}Args`;
10999
}
110100

111101
/**
112-
* Creates a proto field name that combines the parent type name and field name
113-
* @param parentTypeName - The name of the parent type
102+
* Creates a type field context name for a type field
103+
* @param typeName - The name of the type
114104
* @param fieldName - The name of the field
115-
* @returns The name of the proto field
105+
* @returns The name of the type field context
116106
*/
117-
export function parentTypeNameProtoField(parentTypeName: string, fieldName: string): string {
118-
return snakeCase(`${upperFirst(camelCase(parentTypeName))}${upperFirst(camelCase(fieldName))}`);
107+
export function typeFieldContextName(methodName: string): string {
108+
return `${methodName}Context`;
119109
}

0 commit comments

Comments
 (0)