Skip to content

Commit

Permalink
initial commit for early review
Browse files Browse the repository at this point in the history
  • Loading branch information
siderakis committed Apr 22, 2019
1 parent cedc123 commit 7d1d59d
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 353 deletions.
245 changes: 124 additions & 121 deletions rejoiner/pom.xml
Expand Up @@ -16,7 +16,9 @@
limitations under the License. limitations under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <!-- To check for updates: mvn versions:display-dependency-updates -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>


<parent> <parent>
Expand Down Expand Up @@ -79,7 +81,7 @@
<dependency> <dependency>
<groupId>com.graphql-java</groupId> <groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId> <artifactId>graphql-java</artifactId>
<version>2018-11-28T08-13-20-3ada93e</version> <version>2019-04-09T05-29-53-bd9240c</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -159,9 +161,9 @@


</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version> <version>3.7.0</version>
<configuration> <configuration>
Expand All @@ -186,120 +188,121 @@
<version>2.3.1</version> <version>2.3.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version> <version>2.2.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-sources</id> <id>attach-sources</id>
<goals> <goals>
<goal>jar-no-fork</goal> <goal>jar-no-fork</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version> <version>2.9.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-javadocs</id> <id>attach-javadocs</id>
<goals> <goals>
<goal>jar</goal> <goal>jar</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
<configuration> <configuration>
<additionalparam>-Xdoclint:none</additionalparam> <additionalparam>-Xdoclint:none</additionalparam>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId> <artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version> <version>1.5</version>
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>
<phase>verify</phase> <phase>verify</phase>
<goals> <goals>
<goal>sign</goal> <goal>sign</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.sonatype.plugins</groupId> <groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId> <artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version> <version>1.6.7</version>
<extensions>true</extensions> <extensions>true</extensions>
<configuration> <configuration>
<serverId>ossrh</serverId> <serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl> <nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose> <autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.xolstice.maven.plugins</groupId> <groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId> <artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version> <version>0.5.1</version>
<configuration> <configuration>
<protocExecutable>/usr/local/bin/protoc</protocExecutable> <protocExecutable>/usr/local/bin/protoc</protocExecutable>
<writeDescriptorSet>true</writeDescriptorSet> <writeDescriptorSet>true</writeDescriptorSet>
<descriptorSetFileName>descriptor_set.desc</descriptorSetFileName> <descriptorSetFileName>descriptor_set.desc</descriptorSetFileName>
<descriptorSetOutputDirectory>${build.directory}/test-classes/META-INF/proto</descriptorSetOutputDirectory> <descriptorSetOutputDirectory>${build.directory}/test-classes/META-INF/proto
<includeSourceInfoInDescriptorSet>true</includeSourceInfoInDescriptorSet> </descriptorSetOutputDirectory>
<includeDependenciesInDescriptorSet>true</includeDependenciesInDescriptorSet> <includeSourceInfoInDescriptorSet>true</includeSourceInfoInDescriptorSet>
</configuration> <includeDependenciesInDescriptorSet>true</includeDependenciesInDescriptorSet>
<executions> </configuration>
<execution> <executions>
<goals> <execution>
<goal>compile</goal> <goals>
<goal>test-compile</goal> <goal>compile</goal>
</goals> <goal>test-compile</goal>
</execution> </goals>
</executions> </execution>
</plugin> </executions>
<plugin> </plugin>
<groupId>org.jacoco</groupId> <plugin>
<artifactId>jacoco-maven-plugin</artifactId> <groupId>org.jacoco</groupId>
<version>0.8.2</version> <artifactId>jacoco-maven-plugin</artifactId>
<configuration> <version>0.8.2</version>
<excludes> <configuration>
<exclude>**/*AutoValue_*</exclude> <excludes>
<exclude>**/generated-sources/**/*</exclude> <exclude>**/*AutoValue_*</exclude>
</excludes> <exclude>**/generated-sources/**/*</exclude>
</configuration> </excludes>
<executions> </configuration>
<execution> <executions>
<id>prepare-agent</id> <execution>
<goals> <id>prepare-agent</id>
<goal>prepare-agent</goal> <goals>
</goals> <goal>prepare-agent</goal>
</execution> </goals>
<execution> </execution>
<id>report</id> <execution>
<phase>prepare-package</phase> <id>report</id>
<goals> <phase>prepare-package</phase>
<goal>report</goal> <goals>
</goals> <goal>report</goal>
</execution> </goals>
<execution> </execution>
<id>post-unit-test</id> <execution>
<phase>test</phase> <id>post-unit-test</id>
<goals> <phase>test</phase>
<goal>report</goal> <goals>
</goals> <goal>report</goal>
</execution> </goals>
</executions> </execution>
</plugin> </executions>
<plugin> </plugin>
<groupId>org.eluder.coveralls</groupId> <plugin>
<artifactId>coveralls-maven-plugin</artifactId> <groupId>org.eluder.coveralls</groupId>
<version>4.3.0</version> <artifactId>coveralls-maven-plugin</artifactId>
</plugin> <version>4.3.0</version>
</plugins> </plugin>
</build> </plugins>
</build>
</project> </project>
Expand Up @@ -23,6 +23,10 @@ final class Annotations {


private Annotations() {} private Annotations() {}



@Retention(RetentionPolicy.RUNTIME)
@Qualifier
@interface SchemaBundles {}
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Qualifier @Qualifier
@interface Mutations {} @interface Mutations {}
Expand Down
@@ -0,0 +1,24 @@
package com.google.api.graphql.rejoiner;

import com.google.auto.value.AutoValue;
import graphql.schema.DataFetcher;
import graphql.schema.GraphQLFieldDefinition;

/** A GraphQL field definition with it's data fetcher. */
@AutoValue
public abstract class FieldDefinition<T> {
abstract String parentTypeName();

abstract GraphQLFieldDefinition field();

abstract DataFetcher<T> dataFetcher();

static <T> FieldDefinition create(
String parentTypeName, GraphQLFieldDefinition field, DataFetcher<T> dataFetcher) {
return new AutoValue_FieldDefinition(parentTypeName, field, dataFetcher);
}

String fieldName() {
return field().getName();
}
}
Expand Up @@ -119,7 +119,10 @@ public Object get(DataFetchingEnvironment environment) {
return null; return null;
} }
Map<?, ?> map = (Map<?, ?>) mapValue; Map<?, ?> map = (Map<?, ?>) mapValue;
return map.entrySet().stream().map(entry -> ImmutableMap.of("key", entry.getKey(), "value", entry.getValue())).collect(toImmutableList()); return map.entrySet()
.stream()
.map(entry -> ImmutableMap.of("key", entry.getKey(), "value", entry.getValue()))
.collect(toImmutableList());
} }
if (type instanceof GraphQLEnumType) { if (type instanceof GraphQLEnumType) {
Object o = call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name)); Object o = call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
Expand All @@ -146,12 +149,12 @@ private static Object call(Object object, String methodName) {
@Override @Override
public GraphQLFieldDefinition apply(FieldDescriptor fieldDescriptor) { public GraphQLFieldDefinition apply(FieldDescriptor fieldDescriptor) {
String fieldName = fieldDescriptor.getName(); String fieldName = fieldDescriptor.getName();
String convertedFieldName = fieldName.contains("_") ? UNDERSCORE_TO_CAMEL.convert(fieldName) : fieldName; String convertedFieldName =
fieldName.contains("_") ? UNDERSCORE_TO_CAMEL.convert(fieldName) : fieldName;
GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.Builder builder =
GraphQLFieldDefinition.newFieldDefinition() GraphQLFieldDefinition.newFieldDefinition()
.type(convertType(fieldDescriptor)) .type(convertType(fieldDescriptor))
.dataFetcher( .dataFetcher(new ProtoDataFetcher(convertedFieldName))
new ProtoDataFetcher(convertedFieldName))
.name(fieldDescriptor.getJsonName()); .name(fieldDescriptor.getJsonName());
builder.description(DescriptorSet.COMMENTS.get(fieldDescriptor.getFullName())); builder.description(DescriptorSet.COMMENTS.get(fieldDescriptor.getFullName()));
if (fieldDescriptor.getOptions().hasDeprecated() if (fieldDescriptor.getOptions().hasDeprecated()
Expand Down Expand Up @@ -211,27 +214,27 @@ static GraphQLObjectType convert(Descriptor descriptor, GraphQLInterfaceType nod
.build()) .build())
.findFirst(); .findFirst();


if (relayId.isPresent()) { // if (relayId.isPresent()) {
return GraphQLObjectType.newObject() // return GraphQLObjectType.newObject()
.name(getReferenceName(descriptor)) // .name(getReferenceName(descriptor))
.withInterface(nodeInterface) // .withInterface(nodeInterface)
.field(relayId.get()) // .field(relayId.get())
.fields( // .fields(
graphQLFieldDefinitions // graphQLFieldDefinitions
.stream() // .stream()
.map( // .map(
field -> // field ->
field.getName().equals("id") // field.getName().equals("id")
? GraphQLFieldDefinition.newFieldDefinition() // ? GraphQLFieldDefinition.newFieldDefinition()
.name("rawId") // .name("rawId")
.description(field.getDescription()) // .description(field.getDescription())
.type(field.getType()) // .type(field.getType())
.dataFetcher(field.getDataFetcher()) // .dataFetcher(field.getDataFetcher())
.build() // .build()
: field) // : field)
.collect(ImmutableList.toImmutableList())) // .collect(ImmutableList.toImmutableList()))
.build(); // .build();
} // }


return GraphQLObjectType.newObject() return GraphQLObjectType.newObject()
.name(getReferenceName(descriptor)) .name(getReferenceName(descriptor))
Expand All @@ -243,7 +246,10 @@ static GraphQLObjectType convert(Descriptor descriptor, GraphQLInterfaceType nod
static GraphQLEnumType convert(EnumDescriptor descriptor) { static GraphQLEnumType convert(EnumDescriptor descriptor) {
GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum().name(getReferenceName(descriptor)); GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum().name(getReferenceName(descriptor));
for (EnumValueDescriptor value : descriptor.getValues()) { for (EnumValueDescriptor value : descriptor.getValues()) {
builder.value(value.getName(), value.getName(), DescriptorSet.COMMENTS.get(value.getFullName()), builder.value(
value.getName(),
value.getName(),
DescriptorSet.COMMENTS.get(value.getFullName()),
value.getOptions().getDeprecated() ? "deprecated in proto" : null); value.getOptions().getDeprecated() ? "deprecated in proto" : null);
} }
return builder.build(); return builder.build();
Expand Down

0 comments on commit 7d1d59d

Please sign in to comment.