graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

RPC Method Named 'Close' Conflicts with Client Connection Close Operation in GraphQL Mesh gRPC Handling

Open hurenxu opened this issue 4 months ago • 0 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [ ] 3. A local solution has been provided
  • [ ] 4. A pull request is pending review

Describe the bug

When using GraphQL Mesh to wrap a gRPC service, a naming conflict arises if the service includes an RPC method named Close. The conflict occurs because the client.close() operation, intended to close the client connection, is mistakenly treated as an invocation of the RPC Close method. This issue specifically manifests during the mesh build process, leading to unintended behavior and errors.

Error Scenario: The error occurs in the context of dynamically subscribing to a destroy event and attempting to close the gRPC client connection:

const subId = this.pubsub.subscribe('destroy', () => {
  client.close(); // Expected to close the connection, not invoke an RPC method
});

However, because an RPC method named Close exists, calling client.close() attempts to invoke this RPC method instead of closing the client connection, leading to errors and unexpected behavior.

image

To Reproduce Steps to reproduce the behavior:

  1. Define a gRPC service with an RPC method named Close.
  2. Use GraphQL Mesh to wrap this gRPC service.
  3. Run the mesh build process.
  4. Observe the error during the build process, specifically when the destroy event triggers an attempt to close the client connection.

An example RPC:

service MyService {
  rpc Close (CloseRequest) returns (CloseResponse) {}
}

Expected behavior

The client.close() operation should close the gRPC client connection without invoking any RPC method, regardless of the existence of an RPC method named Close.

Environment:

  • OS: Mac
  • "@graphql-mesh/cli": "^0.88.6",
  • "@graphql-mesh/grpc": "^0.97.3",
  • "@graphql-mesh/openapi": "^0.97.4",
  • NodeJS: 18

Additional context

Potential Solution: Explore modifications to the GraphQL Mesh gRPC handling code to distinguish between the connection closing operation and RPC method invocations, potentially by aliasing or wrapping one of the operations.

Seeking guidance on best practices to resolve this naming conflict, including any recommended changes to the gRPC service definition or adjustments to GraphQL Mesh configuration to ensure the correct operation of client.close().

hurenxu avatar Feb 14 '24 23:02 hurenxu