From 1e8c6f04da0cfd1f8b9a0b869b2874dfc9b88e25 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Tue, 7 May 2024 07:18:07 -0500 Subject: [PATCH 1/3] fix: make nullable interface args default to null --- src/helpers/build-field-definition.ts | 11 +++-- .../expected.kt | 2 +- .../expected.kt | 16 +++---- .../expected.kt | 44 +++++++++---------- .../expected.kt | 2 +- 5 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/helpers/build-field-definition.ts b/src/helpers/build-field-definition.ts index e06c2ce..e001b1d 100644 --- a/src/helpers/build-field-definition.ts +++ b/src/helpers/build-field-definition.ts @@ -110,12 +110,17 @@ function buildFieldArguments( if (!typeIsInResolverClasses && !fieldNode.arguments?.length) { return ""; } + const isOverrideFunction = shouldModifyFieldWithOverride( + node, + fieldNode, + schema, + ); + const nullableSuffix = isOverrideFunction ? "?" : "? = null"; const existingFieldArguments = fieldNode.arguments?.map((arg) => { const argMetadata = buildTypeMetadata(arg.type, schema, config); - return `${arg.name.value}: ${argMetadata.typeName}${arg.type.kind === Kind.NON_NULL_TYPE ? "" : "?"}`; + return `${arg.name.value}: ${argMetadata.typeName}${arg.type.kind === Kind.NON_NULL_TYPE ? "" : nullableSuffix}`; }); - const dataFetchingEnvironmentArgument = - "dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment"; + const dataFetchingEnvironmentArgument = `dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment${nullableSuffix}`; const extraFieldArguments = [dataFetchingEnvironmentArgument]; const allFieldArguments = existingFieldArguments?.concat(extraFieldArguments); return allFieldArguments?.length diff --git a/test/unit/should_consolidate_input_and_output_types/expected.kt b/test/unit/should_consolidate_input_and_output_types/expected.kt index 441f9a6..c7d77a6 100644 --- a/test/unit/should_consolidate_input_and_output_types/expected.kt +++ b/test/unit/should_consolidate_input_and_output_types/expected.kt @@ -70,7 +70,7 @@ data class MyTypeToConsolidateInputParent( @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyTypeToConsolidateParent2 { - open fun field(input: MyTypeToConsolidate, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyTypeToConsolidateParent2.field must be implemented.") + open fun field(input: MyTypeToConsolidate, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyTypeToConsolidateParent2.field must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) diff --git a/test/unit/should_generate_classes_for_types_with_field_args/expected.kt b/test/unit/should_generate_classes_for_types_with_field_args/expected.kt index 4d0101f..8adc462 100644 --- a/test/unit/should_generate_classes_for_types_with_field_args/expected.kt +++ b/test/unit/should_generate_classes_for_types_with_field_args/expected.kt @@ -4,8 +4,8 @@ import com.expediagroup.graphql.generator.annotations.* @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class TypeWithOnlyFieldArgs { - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("TypeWithOnlyFieldArgs.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("TypeWithOnlyFieldArgs.nonNullableResolver must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("TypeWithOnlyFieldArgs.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("TypeWithOnlyFieldArgs.nonNullableResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) @@ -13,8 +13,8 @@ open class HybridType( val nullableField: String? = null, val nonNullableField: String ) { - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("HybridType.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("HybridType.nonNullableResolver must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("HybridType.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("HybridType.nonNullableResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) @@ -25,8 +25,8 @@ data class InputTypeForResolver( interface HybridInterface { val field1: String? val field2: String - fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? - fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List + fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? + fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) @@ -38,6 +38,6 @@ open class TypeImplementingInterface( val integerField1: Int? = null, val integerField2: Int ) : HybridInterface { - override fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = throw NotImplementedError("TypeImplementingInterface.nullableListResolver must be implemented.") - override fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = throw NotImplementedError("TypeImplementingInterface.nonNullableListResolver must be implemented.") + override fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment?): List? = throw NotImplementedError("TypeImplementingInterface.nullableListResolver must be implemented.") + override fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment?): List = throw NotImplementedError("TypeImplementingInterface.nonNullableListResolver must be implemented.") } diff --git a/test/unit/should_honor_resolverClasses_config/expected.kt b/test/unit/should_honor_resolverClasses_config/expected.kt index a4944d1..c49adcc 100644 --- a/test/unit/should_honor_resolverClasses_config/expected.kt +++ b/test/unit/should_honor_resolverClasses_config/expected.kt @@ -4,38 +4,38 @@ import com.expediagroup.graphql.generator.annotations.* @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyIncludedResolverType { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyIncludedResolverType.nullableField must be implemented.") - open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MyIncludedResolverType.nonNullableField must be implemented.") - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyIncludedResolverType.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MyIncludedResolverType.nonNullableResolver must be implemented.") - open fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = throw NotImplementedError("MyIncludedResolverType.nullableListResolver must be implemented.") - open fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = throw NotImplementedError("MyIncludedResolverType.nonNullableListResolver must be implemented.") + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverType.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverType.nonNullableField must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverType.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverType.nonNullableResolver must be implemented.") + open fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? = throw NotImplementedError("MyIncludedResolverType.nullableListResolver must be implemented.") + open fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List = throw NotImplementedError("MyIncludedResolverType.nonNullableListResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyIncludedResolverTypeWithNoFieldArgs { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nullableField must be implemented.") - open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nonNullableField must be implemented.") + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nonNullableField must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MySuspendResolverType { - open suspend fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MySuspendResolverType.nullableField must be implemented.") - open suspend fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MySuspendResolverType.nonNullableField must be implemented.") - open suspend fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MySuspendResolverType.nullableResolver must be implemented.") - open suspend fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MySuspendResolverType.nonNullableResolver must be implemented.") - open suspend fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = throw NotImplementedError("MySuspendResolverType.nullableListResolver must be implemented.") - open suspend fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = throw NotImplementedError("MySuspendResolverType.nonNullableListResolver must be implemented.") + open suspend fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MySuspendResolverType.nullableField must be implemented.") + open suspend fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MySuspendResolverType.nonNullableField must be implemented.") + open suspend fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MySuspendResolverType.nullableResolver must be implemented.") + open suspend fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MySuspendResolverType.nonNullableResolver must be implemented.") + open suspend fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? = throw NotImplementedError("MySuspendResolverType.nullableListResolver must be implemented.") + open suspend fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List = throw NotImplementedError("MySuspendResolverType.nonNullableListResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyCompletableFutureResolverType { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableField must be implemented.") - open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableField must be implemented.") - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableResolver must be implemented.") - open fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture?> = throw NotImplementedError("MyCompletableFutureResolverType.nullableListResolver must be implemented.") - open fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture> = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableListResolver must be implemented.") + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableField must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableResolver must be implemented.") + open fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture?> = throw NotImplementedError("MyCompletableFutureResolverType.nullableListResolver must be implemented.") + open fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture> = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableListResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) @@ -45,11 +45,11 @@ data class MyExcludedResolverType( ) interface MyIncludedInterface { - fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? + fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? } interface MyIncludedInterfaceSuspend { - suspend fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? + suspend fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? } interface MyExcludedInterface { diff --git a/test/unit/should_replace_federation_directives/expected.kt b/test/unit/should_replace_federation_directives/expected.kt index 0a6a4e1..44e391c 100644 --- a/test/unit/should_replace_federation_directives/expected.kt +++ b/test/unit/should_replace_federation_directives/expected.kt @@ -17,5 +17,5 @@ open class FederatedTypeResolver( @com.expediagroup.graphql.generator.federation.directives.ExternalDirective val field2: String? = null ) { - open fun field(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("FederatedTypeResolver.field must be implemented.") + open fun field(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("FederatedTypeResolver.field must be implemented.") } From 8c08d1c6116258e9876f95db78b46b35ed29eae5 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Tue, 7 May 2024 07:48:07 -0500 Subject: [PATCH 2/3] default nullable args to null --- src/helpers/build-field-definition.ts | 3 +- test/integration/Query.kt | 2 +- .../expected.kt | 2 +- .../expected.kt | 16 +++---- .../expected.kt | 44 +++++++++---------- .../expected.kt | 2 +- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/helpers/build-field-definition.ts b/src/helpers/build-field-definition.ts index e001b1d..735e30f 100644 --- a/src/helpers/build-field-definition.ts +++ b/src/helpers/build-field-definition.ts @@ -120,7 +120,8 @@ function buildFieldArguments( const argMetadata = buildTypeMetadata(arg.type, schema, config); return `${arg.name.value}: ${argMetadata.typeName}${arg.type.kind === Kind.NON_NULL_TYPE ? "" : nullableSuffix}`; }); - const dataFetchingEnvironmentArgument = `dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment${nullableSuffix}`; + const dataFetchingEnvironmentArgument = + "dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment"; const extraFieldArguments = [dataFetchingEnvironmentArgument]; const allFieldArguments = existingFieldArguments?.concat(extraFieldArguments); return allFieldArguments?.length diff --git a/test/integration/Query.kt b/test/integration/Query.kt index 9786c01..29d12e9 100644 --- a/test/integration/Query.kt +++ b/test/integration/Query.kt @@ -4,6 +4,6 @@ import com.expediagroup.graphql.server.operations.Query import graphql.schema.DataFetchingEnvironment import test.integration.Query as QueryInterface -class IntegrationTestQuery() : Query, QueryInterface() { +class IntegrationTestQuery() : Query, QueryInterface { override fun testQuery(dataFetchingEnvironment: DataFetchingEnvironment): SomeType = SomeType() } diff --git a/test/unit/should_consolidate_input_and_output_types/expected.kt b/test/unit/should_consolidate_input_and_output_types/expected.kt index c7d77a6..441f9a6 100644 --- a/test/unit/should_consolidate_input_and_output_types/expected.kt +++ b/test/unit/should_consolidate_input_and_output_types/expected.kt @@ -70,7 +70,7 @@ data class MyTypeToConsolidateInputParent( @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyTypeToConsolidateParent2 { - open fun field(input: MyTypeToConsolidate, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyTypeToConsolidateParent2.field must be implemented.") + open fun field(input: MyTypeToConsolidate, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyTypeToConsolidateParent2.field must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) diff --git a/test/unit/should_generate_classes_for_types_with_field_args/expected.kt b/test/unit/should_generate_classes_for_types_with_field_args/expected.kt index 8adc462..745447d 100644 --- a/test/unit/should_generate_classes_for_types_with_field_args/expected.kt +++ b/test/unit/should_generate_classes_for_types_with_field_args/expected.kt @@ -4,8 +4,8 @@ import com.expediagroup.graphql.generator.annotations.* @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class TypeWithOnlyFieldArgs { - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("TypeWithOnlyFieldArgs.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("TypeWithOnlyFieldArgs.nonNullableResolver must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("TypeWithOnlyFieldArgs.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("TypeWithOnlyFieldArgs.nonNullableResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) @@ -13,8 +13,8 @@ open class HybridType( val nullableField: String? = null, val nonNullableField: String ) { - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("HybridType.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("HybridType.nonNullableResolver must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("HybridType.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("HybridType.nonNullableResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) @@ -25,8 +25,8 @@ data class InputTypeForResolver( interface HybridInterface { val field1: String? val field2: String - fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? - fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List + fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? + fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) @@ -38,6 +38,6 @@ open class TypeImplementingInterface( val integerField1: Int? = null, val integerField2: Int ) : HybridInterface { - override fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment?): List? = throw NotImplementedError("TypeImplementingInterface.nullableListResolver must be implemented.") - override fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment?): List = throw NotImplementedError("TypeImplementingInterface.nonNullableListResolver must be implemented.") + override fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = throw NotImplementedError("TypeImplementingInterface.nullableListResolver must be implemented.") + override fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = throw NotImplementedError("TypeImplementingInterface.nonNullableListResolver must be implemented.") } diff --git a/test/unit/should_honor_resolverClasses_config/expected.kt b/test/unit/should_honor_resolverClasses_config/expected.kt index c49adcc..4f0e457 100644 --- a/test/unit/should_honor_resolverClasses_config/expected.kt +++ b/test/unit/should_honor_resolverClasses_config/expected.kt @@ -4,38 +4,38 @@ import com.expediagroup.graphql.generator.annotations.* @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyIncludedResolverType { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverType.nullableField must be implemented.") - open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverType.nonNullableField must be implemented.") - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverType.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverType.nonNullableResolver must be implemented.") - open fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? = throw NotImplementedError("MyIncludedResolverType.nullableListResolver must be implemented.") - open fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List = throw NotImplementedError("MyIncludedResolverType.nonNullableListResolver must be implemented.") + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyIncludedResolverType.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MyIncludedResolverType.nonNullableField must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyIncludedResolverType.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MyIncludedResolverType.nonNullableResolver must be implemented.") + open fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = throw NotImplementedError("MyIncludedResolverType.nullableListResolver must be implemented.") + open fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = throw NotImplementedError("MyIncludedResolverType.nonNullableListResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyIncludedResolverTypeWithNoFieldArgs { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nullableField must be implemented.") - open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nonNullableField must be implemented.") + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MyIncludedResolverTypeWithNoFieldArgs.nonNullableField must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MySuspendResolverType { - open suspend fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MySuspendResolverType.nullableField must be implemented.") - open suspend fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MySuspendResolverType.nonNullableField must be implemented.") - open suspend fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MySuspendResolverType.nullableResolver must be implemented.") - open suspend fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MySuspendResolverType.nonNullableResolver must be implemented.") - open suspend fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? = throw NotImplementedError("MySuspendResolverType.nullableListResolver must be implemented.") - open suspend fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List = throw NotImplementedError("MySuspendResolverType.nonNullableListResolver must be implemented.") + open suspend fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MySuspendResolverType.nullableField must be implemented.") + open suspend fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MySuspendResolverType.nonNullableField must be implemented.") + open suspend fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = throw NotImplementedError("MySuspendResolverType.nullableResolver must be implemented.") + open suspend fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("MySuspendResolverType.nonNullableResolver must be implemented.") + open suspend fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = throw NotImplementedError("MySuspendResolverType.nullableListResolver must be implemented.") + open suspend fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = throw NotImplementedError("MySuspendResolverType.nonNullableListResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyCompletableFutureResolverType { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableField must be implemented.") - open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableField must be implemented.") - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableResolver must be implemented.") - open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableResolver must be implemented.") - open fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture?> = throw NotImplementedError("MyCompletableFutureResolverType.nullableListResolver must be implemented.") - open fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): java.util.concurrent.CompletableFuture> = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableListResolver must be implemented.") + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableField must be implemented.") + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nullableResolver must be implemented.") + open fun nonNullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableResolver must be implemented.") + open fun nullableListResolver(arg1: Int? = null, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture?> = throw NotImplementedError("MyCompletableFutureResolverType.nullableListResolver must be implemented.") + open fun nonNullableListResolver(arg1: Int, arg2: Int? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): java.util.concurrent.CompletableFuture> = throw NotImplementedError("MyCompletableFutureResolverType.nonNullableListResolver must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) @@ -45,11 +45,11 @@ data class MyExcludedResolverType( ) interface MyIncludedInterface { - fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? + fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? } interface MyIncludedInterfaceSuspend { - suspend fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? + suspend fun field(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? } interface MyExcludedInterface { diff --git a/test/unit/should_replace_federation_directives/expected.kt b/test/unit/should_replace_federation_directives/expected.kt index 44e391c..0a6a4e1 100644 --- a/test/unit/should_replace_federation_directives/expected.kt +++ b/test/unit/should_replace_federation_directives/expected.kt @@ -17,5 +17,5 @@ open class FederatedTypeResolver( @com.expediagroup.graphql.generator.federation.directives.ExternalDirective val field2: String? = null ) { - open fun field(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("FederatedTypeResolver.field must be implemented.") + open fun field(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("FederatedTypeResolver.field must be implemented.") } From 38fac56aa03dcf233fafacbed2932ab426b64ca5 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Tue, 7 May 2024 09:32:57 -0500 Subject: [PATCH 3/3] undo --- test/integration/Query.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/Query.kt b/test/integration/Query.kt index 29d12e9..9786c01 100644 --- a/test/integration/Query.kt +++ b/test/integration/Query.kt @@ -4,6 +4,6 @@ import com.expediagroup.graphql.server.operations.Query import graphql.schema.DataFetchingEnvironment import test.integration.Query as QueryInterface -class IntegrationTestQuery() : Query, QueryInterface { +class IntegrationTestQuery() : Query, QueryInterface() { override fun testQuery(dataFetchingEnvironment: DataFetchingEnvironment): SomeType = SomeType() }