在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):google/rejoiner开源软件地址(OpenSource Url):https://github.com/google/rejoiner开源编程语言(OpenSource Language):Java 96.5%开源软件介绍(OpenSource Introduction):Rejoiner
Experimental FeaturesThese features are actively being developed.
Schema ModuleSchemaModule is a Guice module that is used to generate parts of a GraphQL schema. It finds methods and fields that have Rejoiner annotations when it's instantiated. It then looks at the parameters and return type of these methods in order to generate the appropriate GraphQL schema. Examples of queries, mutations, and schema modifications are presented below. GraphQL Queryfinal class TodoQuerySchemaModule extends SchemaModule {
@Query("listTodo")
ListenableFuture<ListTodoResponse> listTodo(ListTodoRequest request, TodoClient todoClient) {
return todoClient.listTodo(request);
}
} In this example This is useful for providing rpc services or database access objects for fetching data. Authentication data can also be provided here. Common implementations for these annotated methods:
GraphQL Mutationfinal class TodoMutationSchemaModule extends SchemaModule {
@Mutation("createTodo")
ListenableFuture<Todo> createTodo(
CreateTodoRequest request, TodoService todoService, @AuthenticatedUser String email) {
return todoService.createTodo(request, email);
}
} Adding edges between GraphQL typesIn 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 to get the creator's email. This is how types are joined within and across APIs. Removing a fieldfinal class TodoModificationsSchemaModule extends SchemaModule {
@SchemaModification
TypeModification removePrivateTodoData =
Type.find(Todo.getDescriptor()).removeField("privateTodoData");
} Building the GraphQL schemaimport 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());
}
} Getting startedDependency informationApache Maven <dependency>
<groupId>com.google.api.graphql</groupId>
<artifactId>rejoiner</artifactId>
<version>0.0.4</version>
</dependency> Gradle/Grails
Scala SBT
Supported return typesAll generated proto messages extend
Project information
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论