Skip to content

Commit

Permalink
Merge pull request #246 from yarinvak/release/v8.0
Browse files Browse the repository at this point in the history
Release/v8.0
  • Loading branch information
yarinvak authored Jan 26, 2020
2 parents 93281c8 + 68b966f commit 7619664
Show file tree
Hide file tree
Showing 30 changed files with 543 additions and 820 deletions.
3 changes: 0 additions & 3 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Copyright 2016 Yurii Rashkovskii

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
![logo](polaris-iconsmalredl.png?raw=true)
![logo](graphql-annotations.png?raw=true)
# GraphQL-Java Annotations
[![Build Status](https://travis-ci.org/graphql-java/graphql-java-annotations.svg?branch=master)](https://travis-ci.org/graphql-java/graphql-java-annotations)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.graphql-java/graphql-java-annotations.svg?maxAge=3000)]()

[GraphQL-Java](https://github.com/andimarek/graphql-java) is a great library, but its syntax is a little bit verbose. This library offers an annotations-based
syntax for GraphQL schema definition.

If you would like to use a tool that creates a graphql spring boot server using graphql-java-annotations, you can view the [graphql-spring-annotations](https://github.com/yarinvak/graphql-spring-annotations) library.


## Table Of Contents
- [Getting Started](#getting-started)
Expand Down Expand Up @@ -35,7 +37,7 @@ syntax for GraphQL schema definition.

```groovy
dependencies {
compile "io.github.graphql-java:graphql-java-annotations:7.2.1"
compile "io.github.graphql-java:graphql-java-annotations:8.0"
}
```

Expand All @@ -45,7 +47,7 @@ dependencies {
<dependency>
<groupId>io.github.graphql-java</groupId>
<artifactId>graphql-java-annotations</artifactId>
<version>7.2.1</version>
<version>8.0</version>
</dependency>
```

Expand Down Expand Up @@ -377,7 +379,7 @@ public class HumanExtension {

## Type Inference

By default, standard GraphQL types (String, Integer, Long, Float, Boolean, Enum, List) will be inferred from Java types. Also, it will respect `@javax.validation.constraints.NotNull` annotation with respect to value's nullability, as well as `@GraphQLNonNull`
By default, standard GraphQL types (String, Integer, Long, Float, Boolean, Enum, List) will be inferred from Java types. Also, it will respect `@GraphQLNonNull` with respect to value's nullability

Stream type is also supported and treated as a list.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ gradle.projectsEvaluated {

dependencies {
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'com.graphql-java:graphql-java:13.0'
compile 'com.graphql-java:graphql-java:14.0'

// OSGi
compileOnly 'org.osgi:org.osgi.core:6.0.0'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8

version = 7.2.1
version = 8.0
Binary file added graphql-annotations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed polaris-iconsmalredl.png
Binary file not shown.
44 changes: 37 additions & 7 deletions src/main/java/graphql/annotations/AnnotationsSchemaCreator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* Copyright 2016 Yurii Rashkovskii
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -14,17 +12,23 @@
*/
package graphql.annotations;

import graphql.annotations.directives.AnnotationsDirectiveWiring;
import graphql.annotations.directives.DirectiveSchemaVisitor;
import graphql.annotations.directives.TreeTransformerUtilWrapper;
import graphql.annotations.processor.DirectiveAndWiring;
import graphql.annotations.processor.GraphQLAnnotations;
import graphql.annotations.processor.typeFunctions.TypeFunction;
import graphql.relay.Relay;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLType;
import graphql.schema.SchemaTransformer;

import java.util.HashSet;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static graphql.schema.GraphQLSchema.newSchema;

public class AnnotationsSchemaCreator {

public static Builder newAnnotationsSchema() {
Expand All @@ -43,6 +47,7 @@ public static class Builder {
private Boolean shouldAlwaysPrettify = null;
private GraphQLAnnotations graphQLAnnotations;
private GraphQLSchema.Builder graphqlSchemaBuilder;
private SchemaTransformer schemaTransformer = new SchemaTransformer();

/**
* You can set your own schema builder, but its optional
Expand Down Expand Up @@ -114,12 +119,18 @@ public Builder directives(Set<Class<?>> directiveClasses) {
return this;
}

public Builder directives(Class<?>... directiveClasses) {
this.directivesObjectList.addAll(Arrays.asList(directiveClasses));
return this;
}

/**
* Add directive declaration class to create directives for the graphql schema
*
* @param directiveContainerClass a directive container class (directives are defined as methods inside the class)
* @return the builder after adding the directive container class to the list of directive container classes
*/
public Builder directives(Class<?> directiveContainerClass){
public Builder directives(Class<?> directiveContainerClass) {
this.directiveContainerClasses.add(directiveContainerClass);
return this;
}
Expand Down Expand Up @@ -234,7 +245,7 @@ public GraphQLSchema build() {
}

Set<GraphQLDirective> directives = directivesObjectList.stream().map(dir -> graphQLAnnotations.directive(dir)).collect(Collectors.toSet());
directiveContainerClasses.forEach(dir->directives.addAll(graphQLAnnotations.directives(dir)));
directiveContainerClasses.forEach(dir -> directives.addAll(graphQLAnnotations.directives(dir)));

Set<GraphQLType> additionalTypes = additionalTypesList.stream().map(additionalType ->
additionalType.isInterface() ?
Expand All @@ -252,7 +263,26 @@ public GraphQLSchema build() {
}
this.graphqlSchemaBuilder.additionalTypes(additionalTypes).additionalType(Relay.pageInfoType)
.codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build());
return this.graphqlSchemaBuilder.build();
GraphQLSchema schema = this.graphqlSchemaBuilder.build();
// wire with directives
HashMap<String, AnnotationsDirectiveWiring> directiveWiringHashMap = transformDirectiveRegistry(this.graphQLAnnotations.getContainer().getDirectiveRegistry());
DirectiveSchemaVisitor directiveSchemaVisitor = new DirectiveSchemaVisitor(directiveWiringHashMap,
graphQLAnnotations.getContainer().getCodeRegistryBuilder(), new TreeTransformerUtilWrapper());
GraphQLSchema transformedSchema = this.schemaTransformer.transform(schema, directiveSchemaVisitor);
return newSchema(transformedSchema).codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()).build();
}

private HashMap<String, AnnotationsDirectiveWiring> transformDirectiveRegistry(Map<String, DirectiveAndWiring> directiveRegistry) {
HashMap<String, AnnotationsDirectiveWiring> map = new HashMap<>();
directiveRegistry.forEach((directiveName, directiveAndWiring) -> {
try {
map.put(directiveName, directiveAndWiring.getWiringClass().newInstance());
} catch (Exception e) {
throw new RuntimeException(e);
}
});

return map;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLDirectiveContainer;
import graphql.schema.GraphQLSchemaElement;

public interface AnnotationsWiringEnvironment {
/**
Expand All @@ -33,7 +34,7 @@ public interface AnnotationsWiringEnvironment {
*
* @return the parent name of the element
*/
String getParentName();
GraphQLSchemaElement getParentElement();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLDirectiveContainer;
import graphql.schema.GraphQLSchemaElement;

public class AnnotationsWiringEnvironmentImpl implements AnnotationsWiringEnvironment {
private final GraphQLDirectiveContainer element;
private final GraphQLDirective directive;
private final String parentName;
private final GraphQLSchemaElement parentElement;
private GraphQLCodeRegistry.Builder codeRegistryBuilder;

public AnnotationsWiringEnvironmentImpl(GraphQLDirectiveContainer element, GraphQLDirective directive,
String parentName, GraphQLCodeRegistry.Builder codeRegistryBuilder) {
GraphQLSchemaElement parentElement, GraphQLCodeRegistry.Builder codeRegistryBuilder) {
this.element = element;
this.directive = directive;
this.parentName = parentName;
this.parentElement = parentElement;
this.codeRegistryBuilder = codeRegistryBuilder;
}

Expand All @@ -43,8 +44,8 @@ public GraphQLDirective getDirective() {
}

@Override
public String getParentName() {
return parentName;
public GraphQLSchemaElement getParentElement() {
return parentElement;
}

@Override
Expand All @@ -60,7 +61,7 @@ public boolean equals(Object o) {
AnnotationsWiringEnvironmentImpl that = (AnnotationsWiringEnvironmentImpl) o;

if (element != null ? !element.equals(that.element) : that.element != null) return false;
if (parentName != null ? !parentName.equals(that.parentName) : that.parentName != null) return false;
if (parentElement != null ? !parentElement.equals(that.parentElement) : that.parentElement != null) return false;
if (codeRegistryBuilder != null ? !codeRegistryBuilder.equals(that.codeRegistryBuilder) : that.codeRegistryBuilder != null)
return false;
return directive != null ? directive.equals(that.directive) : that.directive == null;
Expand Down
Loading

0 comments on commit 7619664

Please sign in to comment.