google/rejoiner

Documentation question

Opened this issue · 4 comments

Calling a GRPC service normally looks something like:

Point request = Point.newBuilder().setLatitude(lat).setLongitude(lon).build();
Feature feature;
try {
  feature = blockingStub.getFeature(request);
} catch (StatusRuntimeException e) {
  logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
  return;
}

The example given in the doc looks very different:

final class TodoToUserSchemaModule extends SchemaModule {
  @SchemaModification(addField = "creator", onType = Todo.class)
  ListenableFuture<User> todoCreatorToUser(UserService userService, Todo todo) {
    return userService.getUserByEmail(todo.getCreatorEmail());
  }
}

Is this example calling a GRPC service?

GRPC exposes two ways of making calls, blocking and non-blocking. You could use the blocking stub, which would look something like:

final class TodoToUserSchemaModule extends SchemaModule {
@SchemaModification(addField = "creator", onType = Todo.class)
User todoCreatorToUser(UserBlockingStub stub, Todo todo) {
return stub.getUserByEmail(todo.getCreatorEmail());
}
}

The HelloWorld example is using a blocking stub:

https://github.com/google/rejoiner/blob/master/examples/src/main/java/com/google/api/graphql/examples/helloworld/graphqlserver/HelloWorldSchemaModule.java

I'm guessing you've seen this already based on the example you gave.
https://grpc.io/docs/tutorials/basic/java.html#creating-a-stub

The thing that confuses me is that I think GRPC always takes a request object. E.g. in the HelloWorldSchemaModule example you gave, the call is client.sayHello(request).

I'm confused how the documentation gives an example of userService.getUserByEmail(todo.getCreatorEmail()). This example is passing in an email and I would guess email is a String. However, I would expect a GRPC request to take a request object and look more like userService.getUser(request)

GRPC to my knowledge does not allow that. Can you show us a working example of a proto file that actually des not declare a message but just uses a type directly?

I agree. I'm suggesting that the example in the documentation may not actually be working and needs to be updated