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

Using Reflection for Grpc source does not work as documented #4919

Open
SonofNun15 opened this issue Dec 9, 2022 Discussed in #4890 · 2 comments
Open

Using Reflection for Grpc source does not work as documented #4919

SonofNun15 opened this issue Dec 9, 2022 Discussed in #4890 · 2 comments

Comments

@SonofNun15
Copy link

From the discussion below, I uncovered that using reflection as the protobuf source for a Grpc endpoint does not seem to work as documented. The documentation indicates that reflection will be used if the source property is not defined on the handler.

This block of code, however, fails if the source field is not supplied and does not have a file property on it:
https://github.com/Urigo/graphql-mesh/blob/master/packages/handlers/grpc/src/index.ts#L203-L212

Because of this, in order to get reflection for Grpc you have to use source: { file: "" } in order to use reflection.

Either the documentation should be updated accordingly or ideally the source code updated to handle the missing source property.

Discussed in #4890

Originally posted by SonofNun15 December 5, 2022
I have a GRPC service that has reflection enabled.

I am able to enumerate the schema via reflection in postman and make requests to this service.

I set up my mesh config like this (same port as postman uses):

sources:
  - name: People
    handler:
      grpc:
        endpoint: localhost:5059
        useHTTPS: true

The service is setup to use HTTPS and postman is connecting via TLS.

When I run the mesh service via mesh dev, it runs successfully and brings up the graphql tools, but there is no schema generated. If I look at the schema.graphql files in the .mesh folder and try to open any of the exploration tools in the graphql tools, everything is completely empty.

Any ideas as to what I am doing wrong? Is there something extra you have to do to get reflection to work properly?

UPDATE:

Tried pulling in the proto file locally to see what the issue was and I'm seeing this in the console:

Configuration is not valid:
data/sources/0/handler/grpc must NOT have additional properties

UPDATE:

Here's the proto file I'm using. Maybe it's not compatible for some reason, possible because of the datetime fields?

syntax = "proto3";

package person;

import "google/protobuf/timestamp.proto";

option csharp_namespace = "Models.Person";

service People {
	rpc List (PeopleRequest) returns (PersonListReply);
	rpc Get(PersonRequest) returns (Person);
	rpc Phones(PhonesRequest) returns (PhonesReply);
}

message PeopleRequest {
	int32 limit = 1;
	int32 page = 2;
	oneof optional_query {
		string query = 3;
	}
}

message Person {
	string id = 1;
	string name = 2;
	string email = 3;
	google.protobuf.Timestamp date_of_birth = 4;
}

message PersonListReply {
	int32 count = 1;
	repeated Person people = 2;
	int32 page_size = 3;
}

message PersonRequest {
	string person_id = 1;
}

message PhonesRequest {
	string person_id = 1;
}

enum PhoneType {
	PRIMARY = 0;
	HOME = 1;
	WORK = 2;
	MOBILE = 3;
	OTHER = 4;
}

message PhonesReply {
	string id = 1;
	string person_id = 2;
	string number = 3;
	PhoneType type = 4;
}
```</div>
@EduardValentin
Copy link

I was considering to open a new issue but I'll add that on top of what you described, whenever I add an empty file path to make the reflection flow work, I get another error: Failed to generate the schema TypeError: Cannot read properties of undefined (reading 'Client') at GrpcHandler.processReflection (/~/Desktop/graphql-demo/mesh/node_modules/@graphql-mesh/grpc/cjs/index.js:68:67)

The problem is that the grpc handler uses @ardatan/grpc-reflection-js and uses default import, but @ardatan/grpc-reflection-js doesn't do default export, only named. Maybe a PR should be opened to fix that?

@ardatan
Copy link
Owner

ardatan commented Apr 3, 2023

Could you create a reproduction on CodeSandbox or StackBlitz? Thanks!

This was referenced Apr 30, 2024
This was referenced May 7, 2024
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

3 participants