Skip to content

Commit

Permalink
Merge pull request #330 from amplication/fix/7795-proto-file
Browse files Browse the repository at this point in the history
fix(gRPC): fix proto file methods names
  • Loading branch information
mulygottlieb authored Jan 14, 2024
2 parents 0e8e383 + 5a69b13 commit aca53db
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 76 deletions.
18 changes: 9 additions & 9 deletions plugins/transport-grpc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions plugins/transport-grpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-transport-grpc",
"version": "0.0.6",
"version": "0.0.7",
"description": "add gRPC endpoints to your generated services",
"main": "dist/index.js",
"nx": {},
Expand All @@ -12,7 +12,7 @@
"author": "Mor Hagbi",
"license": "Apache-2.0",
"devDependencies": {
"@amplication/code-gen-types": "^2.0.17",
"@amplication/code-gen-types": "^2.0.22",
"@amplication/code-gen-utils": "^0.0.7",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
Expand Down
26 changes: 16 additions & 10 deletions plugins/transport-grpc/src/core/create-base-grpc-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,51 @@ import { templatesPath } from "../constants";

const controllerBaseGrpcPath = join(
templatesPath,
"controller.grpc.base.template.ts"
"controller.grpc.base.template.ts",
);

export async function createGrpcControllerBase(
context: DsgContext,
eventParams: CreateEntityGrpcControllerBaseParams
eventParams: CreateEntityGrpcControllerBaseParams,
): Promise<void> {
try {
const { controllerBaseId, templateMapping, entity } = eventParams;
const { entityActionsMap } = context;
const entityActions = entityActionsMap[entity.name];

const controllerBaseGrpcTemplate = await readFile(controllerBaseGrpcPath);
interpolate(controllerBaseGrpcTemplate, templateMapping);

const classDeclaration = getClassDeclarationById(
controllerBaseGrpcTemplate,
controllerBaseId
controllerBaseId,
);

controllerMethodsIdsActionPairs(templateMapping, entity).forEach(
({ methodId, entity, methodName }) => {
const classMethod = getClassMethodByIdName(classDeclaration, methodId);
controllerMethodsIdsActionPairs(
templateMapping,
entity,
entityActions,
).forEach(({ methodId, entity, methodName }) => {
const classMethod = getClassMethodByIdName(classDeclaration, methodId);
if (methodName) {
classMethod?.decorators?.push(
buildGrpcMethodDecorator(entity.name, methodName)
buildGrpcMethodDecorator(entity.name, methodName),
);
}
);
});
eventParams.template = controllerBaseGrpcTemplate;
} catch (error) {
console.error(error);
}
}
export function buildGrpcMethodDecorator(
entityName: string,
methodName: string
methodName: string,
): namedTypes.Decorator {
return builders.decorator(
builders.callExpression(builders.identifier("GrpcMethod"), [
builders.stringLiteral(`${entityName}Service`),
builders.stringLiteral(methodName),
])
]),
);
}
Loading

0 comments on commit aca53db

Please sign in to comment.