Skip to content

Commit 7619664

Browse files
authored
Merge pull request #246 from yarinvak/release/v8.0
Release/v8.0
2 parents 93281c8 + 68b966f commit 7619664

30 files changed

+543
-820
lines changed

.travis.yml

-3
This file was deleted.

LICENSE

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
Copyright 2016 Yurii Rashkovskii
2-
31
Licensed under the Apache License, Version 2.0 (the "License");
42
you may not use this file except in compliance with the License.
53
You may obtain a copy of the License at

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
![logo](polaris-iconsmalredl.png?raw=true)
1+
![logo](graphql-annotations.png?raw=true)
22
# GraphQL-Java Annotations
33
[![Build Status](https://travis-ci.org/graphql-java/graphql-java-annotations.svg?branch=master)](https://travis-ci.org/graphql-java/graphql-java-annotations)
44
[![Maven Central](https://img.shields.io/maven-central/v/io.github.graphql-java/graphql-java-annotations.svg?maxAge=3000)]()
55

66
[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
77
syntax for GraphQL schema definition.
88

9+
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.
10+
911

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

3638
```groovy
3739
dependencies {
38-
compile "io.github.graphql-java:graphql-java-annotations:7.2.1"
40+
compile "io.github.graphql-java:graphql-java-annotations:8.0"
3941
}
4042
```
4143

@@ -45,7 +47,7 @@ dependencies {
4547
<dependency>
4648
<groupId>io.github.graphql-java</groupId>
4749
<artifactId>graphql-java-annotations</artifactId>
48-
<version>7.2.1</version>
50+
<version>8.0</version>
4951
</dependency>
5052
```
5153

@@ -377,7 +379,7 @@ public class HumanExtension {
377379

378380
## Type Inference
379381

380-
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`
382+
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
381383

382384
Stream type is also supported and treated as a list.
383385

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ gradle.projectsEvaluated {
6363

6464
dependencies {
6565
compile 'javax.validation:validation-api:1.1.0.Final'
66-
compile 'com.graphql-java:graphql-java:13.0'
66+
compile 'com.graphql-java:graphql-java:14.0'
6767

6868
// OSGi
6969
compileOnly 'org.osgi:org.osgi.core:6.0.0'

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ org.gradle.daemon=true
55
org.gradle.parallel=true
66
org.gradle.jvmargs=-Dfile.encoding=UTF-8
77

8-
version = 7.2.1
8+
version = 8.0

graphql-annotations.png

7.93 KB
Loading

polaris-iconsmalredl.png

-10.6 KB
Binary file not shown.

src/main/java/graphql/annotations/AnnotationsSchemaCreator.java

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/**
2-
* Copyright 2016 Yurii Rashkovskii
3-
*
42
* Licensed under the Apache License, Version 2.0 (the "License");
53
* you may not use this file except in compliance with the License.
64
* You may obtain a copy of the License at
@@ -14,17 +12,23 @@
1412
*/
1513
package graphql.annotations;
1614

15+
import graphql.annotations.directives.AnnotationsDirectiveWiring;
16+
import graphql.annotations.directives.DirectiveSchemaVisitor;
17+
import graphql.annotations.directives.TreeTransformerUtilWrapper;
18+
import graphql.annotations.processor.DirectiveAndWiring;
1719
import graphql.annotations.processor.GraphQLAnnotations;
1820
import graphql.annotations.processor.typeFunctions.TypeFunction;
1921
import graphql.relay.Relay;
2022
import graphql.schema.GraphQLDirective;
2123
import graphql.schema.GraphQLSchema;
2224
import graphql.schema.GraphQLType;
25+
import graphql.schema.SchemaTransformer;
2326

24-
import java.util.HashSet;
25-
import java.util.Set;
27+
import java.util.*;
2628
import java.util.stream.Collectors;
2729

30+
import static graphql.schema.GraphQLSchema.newSchema;
31+
2832
public class AnnotationsSchemaCreator {
2933

3034
public static Builder newAnnotationsSchema() {
@@ -43,6 +47,7 @@ public static class Builder {
4347
private Boolean shouldAlwaysPrettify = null;
4448
private GraphQLAnnotations graphQLAnnotations;
4549
private GraphQLSchema.Builder graphqlSchemaBuilder;
50+
private SchemaTransformer schemaTransformer = new SchemaTransformer();
4651

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

122+
public Builder directives(Class<?>... directiveClasses) {
123+
this.directivesObjectList.addAll(Arrays.asList(directiveClasses));
124+
return this;
125+
}
126+
117127
/**
118128
* Add directive declaration class to create directives for the graphql schema
129+
*
119130
* @param directiveContainerClass a directive container class (directives are defined as methods inside the class)
120131
* @return the builder after adding the directive container class to the list of directive container classes
121132
*/
122-
public Builder directives(Class<?> directiveContainerClass){
133+
public Builder directives(Class<?> directiveContainerClass) {
123134
this.directiveContainerClasses.add(directiveContainerClass);
124135
return this;
125136
}
@@ -234,7 +245,7 @@ public GraphQLSchema build() {
234245
}
235246

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

239250
Set<GraphQLType> additionalTypes = additionalTypesList.stream().map(additionalType ->
240251
additionalType.isInterface() ?
@@ -252,7 +263,26 @@ public GraphQLSchema build() {
252263
}
253264
this.graphqlSchemaBuilder.additionalTypes(additionalTypes).additionalType(Relay.pageInfoType)
254265
.codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build());
255-
return this.graphqlSchemaBuilder.build();
266+
GraphQLSchema schema = this.graphqlSchemaBuilder.build();
267+
// wire with directives
268+
HashMap<String, AnnotationsDirectiveWiring> directiveWiringHashMap = transformDirectiveRegistry(this.graphQLAnnotations.getContainer().getDirectiveRegistry());
269+
DirectiveSchemaVisitor directiveSchemaVisitor = new DirectiveSchemaVisitor(directiveWiringHashMap,
270+
graphQLAnnotations.getContainer().getCodeRegistryBuilder(), new TreeTransformerUtilWrapper());
271+
GraphQLSchema transformedSchema = this.schemaTransformer.transform(schema, directiveSchemaVisitor);
272+
return newSchema(transformedSchema).codeRegistry(graphQLAnnotations.getContainer().getCodeRegistryBuilder().build()).build();
273+
}
274+
275+
private HashMap<String, AnnotationsDirectiveWiring> transformDirectiveRegistry(Map<String, DirectiveAndWiring> directiveRegistry) {
276+
HashMap<String, AnnotationsDirectiveWiring> map = new HashMap<>();
277+
directiveRegistry.forEach((directiveName, directiveAndWiring) -> {
278+
try {
279+
map.put(directiveName, directiveAndWiring.getWiringClass().newInstance());
280+
} catch (Exception e) {
281+
throw new RuntimeException(e);
282+
}
283+
});
284+
285+
return map;
256286
}
257287
}
258288
}

src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironment.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import graphql.schema.GraphQLCodeRegistry;
1818
import graphql.schema.GraphQLDirective;
1919
import graphql.schema.GraphQLDirectiveContainer;
20+
import graphql.schema.GraphQLSchemaElement;
2021

2122
public interface AnnotationsWiringEnvironment {
2223
/**
@@ -33,7 +34,7 @@ public interface AnnotationsWiringEnvironment {
3334
*
3435
* @return the parent name of the element
3536
*/
36-
String getParentName();
37+
GraphQLSchemaElement getParentElement();
3738

3839

3940
/**

src/main/java/graphql/annotations/directives/AnnotationsWiringEnvironmentImpl.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
import graphql.schema.GraphQLCodeRegistry;
1818
import graphql.schema.GraphQLDirective;
1919
import graphql.schema.GraphQLDirectiveContainer;
20+
import graphql.schema.GraphQLSchemaElement;
2021

2122
public class AnnotationsWiringEnvironmentImpl implements AnnotationsWiringEnvironment {
2223
private final GraphQLDirectiveContainer element;
2324
private final GraphQLDirective directive;
24-
private final String parentName;
25+
private final GraphQLSchemaElement parentElement;
2526
private GraphQLCodeRegistry.Builder codeRegistryBuilder;
2627

2728
public AnnotationsWiringEnvironmentImpl(GraphQLDirectiveContainer element, GraphQLDirective directive,
28-
String parentName, GraphQLCodeRegistry.Builder codeRegistryBuilder) {
29+
GraphQLSchemaElement parentElement, GraphQLCodeRegistry.Builder codeRegistryBuilder) {
2930
this.element = element;
3031
this.directive = directive;
31-
this.parentName = parentName;
32+
this.parentElement = parentElement;
3233
this.codeRegistryBuilder = codeRegistryBuilder;
3334
}
3435

@@ -43,8 +44,8 @@ public GraphQLDirective getDirective() {
4344
}
4445

4546
@Override
46-
public String getParentName() {
47-
return parentName;
47+
public GraphQLSchemaElement getParentElement() {
48+
return parentElement;
4849
}
4950

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

6263
if (element != null ? !element.equals(that.element) : that.element != null) return false;
63-
if (parentName != null ? !parentName.equals(that.parentName) : that.parentName != null) return false;
64+
if (parentElement != null ? !parentElement.equals(that.parentElement) : that.parentElement != null) return false;
6465
if (codeRegistryBuilder != null ? !codeRegistryBuilder.equals(that.codeRegistryBuilder) : that.codeRegistryBuilder != null)
6566
return false;
6667
return directive != null ? directive.equals(that.directive) : that.directive == null;

0 commit comments

Comments
 (0)