From 506973864af8ef471c48e25be475145e98d283e6 Mon Sep 17 00:00:00 2001 From: Andrew Kerr Date: Thu, 22 Sep 2022 09:47:47 -0400 Subject: [PATCH 01/10] Remove double throw --- src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt index 5d529d2d..fd445ff9 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaClassScanner.kt @@ -263,7 +263,7 @@ internal class SchemaClassScanner( resolverInfosByDataClass[item.clazz] ?: DataClassResolverInfo(item.clazz) } }) - ?: throw throw SchemaClassScannerError("The GraphQL schema type '${item.type.name}' maps to a field of type java.lang.Object however there is no matching entry for this type in the type dictionary. You may need to add this type to the dictionary before building the schema.") + ?: throw SchemaClassScannerError("The GraphQL schema type '${item.type.name}' maps to a field of type java.lang.Object however there is no matching entry for this type in the type dictionary. You may need to add this type to the dictionary before building the schema.") scanResolverInfoForPotentialMatches(item.type, resolverInfo) } From 6da5272f457fac0d429bf64e216f0fc3b7b26c68 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 23 Sep 2022 20:18:20 +0000 Subject: [PATCH 02/10] Update all non-major dependencies --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 5e33f4d6..91f0a8d0 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ org.slf4j slf4j-api - 2.0.0 + 2.0.2 org.apache.commons @@ -80,14 +80,14 @@ org.javassist javassist - 3.29.1-GA + 3.29.2-GA provided org.springframework spring-aop - 5.3.22 + 5.3.23 provided @@ -100,7 +100,7 @@ ch.qos.logback logback-classic - 1.3.0 + 1.3.1 javax.servlet @@ -304,7 +304,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.2.2 + 3.3.0 test-jar From 778a45ea3f3a12288cb589cb53fb5f98d71ed2a0 Mon Sep 17 00:00:00 2001 From: Oryan M Date: Mon, 26 Sep 2022 09:22:56 -0400 Subject: [PATCH 03/10] Refactor --- .../graphql/kickstart/tools/SchemaParser.kt | 179 +++++++++--------- 1 file changed, 92 insertions(+), 87 deletions(-) diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt index 294c3f03..1f1d3f4e 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt @@ -122,28 +122,30 @@ class SchemaParser internal constructor( .definition(objectDefinition) .description(getDocumentation(objectDefinition, options)) .withAppliedDirectives(*buildAppliedDirectives(objectDefinition.directives)) - - objectDefinition.implements.forEach { implementsDefinition -> - val interfaceName = (implementsDefinition as TypeName).name - builder.withInterface(interfaces.find { it.name == interfaceName } - ?: throw SchemaError("Expected interface type with name '$interfaceName' but found none!")) - } - - objectDefinition.getExtendedFieldDefinitions(extensionDefinitions).forEach { fieldDefinition -> - builder.field { field -> - createField(field, fieldDefinition, inputObjects) - codeRegistryBuilder.dataFetcher( - FieldCoordinates.coordinates(objectDefinition.name, fieldDefinition.name), - fieldResolversByType[objectDefinition]?.get(fieldDefinition)?.createDataFetcher() - ?: throw SchemaError("No resolver method found for object type '${objectDefinition.name}' and field '${fieldDefinition.name}', this is most likely a bug with graphql-java-tools") - ) - - val wiredField = field.build() - GraphQLFieldDefinition.Builder(wiredField) - .clearArguments() - .arguments(wiredField.arguments) + .apply { + objectDefinition.implements.forEach { implementsDefinition -> + val interfaceName = (implementsDefinition as TypeName).name + withInterface(interfaces.find { it.name == interfaceName } + ?: throw SchemaError("Expected interface type with name '$interfaceName' but found none!")) + } + } + .apply { + objectDefinition.getExtendedFieldDefinitions(extensionDefinitions).forEach { fieldDefinition -> + field { field -> + createField(field, fieldDefinition, inputObjects) + codeRegistryBuilder.dataFetcher( + FieldCoordinates.coordinates(objectDefinition.name, fieldDefinition.name), + fieldResolversByType[objectDefinition]?.get(fieldDefinition)?.createDataFetcher() + ?: throw SchemaError("No resolver method found for object type '${objectDefinition.name}' and field '${fieldDefinition.name}', this is most likely a bug with graphql-java-tools") + ) + + val wiredField = field.build() + GraphQLFieldDefinition.Builder(wiredField) + .clearArguments() + .arguments(wiredField.arguments) + } + } } - } return directiveWiringHelper.wireObject(builder.build()) } @@ -152,28 +154,31 @@ class SchemaParser internal constructor( referencingInputObjects: MutableSet): GraphQLInputObjectType { val extensionDefinitions = inputExtensionDefinitions.filter { it.name == definition.name } + referencingInputObjects.add(definition.name) + val builder = GraphQLInputObjectType.newInputObject() .name(definition.name) .definition(definition) .extensionDefinitions(extensionDefinitions) .description(getDocumentation(definition, options)) .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) - - referencingInputObjects.add(definition.name) - - (extensionDefinitions + definition).forEach { - it.inputValueDefinitions.forEach { inputDefinition -> - val fieldBuilder = GraphQLInputObjectField.newInputObjectField() - .name(inputDefinition.name) - .definition(inputDefinition) - .description(getDocumentation(inputDefinition, options)) - .apply { inputDefinition.defaultValue?.let { v -> defaultValueLiteral(v) } } - .apply { getDeprecated(inputDefinition.directives)?.let { deprecate(it) } } - .type(determineInputType(inputDefinition.type, inputObjects, referencingInputObjects)) - .withAppliedDirectives(*buildAppliedDirectives(inputDefinition.directives)) - builder.field(fieldBuilder.build()) + .apply { + (extensionDefinitions + definition).forEach { typeDefinition -> + typeDefinition.inputValueDefinitions.forEach { fieldDefinition -> + field( + GraphQLInputObjectField.newInputObjectField() + .name(fieldDefinition.name) + .definition(fieldDefinition) + .description(getDocumentation(fieldDefinition, options)) + .apply { fieldDefinition.defaultValue?.let { v -> defaultValueLiteral(v) } } + .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } } + .type(determineInputType(fieldDefinition.type, inputObjects, referencingInputObjects)) + .withAppliedDirectives(*buildAppliedDirectives(fieldDefinition.directives)) + .build() + ) + } + } } - } return directiveWiringHelper.wireInputObject(builder.build()) } @@ -189,57 +194,59 @@ class SchemaParser internal constructor( .definition(definition) .description(getDocumentation(definition, options)) .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) - - definition.enumValueDefinitions.forEach { enumDefinition -> - val enumName = enumDefinition.name - val enumValue = type.unwrap().enumConstants.find { (it as Enum<*>).name == enumName } - ?: throw SchemaError("Expected value for name '$enumName' in enum '${type.unwrap().simpleName}' but found none!") - - val enumValueAppliedDirectives = buildAppliedDirectives(enumDefinition.directives) - val enumValueDefinition = GraphQLEnumValueDefinition.newEnumValueDefinition() - .name(enumName) - .description(getDocumentation(enumDefinition, options)) - .value(enumValue) - .apply { getDeprecated(enumDefinition.directives)?.let { deprecationReason(it) } } - .withAppliedDirectives(*enumValueAppliedDirectives) - .definition(enumDefinition) - .build() - - builder.value(enumValueDefinition) - } + .apply { + definition.enumValueDefinitions.forEach { valueDefinition -> + val enumName = valueDefinition.name + val enumValue = type.unwrap().enumConstants.find { (it as Enum<*>).name == enumName } + ?: throw SchemaError("Expected value for name '$enumName' in enum '${type.unwrap().simpleName}' but found none!") + + value( + GraphQLEnumValueDefinition.newEnumValueDefinition() + .name(enumName) + .description(getDocumentation(valueDefinition, options)) + .value(enumValue) + .apply { getDeprecated(valueDefinition.directives)?.let { deprecationReason(it) } } + .withAppliedDirectives(*buildAppliedDirectives(valueDefinition.directives)) + .definition(valueDefinition) + .build() + ) + } + } return directiveWiringHelper.wireEnum(builder.build()) } private fun createInterfaceObject(interfaceDefinition: InterfaceTypeDefinition, inputObjects: List): GraphQLInterfaceType { - val name = interfaceDefinition.name val builder = GraphQLInterfaceType.newInterface() - .name(name) + .name(interfaceDefinition.name) .definition(interfaceDefinition) .description(getDocumentation(interfaceDefinition, options)) .withAppliedDirectives(*buildAppliedDirectives(interfaceDefinition.directives)) - - interfaceDefinition.fieldDefinitions.forEach { fieldDefinition -> - builder.field { field -> createField(field, fieldDefinition, inputObjects) } - } - - interfaceDefinition.implements.forEach { implementsDefinition -> - val interfaceName = (implementsDefinition as TypeName).name - builder.withInterface(GraphQLTypeReference(interfaceName)) - } + .apply { + interfaceDefinition.fieldDefinitions.forEach { fieldDefinition -> + field { field -> createField(field, fieldDefinition, inputObjects) } + } + } + .apply { + interfaceDefinition.implements.forEach { implementsDefinition -> + val interfaceName = (implementsDefinition as TypeName).name + withInterface(GraphQLTypeReference(interfaceName)) + } + } return directiveWiringHelper.wireInterFace(builder.build()) } private fun createUnionObject(definition: UnionTypeDefinition, types: List): GraphQLUnionType { - val name = definition.name val builder = GraphQLUnionType.newUnionType() - .name(name) + .name(definition.name) .definition(definition) .description(getDocumentation(definition, options)) .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) + .apply { + getLeafUnionObjects(definition, types).forEach { possibleType(it) } + } - getLeafUnionObjects(definition, types).forEach { builder.possibleType(it) } return directiveWiringHelper.wireUnion(builder.build()) } @@ -264,34 +271,34 @@ class SchemaParser internal constructor( } private fun createField(field: GraphQLFieldDefinition.Builder, fieldDefinition: FieldDefinition, inputObjects: List): GraphQLFieldDefinition.Builder { - field + return field .name(fieldDefinition.name) .description(getDocumentation(fieldDefinition, options)) .definition(fieldDefinition) .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } } .type(determineOutputType(fieldDefinition.type, inputObjects)) .withAppliedDirectives(*buildAppliedDirectives(fieldDefinition.directives)) - - fieldDefinition.inputValueDefinitions.forEach { argumentDefinition -> - val argumentBuilder = GraphQLArgument.newArgument() - .name(argumentDefinition.name) - .definition(argumentDefinition) - .description(getDocumentation(argumentDefinition, options)) - .type(determineInputType(argumentDefinition.type, inputObjects, setOf())) - .apply { getDeprecated(argumentDefinition.directives)?.let { deprecate(it) } } - .apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } } - .withAppliedDirectives(*buildAppliedDirectives(argumentDefinition.directives)) - - field.argument(argumentBuilder.build()) - } - - return field + .apply { + fieldDefinition.inputValueDefinitions.forEach { argumentDefinition -> + argument( + GraphQLArgument.newArgument() + .name(argumentDefinition.name) + .definition(argumentDefinition) + .description(getDocumentation(argumentDefinition, options)) + .type(determineInputType(argumentDefinition.type, inputObjects, setOf())) + .apply { getDeprecated(argumentDefinition.directives)?.let { deprecate(it) } } + .apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } } + .withAppliedDirectives(*buildAppliedDirectives(argumentDefinition.directives)) + .build() + ) + } + } } private fun createDirective(definition: DirectiveDefinition, inputObjects: List): GraphQLDirective { val locations = definition.directiveLocations.map { Introspection.DirectiveLocation.valueOf(it.name) }.toTypedArray() - val graphQLDirective = GraphQLDirective.newDirective() + return GraphQLDirective.newDirective() .name(definition.name) .description(getDocumentation(definition, options)) .definition(definition) @@ -312,8 +319,6 @@ class SchemaParser internal constructor( } } .build() - - return graphQLDirective } private fun buildAppliedDirectives(directives: List): Array { From d6359574808a402ecac90a07faa1d8f8f38647d1 Mon Sep 17 00:00:00 2001 From: Oryan M Date: Mon, 26 Sep 2022 12:43:13 -0400 Subject: [PATCH 04/10] Add back deprecated directives --- .../graphql/kickstart/tools/SchemaParser.kt | 38 ++++++++++++++- .../tools/directive/DirectiveWiringHelper.kt | 9 ++-- .../graphql/kickstart/tools/DirectiveTest.kt | 47 ++++++++++++++++++- .../kickstart/tools/SchemaClassScannerTest.kt | 2 + 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt index 1f1d3f4e..a4bb3d44 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt @@ -122,6 +122,7 @@ class SchemaParser internal constructor( .definition(objectDefinition) .description(getDocumentation(objectDefinition, options)) .withAppliedDirectives(*buildAppliedDirectives(objectDefinition.directives)) + .withDirectives(*buildDirectives(objectDefinition.directives, Introspection.DirectiveLocation.OBJECT)) .apply { objectDefinition.implements.forEach { implementsDefinition -> val interfaceName = (implementsDefinition as TypeName).name @@ -162,6 +163,7 @@ class SchemaParser internal constructor( .extensionDefinitions(extensionDefinitions) .description(getDocumentation(definition, options)) .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) + .withDirectives(*buildDirectives(definition.directives, Introspection.DirectiveLocation.INPUT_OBJECT)) .apply { (extensionDefinitions + definition).forEach { typeDefinition -> typeDefinition.inputValueDefinitions.forEach { fieldDefinition -> @@ -174,6 +176,12 @@ class SchemaParser internal constructor( .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } } .type(determineInputType(fieldDefinition.type, inputObjects, referencingInputObjects)) .withAppliedDirectives(*buildAppliedDirectives(fieldDefinition.directives)) + .withDirectives( + *buildDirectives( + definition.directives, + Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION + ) + ) .build() ) } @@ -194,6 +202,7 @@ class SchemaParser internal constructor( .definition(definition) .description(getDocumentation(definition, options)) .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) + .withDirectives(*buildDirectives(definition.directives, Introspection.DirectiveLocation.ENUM)) .apply { definition.enumValueDefinitions.forEach { valueDefinition -> val enumName = valueDefinition.name @@ -207,6 +216,7 @@ class SchemaParser internal constructor( .value(enumValue) .apply { getDeprecated(valueDefinition.directives)?.let { deprecationReason(it) } } .withAppliedDirectives(*buildAppliedDirectives(valueDefinition.directives)) + .withDirectives(*buildDirectives(valueDefinition.directives, Introspection.DirectiveLocation.ENUM_VALUE)) .definition(valueDefinition) .build() ) @@ -222,6 +232,7 @@ class SchemaParser internal constructor( .definition(interfaceDefinition) .description(getDocumentation(interfaceDefinition, options)) .withAppliedDirectives(*buildAppliedDirectives(interfaceDefinition.directives)) + .withDirectives(*buildDirectives(interfaceDefinition.directives, Introspection.DirectiveLocation.INTERFACE)) .apply { interfaceDefinition.fieldDefinitions.forEach { fieldDefinition -> field { field -> createField(field, fieldDefinition, inputObjects) } @@ -243,6 +254,7 @@ class SchemaParser internal constructor( .definition(definition) .description(getDocumentation(definition, options)) .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) + .withDirectives(*buildDirectives(definition.directives, Introspection.DirectiveLocation.UNION)) .apply { getLeafUnionObjects(definition, types).forEach { possibleType(it) } } @@ -278,6 +290,7 @@ class SchemaParser internal constructor( .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } } .type(determineOutputType(fieldDefinition.type, inputObjects)) .withAppliedDirectives(*buildAppliedDirectives(fieldDefinition.directives)) + .withDirectives(*buildDirectives(fieldDefinition.directives, Introspection.DirectiveLocation.FIELD_DEFINITION)) .apply { fieldDefinition.inputValueDefinitions.forEach { argumentDefinition -> argument( @@ -289,6 +302,12 @@ class SchemaParser internal constructor( .apply { getDeprecated(argumentDefinition.directives)?.let { deprecate(it) } } .apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } } .withAppliedDirectives(*buildAppliedDirectives(argumentDefinition.directives)) + .withDirectives( + *buildDirectives( + fieldDefinition.directives, + Introspection.DirectiveLocation.ARGUMENT_DEFINITION + ) + ) .build() ) } @@ -315,6 +334,7 @@ class SchemaParser internal constructor( .apply { getDeprecated(arg.directives)?.let { deprecate(it) } } .apply { arg.defaultValue?.let { defaultValueLiteral(it) } } .withAppliedDirectives(*buildAppliedDirectives(arg.directives)) + .withDirectives(*buildDirectives(arg.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION)) .build()) } } @@ -333,17 +353,31 @@ class SchemaParser internal constructor( .name(arg.name) .type(directiveWiringHelper.buildDirectiveInputType(arg.value)) .valueLiteral(arg.value) - .build()) + .build() + ) } } .build() }.toTypedArray() } + // TODO remove this once directives are fully replaced with applied directives + private fun buildDirectives( + directives: List, + directiveLocation: Introspection.DirectiveLocation + ): Array { + return directiveWiringHelper.buildDirectives(directives, directiveLocation).toTypedArray() + } + private fun determineOutputType(typeDefinition: Type<*>, inputObjects: List) = determineType(GraphQLOutputType::class, typeDefinition, permittedTypesForObject, inputObjects) as GraphQLOutputType - private fun determineType(expectedType: KClass, typeDefinition: Type<*>, allowedTypeReferences: Set, inputObjects: List): GraphQLType = + private fun determineType( + expectedType: KClass, + typeDefinition: Type<*>, + allowedTypeReferences: Set, + inputObjects: List + ): GraphQLType = when (typeDefinition) { is ListType -> GraphQLList(determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects)) is NonNullType -> GraphQLNonNull(determineType(expectedType, typeDefinition.type, allowedTypeReferences, inputObjects)) diff --git a/src/main/kotlin/graphql/kickstart/tools/directive/DirectiveWiringHelper.kt b/src/main/kotlin/graphql/kickstart/tools/directive/DirectiveWiringHelper.kt index 0d0a4a0b..f9bfdd29 100644 --- a/src/main/kotlin/graphql/kickstart/tools/directive/DirectiveWiringHelper.kt +++ b/src/main/kotlin/graphql/kickstart/tools/directive/DirectiveWiringHelper.kt @@ -100,7 +100,7 @@ class DirectiveWiringHelper( return output } - private fun buildDirectives(directives: List, directiveLocation: Introspection.DirectiveLocation): List { + fun buildDirectives(directives: List, directiveLocation: Introspection.DirectiveLocation): List { val names = mutableSetOf() val output = mutableListOf() @@ -108,9 +108,10 @@ class DirectiveWiringHelper( val repeatable = directiveDefinitions.find { it.name.equals(directive.name) }?.isRepeatable ?: false if (repeatable || !names.contains(directive.name)) { names.add(directive.name) - output.add(GraphQLDirective.newDirective() - .name(directive.name) - .description(getDocumentation(directive, options)) + output.add( + GraphQLDirective.newDirective() + .name(directive.name) + .description(getDocumentation(directive, options)) .comparatorRegistry(runtimeWiring.comparatorRegistry) .validLocation(directiveLocation) .repeatable(repeatable) diff --git a/src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt b/src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt index 8682322f..03b0dd85 100644 --- a/src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt +++ b/src/test/kotlin/graphql/kickstart/tools/DirectiveTest.kt @@ -122,6 +122,7 @@ class DirectiveTest { .schemaString( """ directive @double repeatable on FIELD_DEFINITION + directive @uppercase on FIELD_DEFINITION type Query { user: User @@ -192,7 +193,8 @@ class DirectiveTest { name } } - """) + """ + ) val expected = mapOf( "user" to mapOf("id" to "1", "name" to "LukeLukeLukeLuke") @@ -201,6 +203,49 @@ class DirectiveTest { assertEquals(result.getData(), expected) } + @Test + fun `should have access to applied directives through the data fetching environment`() { + val schema = SchemaParser.newParser() + .schemaString( + """ + directive @uppercase on OBJECT + + type Query { + name: String @uppercase + } + + """ + ) + .resolvers(NameResolver()) + .directive("uppercase", UppercaseDirective()) + .build() + .makeExecutableSchema() + + val gql = GraphQL.newGraphQL(schema) + .queryExecutionStrategy(AsyncExecutionStrategy()) + .build() + + val result = gql.execute( + """ + query { + name + } + """ + ) + + val expected = mapOf("name" to "LUKE") + + assertEquals(result.getData(), expected) + } + + internal class NameResolver : GraphQLQueryResolver { + fun name(environment: DataFetchingEnvironment): String { + assertNotNull(environment.fieldDefinition.getAppliedDirective("uppercase")) + assertNotNull(environment.fieldDefinition.getDirective("uppercase")) + return "luke" + } + } + @Test @Ignore("Ignore until enums work in directives") fun `should compile schema with directive that has enum parameter`() { diff --git a/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt b/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt index f5893618..673fbe33 100644 --- a/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt +++ b/src/test/kotlin/graphql/kickstart/tools/SchemaClassScannerTest.kt @@ -1,6 +1,7 @@ package graphql.kickstart.tools import graphql.schema.* +import org.junit.Ignore import org.junit.Test import java.util.concurrent.CompletableFuture @@ -418,6 +419,7 @@ class SchemaClassScannerTest { } @Test + @Ignore("TODO remove this once directives are fully replaced with applied directives OR issue #664 is resolved") fun `scanner should handle unused types when option is true`() { val schema = SchemaParser.newParser() .schemaString( From 2a33e6b752aa791f0c92ea44f5a9d9e40ca6591b Mon Sep 17 00:00:00 2001 From: Oryan M Date: Mon, 26 Sep 2022 12:51:52 -0400 Subject: [PATCH 05/10] Extract create argument method --- .../graphql/kickstart/tools/SchemaParser.kt | 52 +++++++------------ 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt index a4bb3d44..7772f7ab 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt @@ -1,6 +1,7 @@ package graphql.kickstart.tools import graphql.introspection.Introspection +import graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION import graphql.kickstart.tools.directive.DirectiveWiringHelper import graphql.kickstart.tools.util.getDocumentation import graphql.kickstart.tools.util.getExtendedFieldDefinitions @@ -176,12 +177,7 @@ class SchemaParser internal constructor( .apply { getDeprecated(fieldDefinition.directives)?.let { deprecate(it) } } .type(determineInputType(fieldDefinition.type, inputObjects, referencingInputObjects)) .withAppliedDirectives(*buildAppliedDirectives(fieldDefinition.directives)) - .withDirectives( - *buildDirectives( - definition.directives, - Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION - ) - ) + .withDirectives(*buildDirectives(definition.directives, INPUT_FIELD_DEFINITION)) .build() ) } @@ -293,27 +289,24 @@ class SchemaParser internal constructor( .withDirectives(*buildDirectives(fieldDefinition.directives, Introspection.DirectiveLocation.FIELD_DEFINITION)) .apply { fieldDefinition.inputValueDefinitions.forEach { argumentDefinition -> - argument( - GraphQLArgument.newArgument() - .name(argumentDefinition.name) - .definition(argumentDefinition) - .description(getDocumentation(argumentDefinition, options)) - .type(determineInputType(argumentDefinition.type, inputObjects, setOf())) - .apply { getDeprecated(argumentDefinition.directives)?.let { deprecate(it) } } - .apply { argumentDefinition.defaultValue?.let { defaultValueLiteral(it) } } - .withAppliedDirectives(*buildAppliedDirectives(argumentDefinition.directives)) - .withDirectives( - *buildDirectives( - fieldDefinition.directives, - Introspection.DirectiveLocation.ARGUMENT_DEFINITION - ) - ) - .build() - ) + argument(createArgument(argumentDefinition, inputObjects)) } } } + private fun createArgument(definition: InputValueDefinition, inputObjects: List): GraphQLArgument { + return GraphQLArgument.newArgument() + .name(definition.name) + .definition(definition) + .description(getDocumentation(definition, options)) + .type(determineInputType(definition.type, inputObjects, setOf())) + .apply { getDeprecated(definition.directives)?.let { deprecate(it) } } + .apply { definition.defaultValue?.let { defaultValueLiteral(it) } } + .withAppliedDirectives(*buildAppliedDirectives(definition.directives)) + .withDirectives(*buildDirectives(definition.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION)) + .build() + } + private fun createDirective(definition: DirectiveDefinition, inputObjects: List): GraphQLDirective { val locations = definition.directiveLocations.map { Introspection.DirectiveLocation.valueOf(it.name) }.toTypedArray() @@ -325,17 +318,8 @@ class SchemaParser internal constructor( .validLocations(*locations) .repeatable(definition.isRepeatable) .apply { - definition.inputValueDefinitions.forEach { arg -> - argument(GraphQLArgument.newArgument() - .name(arg.name) - .definition(arg) - .description(getDocumentation(arg, options)) - .type(determineInputType(arg.type, inputObjects, setOf())) - .apply { getDeprecated(arg.directives)?.let { deprecate(it) } } - .apply { arg.defaultValue?.let { defaultValueLiteral(it) } } - .withAppliedDirectives(*buildAppliedDirectives(arg.directives)) - .withDirectives(*buildDirectives(arg.directives, Introspection.DirectiveLocation.ARGUMENT_DEFINITION)) - .build()) + definition.inputValueDefinitions.forEach { argumentDefinition -> + argument(createArgument(argumentDefinition, inputObjects)) } } .build() From 6eee655b809f760125e7778ff01d3cc5e83811e3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 29 Sep 2022 12:30:05 +0000 Subject: [PATCH 06/10] Update kotlin to v1.7.20 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 91f0a8d0..c2db9a6a 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ UTF-8 1.8 - 1.7.10 + 1.7.20 1.6.4 2.13.4 19.2 From 6aa53518b03584d53be3a14e28ce94cd5481cb2a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 22:54:23 +0000 Subject: [PATCH 07/10] Update all non-major dependencies --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c2db9a6a..6bf040c8 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ org.slf4j slf4j-api - 2.0.2 + 2.0.3 org.apache.commons @@ -100,7 +100,7 @@ ch.qos.logback logback-classic - 1.3.1 + 1.3.3 javax.servlet From 109d170edd18789edf56bd06d016b1cf19544132 Mon Sep 17 00:00:00 2001 From: Oryan M Date: Thu, 6 Oct 2022 15:38:18 -0400 Subject: [PATCH 08/10] Bump version to 13.0.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 385e544e..900e24bf 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ kotlin.version=1.7.10 Add the dependency: ```groovy -compile 'com.graphql-java-kickstart:graphql-java-tools:13.0.1' +compile 'com.graphql-java-kickstart:graphql-java-tools:13.0.2' ``` ### Using Maven @@ -43,7 +43,7 @@ Add the dependency: com.graphql-java-kickstart graphql-java-tools - 13.0.1 + 13.0.2 ``` From 2f17a9819677550cb6ff3708aec1d546623bcd2f Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 6 Oct 2022 19:45:48 +0000 Subject: [PATCH 09/10] Update version for release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6bf040c8..0d87474a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.graphql-java-kickstart graphql-java-tools - 13.0.2-SNAPSHOT + 13.0.2 jar GraphQL Java Tools From ec4864e2cd99f88e1d7684fe85c8a79af4d565c4 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 6 Oct 2022 19:45:48 +0000 Subject: [PATCH 10/10] Update version for release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0d87474a..b39a12c9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.graphql-java-kickstart graphql-java-tools - 13.0.2 + 13.0.3-SNAPSHOT jar GraphQL Java Tools