当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

rejoiner

授权协议 Apache-2.0 License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 栾英资
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Rejoiner

  • Creates a uniform GraphQL schema from microservices
  • Allows the GraphQL schema to be flexibly defined and composed as shared components
  • Generates GraphQL types from Proto definitions
  • Populates request Proto based on GraphQL query parameters
  • Supplies a DSL to modify the generated schema
  • Joins data sources by annotating methods that fetch data
  • Creates Proto FieldMasks based on GraphQL selectors

Experimental Features

These features are actively being developed.

  • Expose any GraphQL schema as a gRPC service.
  • Lossless end to end proto scalar types when using gRPC.
  • Relay support [Example]
  • GraphQL Stream (based on gRPC streaming) [Example]

Schema Module

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.

GraphQL Query

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:

  • Make gRPC calls to microservices which can be implemented in any language
  • Load protobuf messages directly from storage
  • Perform arbitrary logic to produce the result

GraphQL Mutation

final 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 types

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.

Removing a field

final class TodoModificationsSchemaModule extends SchemaModule {
  @SchemaModification
  TypeModification removePrivateTodoData =
      Type.find(Todo.getDescriptor()).removeField("privateTodoData");
}

Building the GraphQL schema

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());
  }
}

Getting started

Dependency information

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"

Supported return types

All generated proto messages extend Message.

  • Any subclass of Message
  • ImmutableList<? extends Message>
  • ListenableFuture<? extends Message>
  • ListenableFuture<ImmutableList<? extends Message>>

Project information

  • Rejoiner is built on top of GraphQL-Java which provides the coreGraphQL capabilities such as query parsing, validation, and execution.
  • Java code is formatted using google-java-format.
  • Note: This is not an official Google product.
  • 今日份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" /> 但是还