ardatan / graphql-mesh

πŸ•ΈοΈ GraphQL Federation Framework for any API services such as REST, OpenAPI, Swagger, SOAP, gRPC and more...
https://the-guild.dev/graphql/mesh
MIT License
3.27k stars 339 forks source link

gRPC reflection doesn't work for one endpoint handling multiple services #6847

Closed mr-nagashima closed 2 hours ago

mr-nagashima commented 6 months ago

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.


Describe the bug

The backend's gRPC API provides nine services.

I wrote the .meshrc.yaml below.

.meshrc.yaml

sources:
  - name: Backend
    handler:
      grpc:
        endpoint: backend:3000

And when I started GraphQL Mesh in dev mode, I got an error at the end.

$ mesh dev
    :
Mesh - Server πŸ’‘ Starting GraphQL Mesh...
Mesh - Server πŸ’‘ Serving GraphQL Mesh: http://0.0.0.0:4000
Mesh - Backend πŸ› Getting stored root and decoded descriptor set objects
Mesh - Backend πŸ› Building Roots
Mesh - Backend πŸ› Using the reflection
Mesh - Backend πŸ› Creating gRPC Reflection Client
Mesh - Backend πŸ› Resolving root of Service: greet.v1.GreetService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: cancellation.v1.CancellationService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: supplier.v1.SupplierService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: depot.v1.DepotService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: warehouse.v1.WarehouseService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: office.v1.OfficeService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: company.v1.CompanyService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: plan.v1.PlanService from the reflection response
Mesh - Backend πŸ› Resolving root of Service: room.v1.RoomService from the reflection response
    :
Mesh - Backend πŸ› Building the schema structure based on the root object
Mesh - Backend - Root0 πŸ› Visiting .nested[greet]
    :
Mesh - Backend πŸ› Building the schema structure based on the root object
Mesh - Backend - Root8 πŸ› Visiting .nested[google]
    :
Mesh - Backend πŸ› Building the final GraphQL Schema
Mesh - Backend - Root8 πŸ› Creating service client for package definition
Mesh - Backend πŸ’₯ Failed to generate the schema for the source "Backend"
Invalid value used as weak map key
Mesh HTTP πŸ’₯ Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh.
    at getMesh (/app/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:124:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

I think that the reflection has been loaded, the above error occurs at the very end. What does "Invalid value used as weak map key" indicate?

I would appreciate it if you could tell me the solution.

To Reproduce Steps to reproduce the behavior:

Expected behavior

Start normally

Environment:

Additional context

mbrowne commented 3 hours ago

Caused by https://github.com/ardatan/graphql-mesh/issues/6424. The bug was introduced by https://github.com/ardatan/graphql-mesh/pull/5420 (this used to work fine before that).

ardatan commented 3 hours ago

An isolated, minimal reproduction would be good for us in order to debug so that we can try to fix it after.

mbrowne commented 3 hours ago

Hi @ardatan , @Francismb created a reproduction here earlier: https://github.com/ardatan/graphql-mesh/issues/5438#issuecomment-1590313857

And I had created this reproduction originally: https://github.com/mbrowne/graphql-mesh-bug-repro/tree/grpc-source-issue

There's also a lot of info in https://github.com/ardatan/graphql-mesh/issues/5438 that you might find helpful for debugging.

mbrowne commented 2 hours ago

Actually I took a closer look at https://github.com/Francismb/graphql-mesh-issue and it doesn't reproduce the issue for me because it apparently depends on a gRPC server not included in that repo. Here are updated/fixed instructions on how to more simply reproduce the issue using my branch:

git clone git@github.com:mbrowne/graphql-mesh-bug-repro.git --single-branch --branch grpc-source-issue
yarn
yarn start
ardatan commented 2 hours ago

Thanks for the reproduction! Fixed by https://github.com/ardatan/graphql-mesh/pull/7807

mbrowne commented 2 hours ago

@ardatan Thanks! I'll take a closer look at this later. I still think there is a bug in @graphql-tools/stitch, but if your fix makes gRPC work properly without needing to fix that bug then that's awesome! :-)