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

"duplicate name" error when importing schemas with extensions #1783

Closed
ThePlenkov opened this issue Aug 2, 2022 · 1 comment
Closed

"duplicate name" error when importing schemas with extensions #1783

ThePlenkov opened this issue Aug 2, 2022 · 1 comment

Comments

@ThePlenkov
Copy link
Contributor

Hi!

I've stuck with a problem, which I'm not sure how to solve.

So I have a file like this:

syntax = "proto3";

package validation;

import "google/protobuf/descriptor.proto";

option java_package = "com.reserve.validation";
option java_outer_classname = "ValidationRules";

extend google.protobuf.FieldOptions {
    FieldRules rules = 70001;
}

message FieldRules {
    reserved 1;
    reserved "optional";
}

In fact I have this file as a nested dependency , so cannot change the way of extending.

I want to convert this file to graphQL schema using this module:
https://www.graphql-mesh.com/docs/handlers/grpc

So internally they build decodedDescriptorSet and call protobuf like this:
https://github.com/grpc/grpc-node/blob/a8719c4f38f9c356ca5f699656ff49c0292fceb7/packages/proto-loader/src/index.ts#L345

which calls Root.fromDescriptor from this module.

The problem is - right now it gives the error:

mesh build
💡 🕸️  Mesh Cleaning existing artifacts
💡 🕸️  Mesh Reading the configuration
💡 🕸️  Mesh Generating the unified schema
💥 🕸️  Mesh - order-search Failed to generate the schema Error: duplicate name '.validation.rules' in Type .google.protobuf.FieldOptions
    at Type.add (/workspaces/order-search-graphql/node_modules/protobufjs/src/type.js:331:15)
    at tryHandleExtension (/workspaces/order-search-graphql/node_modules/protobufjs/src/root.js:278:22)
    at Root._handleAdd (/workspaces/order-search-graphql/node_modules/protobufjs/src/root.js:306:21)
    at Type.onAdd (/workspaces/order-search-graphql/node_modules/protobufjs/src/object.js:126:14)
    at Namespace.add (/workspaces/order-search-graphql/node_modules/protobufjs/src/namespace.js:243:12)
    at Function.fromDescriptor (/workspaces/order-search-graphql/node_modules/protobufjs/ext/descriptor/index.js:92:33)
    at createPackageDefinitionFromDescriptorSet (/workspaces/order-search-graphql/node_modules/@grpc/proto-loader/build/src/index.js:159:32)
    at Object.loadFileDescriptorSetFromObject (/workspaces/order-search-graphql/node_modules/@grpc/proto-loader/build/src/index.js:214:12)
    at GrpcHandler.getMeshSource (/workspaces/order-search-graphql/node_modules/@graphql-mesh/grpc/index.js:532:51)
    at async /workspaces/order-search-graphql/node_modules/@graphql-mesh/runtime/index.js:281:28
💥 🕸️  Mesh Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh with DEBUG=1 e...

This issue is very similar to #1080 however in my case i don't have an option to change imported files. I tried also to load this file as a root - the result is the same. What triggers this error - is exactly extend statement.

Do you have any ideas why can it happen?

ThePlenkov added a commit to ThePlenkov/protobuf.js that referenced this issue Aug 18, 2022
jackkav pushed a commit to Kong/protobuf.js that referenced this issue Dec 15, 2022
alexander-fenster pushed a commit that referenced this issue Feb 7, 2023
)

* do not allow to extend same field twice to prevent the error

* Ignore gitpod config

* unit test for issue #1783

* using existing test file
@ThePlenkov
Copy link
Contributor Author

ThePlenkov commented Mar 21, 2023

Closing this issue since is release in 7.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant