These features are actively being developed.
SchemaModule is a Guice module that is used to generate parts of a GraphQLschema. It finds methods and fields that have Rejoiner annotations when it'sinstantiated. It then looks at the parameters and return type of these methodsin order to generate the appropriate GraphQL schema. Examples of queries,mutations, and schema modifications are presented below.
final class TodoQuerySchemaModule extends SchemaModule {
@Query("listTodo")
ListenableFuture<ListTodoResponse> listTodo(ListTodoRequest request, TodoClient todoClient) {
return todoClient.listTodo(request);
}
}
In this example request
is of type ListTodoRequest
(a protobuf message), soit's used as a parameter in the generated GraphQL query. todoService
isn't aprotobuf message, so it's provided by the Guice injector.
This is useful for providing rpc services or database access objects forfetching data. Authentication data can also be provided here.
Common implementations for these annotated methods:
final class TodoMutationSchemaModule extends SchemaModule {
@Mutation("createTodo")
ListenableFuture<Todo> createTodo(
CreateTodoRequest request, TodoService todoService, @AuthenticatedUser String email) {
return todoService.createTodo(request, email);
}
}
In this example we are adding a reference to the User type on the Todo type.
final class TodoToUserSchemaModule extends SchemaModule {
@SchemaModification(addField = "creator", onType = Todo.class)
ListenableFuture<User> todoCreatorToUser(UserService userService, Todo todo) {
return userService.getUserByEmail(todo.getCreatorEmail());
}
}
In this case the Todo parameter is the parent object which can be referenced toget the creator's email.
This is how types are joined within and across APIs.
final class TodoModificationsSchemaModule extends SchemaModule {
@SchemaModification
TypeModification removePrivateTodoData =
Type.find(Todo.getDescriptor()).removeField("privateTodoData");
}
import com.google.api.graphql.rejoiner.SchemaProviderModule;
public final class TodoModule extends AbstractModule {
@Override
protected void configure() {
// Guice module that provides the generated GraphQLSchema instance
install(new SchemaProviderModule());
// Install schema modules
install(new TodoQuerySchemaModule());
install(new TodoMutationSchemaModule());
install(new TodoModificationsSchemaModule());
install(new TodoToUserSchemaModule());
}
}
Apache Maven
<dependency>
<groupId>com.google.api.graphql</groupId>
<artifactId>rejoiner</artifactId>
<version>0.0.4</version>
</dependency>
Gradle/Grailscompile 'com.google.api.graphql:rejoiner:0.0.4'
Scala SBTlibraryDependencies += "com.google.api.graphql" % "rejoiner" % "0.0.4"
All generated proto messages extend Message
.
Message
ImmutableList<? extends Message>
ListenableFuture<? extends Message>
ListenableFuture<ImmutableList<? extends Message>>
今日份Rejoiner,今天老大让我弄了个东西,就是在proto文件生成的同时添加一个注释,这个注释可以给前台人员看到,因为rejoiner的文章比较少,所以弄了一上午时间,难受啊, 然后在这里说一下解决过程。 首先说一下解决后的感悟吧,这个东西的执行是这样的:首先在自动生成的时候,直接将proto文件中的注释都添加在一个文件中,然后Regoiner将这些注释在注入进去,这里是自动注入的,所以不用
首先确定在代码中的post请求中已经设置了跨域如下 resp.setHeader("Access-Control-Allow-Origin", "*"); resp.setHeader("Access-Control-Allow-Origin", "*"); resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS,
接之前rejoiner的desc问题,最近打开看了一下之前写过rejoiner的一些业务,突然发现一个问题,就是之前写好的desc在页面上都变成了“?”,真的是百思不解,因为项目上线之后就没用这个页面,按道理应该是编码的问题,可是在页面上已经加过: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 但是还