Skip to content
Merged

V 7.0 #212

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9d6bd9e
Merge branch 'master-upstream'
yarinvak Aug 8, 2018
aec2371
Set up CI with Azure Pipelines 2
azure-pipelines[bot] Nov 20, 2018
13a1b53
Merge pull request #3 from yarinvak/azure-pipelines2
yarinvak Nov 20, 2018
ba071d8
Merge branch 'master' of https://github.com/graphql-java/graphql-java…
yarinvak Nov 22, 2018
b05ed6c
Merge remote-tracking branch 'origin/master'
yarinvak Nov 22, 2018
26968b6
Merge branch 'master' of https://github.com/graphql-java/graphql-java…
yarinvak Nov 25, 2018
140e4c1
Switched from getType() to getUnwrappedNonNullType()
richharms Nov 28, 2018
613f429
Merge pull request #201 from richharms/graphql-java-11-fix
yarinvak Dec 2, 2018
faa91e2
Merge branch 'development' of https://github.com/Enigmatis/graphql-ja…
chenshoo Feb 3, 2019
44bacec
added tests for directive on argument + input field
chenshoo Feb 5, 2019
b645d27
fix tests are working now
chenshoo Feb 6, 2019
6a5e64c
remove note
chenshoo Feb 6, 2019
0f2ed03
license
chenshoo Feb 6, 2019
64e25ec
Merge pull request #203 from yarinvak/directives-on-input
yarinvak Feb 25, 2019
f8029ff
readme prettify with logo
yarinvak Apr 17, 2019
3e4c0c5
v6.2
yarinvak Apr 17, 2019
cf27969
added toc
yarinvak Apr 17, 2019
cc1d1ac
Merge pull request #207 from yarinvak/readme-update
yarinvak Apr 17, 2019
9c112dc
check bintray release
yarinvak Apr 17, 2019
08c78de
check bintray release
yarinvak Apr 17, 2019
5903d26
check bintray release
yarinvak Apr 17, 2019
20f4bc3
true sync to maven central
yarinvak Apr 17, 2019
dd0f676
push
yarinvak Apr 17, 2019
02f173b
push
yarinvak Apr 19, 2019
8ae1e10
changed the way of handling data fetchers -> instead of wiring fields…
yarinvak Apr 20, 2019
68d0ee7
working directives wiring
yarinvak Apr 20, 2019
1ec73f3
registry builder to environment
yarinvak Apr 20, 2019
a9c49dd
Merge pull request #208 from yarinvak/bintray-release
yarinvak Apr 29, 2019
221c0eb
Added codeRegistryUtil to wrap fetchers
yarinvak Apr 29, 2019
37355bf
Fix Tests
yarinvak Apr 29, 2019
c07a960
fix tests
yarinvak Apr 29, 2019
51dc3c9
fix license format and remove GraphQLFieldDefinitionWrapper
yarinvak Apr 29, 2019
8333061
remove notes
yarinvak Apr 29, 2019
09aa67e
name change
yarinvak Apr 29, 2019
59f78b1
fix extensions
yarinvak Apr 29, 2019
868867f
When creating schema, relay PageInfo is now added as an additional type.
yarinvak Apr 29, 2019
69460c9
fix tests of simple connection and enhanced connection
yarinvak Apr 29, 2019
156da41
relay tests fixed
yarinvak Apr 29, 2019
3dbb3a6
build to gql java 12
yarinvak Apr 29, 2019
73d53b5
Merge branch 'development' of https://github.com/graphql-java/graphql…
yarinvak Apr 29, 2019
f10ee5b
fix license
yarinvak Apr 29, 2019
8dd67dd
readme fixes to comply with new PR
yarinvak Apr 29, 2019
0678b36
license
yarinvak Apr 29, 2019
5004cfd
readme
yarinvak Apr 29, 2019
0e08a7c
readme
yarinvak Apr 29, 2019
15e47b8
added tests
chenshoo Apr 30, 2019
0320eab
fix directive tests
chenshoo Apr 30, 2019
677a693
fix code review fixes
chenshoo Apr 30, 2019
6335967
fix code review
yarinvak May 8, 2019
84c738d
remove binary classes
yarinvak May 8, 2019
51774f0
Merge pull request #209 from yarinvak/graphql-java-12
yarinvak May 12, 2019
db9b740
version 7.0
DoctorVoid May 12, 2019
af891db
Merge pull request #211 from yarinvak/release/version7
yarinvak May 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 97 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
![logo](polaris-iconsmalredl.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 Annotations for Java

[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.


## Table Of Contents
- [Getting Started](#getting-started)
- [GraphQLAnnotations class](#graphqlannotations-class)
- [Annotations Schema Creator](#annotations-schema-creator)
- [Defining Objects](#defining-objects)
- [Defining Interfaces](#defining-interfaces)
- [Defining Unions](#defining-unions)
- [Fields](#fields)
- [Custom DataFetcher](#custom-data-fetcher)
- [Type Extensions](#type-extensions)
- [Defining Extensions in Annotation](#defining-extensions-in-annotations)
- [Data Fetching with Extensions](#data-fetching-with-extensions)
- [Type Inference](#type-inference)
- [Directives](#directives)
- [Creating/Defining a GraphQL Directive](#creatingdefining-a-graphqldirective)
- [Wiring with Directives](#wiring-with-directives)
- [Relay Support](#relay-support)
- [Mutations](#mutations)
- [Connection](#connection)
- [Customizing Relay Schema](#customizing-relay-schema)

## Getting Started


(Gradle syntax)

```groovy
dependencies {
compile "io.github.graphql-java:graphql-java-annotations:6.1"
compile "io.github.graphql-java:graphql-java-annotations:7.0"
}
```

Expand All @@ -22,10 +45,65 @@ dependencies {
<dependency>
<groupId>io.github.graphql-java</groupId>
<artifactId>graphql-java-annotations</artifactId>
<version>6.1</version>
<version>7.0</version>
</dependency>
```

The graphql-java-annotations library is able to create GraphQLType objects out of your Java classes.
These GraphQLType objects can be later injected into the graphql-java schema.

graphql-java-annotations also allows you to wire your objects with data fetchers and type resolvers while annotating your fields/types. The result of this process will be a ``GraphQLCodeRegistry.Builder`` object that can be later built and injected to the graphql-java schema.


## GraphQLAnnotations class

You can create an instance of the `GraphQLAnnotations` class in order to create the GraphQL types.
```java
GraphQLAnnotations graphqlAnnotations = new GraphQLAnnotations();
```

Using this object, you will be able to create the GraphQL types.
There are few types that can be generated - a `GraphQLObjectType`, a `GraphQLInterfaceType` and a `GraphQLDirective`.

```java
GraphQLObjectType query = graphqlAnnotations.object(Query.class);
GraphQLDirective upperDirective = graphqlAnnotations.directive(UpperDirective.class);
GraphQLInterfaceType myInterface = graphqlAnnotations.generateInterface(MyInterface.class);
```

Then you can use these types in order to create a graphql-java schema.
But, in order to create a graphql-java schema, you need also the ``GraphQLCodeRegistry``, which contains all the data fetchers mapped to their fields (and also type resolvers).

You can obtain the code registry this way:

```java
graphqlAnnotations.getContainer().getCodeRegistryBuilder().build();
```

## Annotations Schema Creator

Using the `GraphQLAnnotations` processor object can be a little bit confusing if you wish to use it to create a GraphQL schema.
So we created a util class to help you create your desired GraphQL schema, in a syntax similiar to the graphql-java syntax.

In order to do so you can use the ``AnnotationsSchemaCreator.Builder`` in the following way:

```java
GraphQLSchema schema = AnnotationsSchemaCreator.newAnnotationsSchema()
.query(Query.class) // to create you query object
.mutation(Mutation.class) // to create your mutation object
.subscription(Subscription.class) // to create your subscription object
.directive(UpperDirective.class) // to create a directive
.additionalType(AdditionalType.class) // to create some additional type and add it to the schema
.typeFunction(CustomType.class) // to add a typefunction
.setAlwaysPrettify(true) // to set the global prettifier of field names (removes get/set/is prefixes from names)
.setRelay(customRelay) // to add a custom relay object
.build();
```

Of course you can use this builder with only some of the properties, but the query class must be provided.
note - The GraphQLSchema is a graphql-java type.

Continue reading in order to understand how your java classes should look in order to be provided to the annotations schema creator.

## Defining Objects

Expand All @@ -39,7 +117,8 @@ public class SomeObject {
}

// ...
GraphQLObjectType object = GraphQLAnnotations.object(SomeObject.class);
GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations();
GraphQLObjectType object = graphQLAnnotations.object(SomeObject.class);
```

## Defining Interfaces
Expand All @@ -58,7 +137,8 @@ public class MyTypeResolver implements TypeResolver {
}

// ...
GraphQLInterfaceType object = GraphQLAnnotations.iface(SomeInterface.class);
GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations();
GraphQLInterfaceType object = graphQLAnnotations.generateInterface(SomeInterface.class);
```

An instance of the type resolver will be created from the specified class. If a `getInstance` method is present on the
Expand Down Expand Up @@ -262,13 +342,11 @@ public class HumanExtension {
Classes marked as "extensions" will actually not define a new type, but rather set new fields on the class it extends when it will be created.
All GraphQL annotations can be used on extension classes.

Extensions are registered in GraphQLAnnotationProcessor by using `registerTypeExtension`. Note that extensions must be registered before the type itself is requested with `getObject()` :
Extensions are registered in GraphQLAnnotations object by using `registerTypeExtension`. Note that extensions must be registered before the type itself is requested with `getObject()` :

```
GraphQLAnnotationsProcessor processor = GraphQLAnnotations.getInstance();

// Register extensions
processor.registerTypeExtension(HumanExtension.class);
graphqlAnnotations.registerTypeExtension(HumanExtension.class);

// Create type
GraphQLObjectType type = processor.getObject(Human.class);
Expand Down Expand Up @@ -314,7 +392,7 @@ public class UUIDTypeFunction implements TypeFunction {
And register it with `GraphQLAnnotations`:

```java
GraphQLAnnotations.register(new UUIDTypeFunction())
graphqlAnnotations.registerType(new UUIDTypeFunction())

// or if not using a static version of GraphQLAnnotations:
// new GraphQLAnnotations().registerType(new UUIDTypeFunction())
Expand Down Expand Up @@ -348,7 +426,7 @@ You can also use ``@GraphQLName`` and ``@GraphQLDescription`` annotations on the

After you created the class, you will be able to create the ``GraphQLDirective`` object using the following code:
```java
GraphQLAnnotations.directive(UpperDirective.class);
graphqlAnnotations.directive(UpperDirective.class);
```

### Wiring with directives
Expand All @@ -361,16 +439,19 @@ public class UpperWiring implements AnnotationsDirectiveWiring {
public GraphQLFieldDefinition onField(AnnotationsWiringEnvironment environment) {
GraphQLFieldDefinition field = (GraphQLFieldDefinition) environment.getElement();
boolean isActive = (boolean) environment.getDirective().getArgument("isActive").getValue();
DataFetcher dataFetcher = DataFetcherFactories.wrapDataFetcher(field.getDataFetcher(), (((dataFetchingEnvironment, value) -> {
CodeRegistryUtil.wrapDataFetcher(field, environment, (((dataFetchingEnvironment, value) -> {
if (value instanceof String && isActive) {
return ((String) value).toUpperCase();
}
return value;
})));
return field.transform(builder -> builder.dataFetcher(dataFetcher));
return value;
})));
return field;
}
}
```

You can also use the `field.transform` method in order to change some of the field's properties.

This class turns your string field to upper case if the directive argument "isActive" is set to true.
Now, you have to wire the field itself:
```java
Expand Down Expand Up @@ -410,7 +491,7 @@ NOTE: because `PropertyDataFetcher` and `FieldDataFetcher` can't handle connecti
### Customizing Relay schema

By default, GraphQLAnnotations will use the `graphql.relay.Relay` class to create the Relay specific schema types (Mutations, Connections, Edges, PageInfo, ...).
It is possible to set a custom implementation of the Relay class with `GraphQLAnnotations.setRelay` method. The class should inherit from `graphql.relay.Relay` and
It is possible to set a custom implementation of the Relay class with `graphqlAnnotations.setRelay` method. The class should inherit from `graphql.relay.Relay` and
can redefine methods that create Relay types.

It is also possible to specify for every connection which relay do you want to use, by giving a value to the annotation:
Expand Down
13 changes: 5 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}

idea {
project {
languageLevel = '1.8'
vcs = 'Git'
}
}
release {
tagTemplate = 'v${version}'
failOnPublishNeeded = false
Expand All @@ -69,7 +63,7 @@ gradle.projectsEvaluated {

dependencies {
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'com.graphql-java:graphql-java:11.0'
compile 'com.graphql-java:graphql-java:12.0'

// OSGi
compileOnly 'org.osgi:org.osgi.core:6.0.0'
Expand Down Expand Up @@ -169,8 +163,11 @@ bintray {
version {
name = project.version
released = new Date()
gpg {
sign = false
}
mavenCentralSync {
sync = true //[Default: true] Determines whether to sync the version to Maven Central.
sync = true //[Default: true] Determines whether to sync the version to Maven Central..
user = System.getenv('OSS_USER') ?: project.findProperty('OSS_USER') ?: ''
password = System.getenv('OSS_PASS') ?: project.findProperty('OSS_PASS') ?: ''
close = '1'
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 = 6.2
version = 7.0
Binary file added polaris-iconsmalredl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading