Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/check field optional proto #6137

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-dryers-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/grpc': minor
---

make required field of graphql schema using protobuf field
4 changes: 2 additions & 2 deletions packages/container/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-mesh/container",
"version": "0.2.4",
"name": "@q00/container",
"version": "0.2.5",
"type": "module",
"repository": {
"type": "git",
Expand Down
11 changes: 11 additions & 0 deletions packages/handlers/grpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ export default class GrpcHandler implements MeshHandler {
string,
protobufjs.IField & { comment: string; keyType?: string },
][];
const oneofEntries = nested.oneofs ?? {} as {
[k: string]: protobufjs.IOneOf;
};

if (fieldEntries.length) {
const inputTC = this.schemaComposer.createInputTC({
name: inputTypeName,
Expand All @@ -552,6 +556,7 @@ export default class GrpcHandler implements MeshHandler {
});
for (const [fieldName, { type, rule, comment, keyType }] of fieldEntries) {
logger.debug(`Visiting ${currentPath}.nested.fields[${fieldName}]`);
const isOptional = oneofEntries[`_${fieldName}`]?.oneof.includes(fieldName)
const baseFieldTypePath = type.split('.');
inputTC.addFields({
[fieldName]: {
Expand All @@ -566,6 +571,9 @@ export default class GrpcHandler implements MeshHandler {
baseFieldTypePath,
);
fieldInputTypeName = getTypeName(this.schemaComposer, fieldTypePath, true);
if (!isOptional) {
fieldInputTypeName = fieldInputTypeName + '!';
}
}
return rule === 'repeated' ? `[${fieldInputTypeName}]` : fieldInputTypeName;
},
Expand All @@ -585,6 +593,9 @@ export default class GrpcHandler implements MeshHandler {
baseFieldTypePath,
);
fieldTypeName = getTypeName(this.schemaComposer, fieldTypePath, false);
if (!isOptional) {
fieldTypeName = fieldTypeName + '!';
}
}
return rule === 'repeated' ? `[${fieldTypeName}]` : fieldTypeName;
},
Expand Down
Loading