Skip to content

Commit 6f93d40

Browse files
committed
chore: format code
1 parent 8729c58 commit 6f93d40

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

protographic/src/sdl-to-proto-visitor.ts

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,18 @@ export class GraphQLToProtoTextVisitor {
472472
const mutationResult = this.collectMutationRpcMethods();
473473

474474
// Combine all RPC methods and message definitions
475-
const allRpcMethods = [...entityResult.rpcMethods, ...queryResult.rpcMethods, ...mutationResult.rpcMethods, ...resolverResult.rpcMethods];
476-
const allMethodNames = [...entityResult.methodNames, ...queryResult.methodNames, ...mutationResult.methodNames, ...resolverResult.methodNames];
475+
const allRpcMethods = [
476+
...entityResult.rpcMethods,
477+
...queryResult.rpcMethods,
478+
...mutationResult.rpcMethods,
479+
...resolverResult.rpcMethods,
480+
];
481+
const allMethodNames = [
482+
...entityResult.methodNames,
483+
...queryResult.methodNames,
484+
...mutationResult.methodNames,
485+
...resolverResult.methodNames,
486+
];
477487

478488
const allMessageDefinitions = [
479489
...entityResult.messageDefinitions,
@@ -1138,7 +1148,10 @@ Example:
11381148
return result;
11391149
}
11401150

1141-
private getFieldContext(parent: GraphQLObjectType, field: GraphQLField<any, any>): { context: string, error: string | undefined } {
1151+
private getFieldContext(
1152+
parent: GraphQLObjectType,
1153+
field: GraphQLField<any, any>,
1154+
): { context: string; error: string | undefined } {
11421155
const resolvedDirective = this.findResolvedDirective(field);
11431156
if (resolvedDirective) {
11441157
const valueNode = resolvedDirective.arguments?.find((arg) => arg.name.value === 'context')?.value;
@@ -1162,7 +1175,11 @@ Example:
11621175
case 1:
11631176
return { context: idFields[0].name, error: undefined };
11641177
default:
1165-
return { context: '', error: 'Multiple fields with type ID found - provide a context with the fields you want to use in the @resolved directive' };
1178+
return {
1179+
context: '',
1180+
error:
1181+
'Multiple fields with type ID found - provide a context with the fields you want to use in the @resolved directive',
1182+
};
11661183
}
11671184
}
11681185

@@ -1229,12 +1246,10 @@ Example:
12291246
field: GraphQLField<any, any>,
12301247
): string[] {
12311248
const messageLines: string[] = [];
1232-
const {context, error} = this.getFieldContext(parent, field);
1249+
const { context, error } = this.getFieldContext(parent, field);
12331250

12341251
if (error) {
1235-
throw new Error(
1236-
`Invalid field context for resolver. ${error}`,
1237-
);
1252+
throw new Error(`Invalid field context for resolver. ${error}`);
12381253
}
12391254

12401255
const argsMessageName = typeFieldArgsName(parent.name, field.name);
@@ -1252,16 +1267,13 @@ Example:
12521267
}),
12531268
);
12541269

1255-
12561270
// build the key message
12571271
const searchFields = context.split(/[,\s]+/).filter((field) => field.length > 0);
12581272
const fieldFilter = Object.entries(parent.getFields())
12591273
.filter(([_, field]) => searchFields.includes(field.name))
12601274
.map(([_, field]) => field);
12611275
if (searchFields.length !== fieldFilter.length) {
1262-
throw new Error(
1263-
`Invalid field context for resolver. Could not find all fields in the parent type: ${context}`,
1264-
);
1276+
throw new Error(`Invalid field context for resolver. Could not find all fields in the parent type: ${context}`);
12651277
}
12661278

12671279
fieldNumber = 0;
@@ -1335,33 +1347,38 @@ Example:
13351347
parent: GraphQLObjectType,
13361348
field: GraphQLField<any, any>,
13371349
): string[] {
1338-
console.log('createResolverResponseMessage', responseName, parent, field);
13391350
const messageLines: string[] = [];
13401351

1341-
13421352
// CreateResultMessage
13431353
const resultMessageName = resolverResponseResultName(responseName);
13441354
const protoType = this.getProtoTypeFromGraphQL(field.type);
13451355

1346-
messageLines.push(...this.buildMessage({
1347-
messageName: resultMessageName,
1348-
fields: [{
1349-
fieldName: graphqlFieldToProtoField(field.name),
1350-
typeName: protoType.typeName,
1351-
fieldNumber: 1,
1352-
}]
1353-
}))
1354-
1355-
messageLines.push(...this.buildMessage({
1356-
messageName: responseName,
1357-
fields: [{
1358-
fieldName: 'result',
1359-
typeName: resultMessageName,
1360-
fieldNumber: 1,
1361-
isRepeated: true,
1362-
}]
1363-
}))
1356+
messageLines.push(
1357+
...this.buildMessage({
1358+
messageName: resultMessageName,
1359+
fields: [
1360+
{
1361+
fieldName: graphqlFieldToProtoField(field.name),
1362+
typeName: protoType.typeName,
1363+
fieldNumber: 1,
1364+
},
1365+
],
1366+
}),
1367+
);
13641368

1369+
messageLines.push(
1370+
...this.buildMessage({
1371+
messageName: responseName,
1372+
fields: [
1373+
{
1374+
fieldName: 'result',
1375+
typeName: resultMessageName,
1376+
fieldNumber: 1,
1377+
isRepeated: true,
1378+
},
1379+
],
1380+
}),
1381+
);
13651382

13661383
return messageLines;
13671384
}

protographic/tests/sdl-to-proto/13-field-arguments.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ describe('SDL to Proto Field Arguments', () => {
550550
}
551551
`;
552552

553-
expect(() => compileGraphQLToProto(sdl)).throws('Invalid field context for resolver. Multiple fields with type ID found - provide a context with the fields you want to use in the @resolved directive');
553+
expect(() => compileGraphQLToProto(sdl)).throws(
554+
'Invalid field context for resolver. Multiple fields with type ID found - provide a context with the fields you want to use in the @resolved directive',
555+
);
554556
});
555557
});

0 commit comments

Comments
 (0)