Skip to content

Commit d6c6176

Browse files
authored
Merge branch 'master' into timward/custom-handler-resolver-new
2 parents 49cd00f + 0b2a3a5 commit d6c6176

File tree

16 files changed

+428
-179
lines changed

16 files changed

+428
-179
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Question
4-
url: https://spectrum.chat/graphql-java-kick
5-
about: Anything you are not sure about? Ask the community on Spectrum!
4+
url: https://github.com/graphql-java-kickstart/graphql-java-tools/discussions
5+
about: Anything you are not sure about? Ask the community!

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![TravisCI Build](https://travis-ci.org/graphql-java-kickstart/graphql-java-tools.svg?branch=master)](https://travis-ci.org/graphql-java-kickstart/graphql-java-tools)
44
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.graphql-java-kickstart/graphql-java-tools/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.graphql-java-kickstart/graphql-java-tools)
5-
[![Chat on Spectrum](https://img.shields.io/badge/spectrum-join%20the%20community-%23800080)](https://spectrum.chat/graphql-java-kick)
5+
[![Discuss on GitHub](https://img.shields.io/badge/GitHub-discuss-orange)](https://github.com/graphql-java-kickstart/graphql-java-tools/discussions)
66

77
This library allows you to use the GraphQL schema language to build your [graphql-java](https://github.com/graphql-java/graphql-java) schema.
88
Inspired by [graphql-tools](https://github.com/apollographql/graphql-tools), it parses the given GraphQL schema and allows you to BYOO (bring your own object) to fill in the implementations.
@@ -11,9 +11,10 @@ GraphQL Java Tools works well if you already have domain POJOs that hold your da
1111
GraphQL Java Tools aims for seamless integration with Java, but works for any JVM language. Try it with Kotlin!
1212

1313
## We are looking for contributors!
14+
1415
Are you interested in improving our documentation, working on the codebase, reviewing PRs?
1516

16-
[Reach out to us on Spectrum](https://spectrum.chat/graphql-java-kick) and join the team!
17+
[Reach out to us on GitHub](https://github.com/graphql-java-kickstart/graphql-java-tools/discussions) and join the team!
1718

1819
## Quick start
1920

@@ -25,7 +26,7 @@ kotlin.version=1.3.70
2526

2627
Add the dependency:
2728
```groovy
28-
compile 'com.graphql-java-kickstart:graphql-java-tools:6.2.0'
29+
compile 'com.graphql-java-kickstart:graphql-java-tools:11.0.0'
2930
```
3031

3132
### Using Maven
@@ -41,7 +42,7 @@ Add the dependency:
4142
<dependency>
4243
<groupId>com.graphql-java-kickstart</groupId>
4344
<artifactId>graphql-java-tools</artifactId>
44-
<version>6.2.0</version>
45+
<version>11.0.0</version>
4546
</dependency>
4647
```
4748

pom.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.graphql-java-kickstart</groupId>
66
<artifactId>graphql-java-tools</artifactId>
7-
<version>6.2.1-SNAPSHOT</version>
7+
<version>11.0.1-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>GraphQL Java Tools</name>
@@ -17,14 +17,25 @@
1717
<kotlin.version>1.3.72</kotlin.version>
1818
<kotlin-coroutines.version>1.3.9</kotlin-coroutines.version>
1919
<jackson.version>2.10.3</jackson.version>
20-
<graphql-java.version>15.0</graphql-java.version>
20+
<graphql-java.version>16.1</graphql-java.version>
2121

2222
<maven.compiler.source>${java.version}</maven.compiler.source>
2323
<maven.compiler.target>${java.version}</maven.compiler.target>
2424
<useReleaseProfile>false</useReleaseProfile>
2525
<project.scm.id>github</project.scm.id>
2626
</properties>
2727

28+
<dependencyManagement>
29+
<dependencies>
30+
<!-- graphql-java defines this dependency as 'runtime', but we need it at compile time -->
31+
<dependency>
32+
<groupId>org.antlr</groupId>
33+
<artifactId>antlr4-runtime</artifactId>
34+
<scope>compile</scope>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
2839
<dependencies>
2940
<dependency>
3041
<groupId>org.jetbrains.kotlin</groupId>
@@ -112,7 +123,7 @@
112123
<dependency>
113124
<groupId>org.slf4j</groupId>
114125
<artifactId>slf4j-api</artifactId>
115-
<version>1.7.25</version>
126+
<version>1.7.30</version>
116127
</dependency>
117128

118129
<!-- Optional for supporting spring proxies -->

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import graphql.language.*
1010
import graphql.schema.*
1111
import graphql.schema.idl.RuntimeWiring
1212
import graphql.schema.idl.ScalarInfo
13-
import graphql.schema.idl.SchemaGeneratorHelper
13+
import graphql.schema.idl.SchemaGeneratorHelperExt
1414
import graphql.schema.visibility.NoIntrospectionGraphqlFieldVisibility
1515
import org.slf4j.LoggerFactory
1616
import kotlin.reflect.KClass
@@ -58,7 +58,7 @@ class SchemaParser internal constructor(
5858

5959
private val codeRegistryBuilder = GraphQLCodeRegistry.newCodeRegistry()
6060

61-
private val schemaGeneratorHelper = SchemaGeneratorHelper()
61+
private val schemaGeneratorHelper = SchemaGeneratorHelperExt()
6262
private val schemaGeneratorDirectiveHelper = SchemaGeneratorDirectiveHelper()
6363
private val schemaDirectiveParameters = SchemaGeneratorDirectiveHelper.Parameters(null, runtimeWiring, null, codeRegistryBuilder)
6464

@@ -76,7 +76,7 @@ class SchemaParser internal constructor(
7676
val inputObjects: MutableList<GraphQLInputObjectType> = mutableListOf()
7777
inputObjectDefinitions.forEach {
7878
if (inputObjects.none { io -> io.name == it.name }) {
79-
inputObjects.add(createInputObject(it, inputObjects))
79+
inputObjects.add(createInputObject(it, inputObjects, mutableSetOf()))
8080
}
8181
}
8282
val interfaces = interfaceDefinitions.map { createInterfaceObject(it, inputObjects) }
@@ -155,7 +155,8 @@ class SchemaParser internal constructor(
155155
return schemaGeneratorDirectiveHelper.onObject(objectType, directiveHelperParameters)
156156
}
157157

158-
private fun createInputObject(definition: InputObjectTypeDefinition, inputObjects: List<GraphQLInputObjectType>): GraphQLInputObjectType {
158+
private fun createInputObject(definition: InputObjectTypeDefinition, inputObjects: List<GraphQLInputObjectType>,
159+
referencingInputObjects: MutableSet<String>): GraphQLInputObjectType {
159160
val extensionDefinitions = inputExtensionDefinitions.filter { it.name == definition.name }
160161

161162
val builder = GraphQLInputObjectType.newInputObject()
@@ -166,14 +167,16 @@ class SchemaParser internal constructor(
166167

167168
builder.withDirectives(*buildDirectives(definition.directives, Introspection.DirectiveLocation.INPUT_OBJECT))
168169

170+
referencingInputObjects.add(definition.name)
171+
169172
(extensionDefinitions + definition).forEach {
170173
it.inputValueDefinitions.forEach { inputDefinition ->
171174
val fieldBuilder = GraphQLInputObjectField.newInputObjectField()
172175
.name(inputDefinition.name)
173176
.definition(inputDefinition)
174177
.description(if (inputDefinition.description != null) inputDefinition.description.content else getDocumentation(inputDefinition))
175178
.defaultValue(buildDefaultValue(inputDefinition.defaultValue))
176-
.type(determineInputType(inputDefinition.type, inputObjects))
179+
.type(determineInputType(inputDefinition.type, inputObjects, referencingInputObjects))
177180
.withDirectives(*buildDirectives(inputDefinition.directives, Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION))
178181
builder.field(fieldBuilder.build())
179182
}
@@ -280,7 +283,7 @@ class SchemaParser internal constructor(
280283
.name(argumentDefinition.name)
281284
.definition(argumentDefinition)
282285
.description(if (argumentDefinition.description != null) argumentDefinition.description.content else getDocumentation(argumentDefinition))
283-
.type(determineInputType(argumentDefinition.type, inputObjects))
286+
.type(determineInputType(argumentDefinition.type, inputObjects, setOf()))
284287
.apply { buildDefaultValue(argumentDefinition.defaultValue)?.let { defaultValue(it) } }
285288
.withDirectives(*buildDirectives(argumentDefinition.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION))
286289

@@ -311,7 +314,7 @@ class SchemaParser internal constructor(
311314
.build()
312315

313316

314-
output.add(schemaGeneratorHelper.buildDirective(directive, setOf(graphQLDirective), directiveLocation, runtimeWiring.comparatorRegistry))
317+
output.add(schemaGeneratorHelper.buildDirective(directive, graphQLDirective, directiveLocation, runtimeWiring.comparatorRegistry))
315318
}
316319
}
317320

@@ -360,8 +363,8 @@ class SchemaParser internal constructor(
360363
private fun buildDefaultValue(value: Value<*>?): Any? {
361364
return when (value) {
362365
null -> null
363-
is IntValue -> value.value
364-
is FloatValue -> value.value
366+
is IntValue -> value.value.toInt()
367+
is FloatValue -> value.value.toDouble()
365368
is StringValue -> value.value
366369
is EnumValue -> value.name
367370
is BooleanValue -> value.isValue
@@ -380,7 +383,7 @@ class SchemaParser internal constructor(
380383
is NonNullType -> GraphQLNonNull(determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects))
381384
is InputObjectTypeDefinition -> {
382385
log.info("Create input object")
383-
createInputObject(typeDefinition, inputObjects)
386+
createInputObject(typeDefinition, inputObjects, mutableSetOf())
384387
}
385388
is TypeName -> {
386389
val scalarType = customScalars[typeDefinition.name]
@@ -398,16 +401,19 @@ class SchemaParser internal constructor(
398401
else -> throw SchemaError("Unknown type: $typeDefinition")
399402
}
400403

401-
private fun determineInputType(typeDefinition: Type<*>, inputObjects: List<GraphQLInputObjectType>) =
402-
determineInputType(GraphQLInputType::class, typeDefinition, permittedTypesForInputObject, inputObjects) as GraphQLInputType
404+
private fun determineInputType(typeDefinition: Type<*>, inputObjects: List<GraphQLInputObjectType>, referencingInputObjects: Set<String>) =
405+
determineInputType(GraphQLInputType::class, typeDefinition, permittedTypesForInputObject, inputObjects, referencingInputObjects) as GraphQLInputType
403406

404-
private fun <T : Any> determineInputType(expectedType: KClass<T>, typeDefinition: Type<*>, allowedTypeReferences: Set<String>, inputObjects: List<GraphQLInputObjectType>): GraphQLType =
407+
private fun <T : Any> determineInputType(expectedType: KClass<T>,
408+
typeDefinition: Type<*>, allowedTypeReferences: Set<String>,
409+
inputObjects: List<GraphQLInputObjectType>,
410+
referencingInputObjects: Set<String>): GraphQLType =
405411
when (typeDefinition) {
406412
is ListType -> GraphQLList(determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects))
407413
is NonNullType -> GraphQLNonNull(determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects))
408414
is InputObjectTypeDefinition -> {
409415
log.info("Create input object")
410-
createInputObject(typeDefinition, inputObjects)
416+
createInputObject(typeDefinition, inputObjects, referencingInputObjects as MutableSet<String>)
411417
}
412418
is TypeName -> {
413419
val scalarType = customScalars[typeDefinition.name]
@@ -425,9 +431,14 @@ class SchemaParser internal constructor(
425431
} else {
426432
val filteredDefinitions = inputObjectDefinitions.filter { it.name == typeDefinition.name }
427433
if (filteredDefinitions.isNotEmpty()) {
428-
val inputObject = createInputObject(filteredDefinitions[0], inputObjects)
429-
(inputObjects as MutableList).add(inputObject)
430-
inputObject
434+
val referencingInputObject = referencingInputObjects.find { it == typeDefinition.name }
435+
if (referencingInputObject != null) {
436+
GraphQLTypeReference(referencingInputObject)
437+
} else {
438+
val inputObject = createInputObject(filteredDefinitions[0], inputObjects, referencingInputObjects as MutableSet<String>)
439+
(inputObjects as MutableList).add(inputObject)
440+
inputObject
441+
}
431442
} else {
432443
// todo: handle enum type
433444
GraphQLTypeReference(typeDefinition.name)

src/main/kotlin/graphql/kickstart/tools/directive/SchemaDirectiveWiringEnvironmentImpl.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
import graphql.Internal;
44
import graphql.language.NamedNode;
55
import graphql.language.NodeParentTree;
6-
import graphql.schema.*;
6+
import graphql.schema.DataFetcher;
7+
import graphql.schema.FieldCoordinates;
8+
import graphql.schema.GraphQLCodeRegistry;
9+
import graphql.schema.GraphQLDirective;
10+
import graphql.schema.GraphQLDirectiveContainer;
11+
import graphql.schema.GraphQLFieldDefinition;
12+
import graphql.schema.GraphQLFieldsContainer;
13+
import graphql.schema.GraphqlElementParentTree;
714
import graphql.schema.idl.SchemaDirectiveWiringEnvironment;
815
import graphql.schema.idl.TypeDefinitionRegistry;
916
import graphql.util.FpKit;
@@ -17,14 +24,14 @@
1724
/*
1825
* DO NOT EDIT THIS FILE!
1926
*
20-
* File copied from com.graphql-java.graphql-java:15.0 without any changes.
27+
* File copied from com.graphql-java.graphql-java:16.1 without any changes.
2128
*/
2229
@Internal
2330
public class SchemaDirectiveWiringEnvironmentImpl<T extends GraphQLDirectiveContainer> implements SchemaDirectiveWiringEnvironment<T> {
2431

2532
private final T element;
2633
private final Map<String, GraphQLDirective> directives;
27-
private final NodeParentTree<NamedNode> nodeParentTree;
34+
private final NodeParentTree<NamedNode<?>> nodeParentTree;
2835
private final TypeDefinitionRegistry typeDefinitionRegistry;
2936
private final Map<String, Object> context;
3037
private final GraphQLCodeRegistry.Builder codeRegistry;
@@ -33,12 +40,7 @@ public class SchemaDirectiveWiringEnvironmentImpl<T extends GraphQLDirectiveCont
3340
private final GraphQLFieldDefinition fieldDefinition;
3441
private final GraphQLDirective registeredDirective;
3542

36-
public SchemaDirectiveWiringEnvironmentImpl(
37-
T element,
38-
List<GraphQLDirective> directives,
39-
GraphQLDirective registeredDirective,
40-
SchemaGeneratorDirectiveHelper.Parameters parameters
41-
) {
43+
public SchemaDirectiveWiringEnvironmentImpl(T element, List<GraphQLDirective> directives, GraphQLDirective registeredDirective, SchemaGeneratorDirectiveHelper.Parameters parameters) {
4244
this.element = element;
4345
this.registeredDirective = registeredDirective;
4446
this.typeDefinitionRegistry = parameters.getTypeRegistry();
@@ -77,7 +79,7 @@ public boolean containsDirective(String directiveName) {
7779
}
7880

7981
@Override
80-
public NodeParentTree<NamedNode> getNodeParentTree() {
82+
public NodeParentTree<NamedNode<?>> getNodeParentTree() {
8183
return nodeParentTree;
8284
}
8385

@@ -112,14 +114,14 @@ public GraphQLFieldDefinition getFieldDefinition() {
112114
}
113115

114116
@Override
115-
public DataFetcher getFieldDataFetcher() {
117+
public DataFetcher<?> getFieldDataFetcher() {
116118
assertNotNull(fieldDefinition, () -> "An output field must be in context to call this method");
117119
assertNotNull(fieldsContainer, () -> "An output field container must be in context to call this method");
118120
return codeRegistry.getDataFetcher(fieldsContainer, fieldDefinition);
119121
}
120122

121123
@Override
122-
public GraphQLFieldDefinition setFieldDataFetcher(DataFetcher newDataFetcher) {
124+
public GraphQLFieldDefinition setFieldDataFetcher(DataFetcher<?> newDataFetcher) {
123125
assertNotNull(fieldDefinition, () -> "An output field must be in context to call this method");
124126
assertNotNull(fieldsContainer, () -> "An output field container must be in context to call this method");
125127

0 commit comments

Comments
 (0)