From 2950564786afc4e8cb2ff697d7dd063d07dc4c84 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Fri, 14 Jun 2024 17:46:30 -0500 Subject: [PATCH] feat: add nullableDataFetchingEnvironment config --- src/config/schema.ts | 8 ++- src/definitions/field.ts | 3 +- .../expected.kt | 2 +- .../expected.kt | 16 +++--- .../expected.kt | 2 +- .../expected.kt | 16 +++--- .../codegen.config.ts | 4 ++ .../expected.kt | 52 +++++++++++-------- .../schema.graphql | 5 ++ .../expected.kt | 2 +- 10 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/config/schema.ts b/src/config/schema.ts index eec4c86..866500a 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -112,7 +112,8 @@ export const configSchema = object({ * interface functions to enforce a type contract. * * Type names can be optionally passed with the classMethods config to generate the interface with `suspend` functions or - * `java.util.concurrent.CompletableFuture` functions. + * `java.util.concurrent.CompletableFuture` functions. Pass `nullableDataFetchingEnvironment: true` to make the + * `DataFetchingEnvironment` argument nullable in each resolver function for that class. * @example * [ * { @@ -125,6 +126,10 @@ export const configSchema = object({ * { * typeName: "MyCompletableFutureResolverType", * classMethods: "COMPLETABLE_FUTURE", + * }, + * { + * typeName: "MyTypeWithNullableDataFetchingEnvironment", + * nullableDataFetchingEnvironment: true, * } * ] * @link https://opensource.expediagroup.com/graphql-kotlin-codegen/docs/recommended-usage @@ -136,6 +141,7 @@ export const configSchema = object({ classMethods: optional( union([literal("SUSPEND"), literal("COMPLETABLE_FUTURE")]), ), + nullableDataFetchingEnvironment: optional(boolean()), }), ), ), diff --git a/src/definitions/field.ts b/src/definitions/field.ts index 4cb6cfe..39715c5 100644 --- a/src/definitions/field.ts +++ b/src/definitions/field.ts @@ -287,8 +287,7 @@ function buildFieldArguments( const argMetadata = buildTypeMetadata(arg.type, schema, config); return `${sanitizeName(arg.name.value)}: ${argMetadata.typeName}${arg.type.kind === Kind.NON_NULL_TYPE ? "" : nullableSuffix}`; }); - const dataFetchingEnvironmentArgument = - "dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null"; + const dataFetchingEnvironmentArgument = `dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment${typeInResolverInterfacesConfig?.nullableDataFetchingEnvironment ? "? = null" : ""}`; 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 865d7f5..8a34614 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 9d32f5c..8c2d70b 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]) @@ -15,8 +15,8 @@ open class HybridType( private val nullableResolver: String? = null, private val nonNullableResolver: String ) { - open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = nullableResolver - open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = nonNullableResolver + open fun nullableResolver(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = nullableResolver + open fun nonNullableResolver(arg: InputTypeForResolver, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = nonNullableResolver } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.INPUT_OBJECT]) @@ -27,8 +27,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]) @@ -42,6 +42,6 @@ open class TypeImplementingInterface( private val nullableListResolver: List? = null, private val nonNullableListResolver: List = emptyList() ) : HybridInterface { - override fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List? = nullableListResolver - override fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): List = nonNullableListResolver + override fun nullableListResolver(arg1: Int?, arg2: Int, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List? = nullableListResolver + override fun nonNullableListResolver(arg1: Int, arg2: Int?, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): List = nonNullableListResolver } diff --git a/test/unit/should_handle_reserved_kotlin_keywords/expected.kt b/test/unit/should_handle_reserved_kotlin_keywords/expected.kt index aeb3efd..c6a91e9 100644 --- a/test/unit/should_handle_reserved_kotlin_keywords/expected.kt +++ b/test/unit/should_handle_reserved_kotlin_keywords/expected.kt @@ -14,7 +14,7 @@ open class TypeWithReservedKotlinKeywordsAndFieldArgs( val `typeof`: String? = null, private val `throw`: String? = null ) { - open fun `throw`(`else`: String? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = `throw` + open fun `throw`(`else`: String? = null, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = `throw` } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) diff --git a/test/unit/should_handle_top_level_types_properly/expected.kt b/test/unit/should_handle_top_level_types_properly/expected.kt index 6ea8122..dd8c83e 100644 --- a/test/unit/should_handle_top_level_types_properly/expected.kt +++ b/test/unit/should_handle_top_level_types_properly/expected.kt @@ -4,32 +4,32 @@ import com.expediagroup.graphql.generator.annotations.* @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class Query { - open fun getStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Query.getStuff must be implemented.") - open fun getStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Query.getStuffWithInput must be implemented.") + open fun getStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Query.getStuff must be implemented.") + open fun getStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Query.getStuffWithInput must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class GetStuffQueryInterface { - open fun getStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Query.getStuff must be implemented.") + open fun getStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Query.getStuff must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class GetStuffWithInputQueryInterface { - open fun getStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Query.getStuffWithInput must be implemented.") + open fun getStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Query.getStuffWithInput must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class Mutation { - open suspend fun mutateStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Mutation.mutateStuff must be implemented.") - open suspend fun mutateStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Mutation.mutateStuffWithInput must be implemented.") + open suspend fun mutateStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Mutation.mutateStuff must be implemented.") + open suspend fun mutateStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Mutation.mutateStuffWithInput must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MutateStuffMutationInterface { - open suspend fun mutateStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Mutation.mutateStuff must be implemented.") + open suspend fun mutateStuff(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Mutation.mutateStuff must be implemented.") } @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MutateStuffWithInputMutationInterface { - open suspend fun mutateStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("Mutation.mutateStuffWithInput must be implemented.") + open suspend fun mutateStuffWithInput(input: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = throw NotImplementedError("Mutation.mutateStuffWithInput must be implemented.") } diff --git a/test/unit/should_honor_resolverInterfaces_config/codegen.config.ts b/test/unit/should_honor_resolverInterfaces_config/codegen.config.ts index 52b0393..2a12eb9 100644 --- a/test/unit/should_honor_resolverInterfaces_config/codegen.config.ts +++ b/test/unit/should_honor_resolverInterfaces_config/codegen.config.ts @@ -23,5 +23,9 @@ export default { typeName: "MyIncludedInterfaceSuspend", classMethods: "SUSPEND", }, + { + typeName: "MyIncludedResolverTypeWithNullDataFetchingEnvironment", + nullableDataFetchingEnvironment: true, + }, ], } satisfies GraphQLKotlinCodegenConfig; diff --git a/test/unit/should_honor_resolverInterfaces_config/expected.kt b/test/unit/should_honor_resolverInterfaces_config/expected.kt index e19da9f..9d0af88 100644 --- a/test/unit/should_honor_resolverInterfaces_config/expected.kt +++ b/test/unit/should_honor_resolverInterfaces_config/expected.kt @@ -4,12 +4,12 @@ import com.expediagroup.graphql.generator.annotations.* @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) open class MyIncludedResolverType { - open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): MyChildType? = 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): MyChildType? = 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]) @@ -17,33 +17,33 @@ open class MyChildType( val field: String? = null, private val field2: String? = null ) { - open fun field2(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = field2 + open fun field2(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String? = field2 } @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]) @@ -53,13 +53,19 @@ 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 { val field: String? } + +@GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations.Locations.OBJECT]) +open class MyIncludedResolverTypeWithNullDataFetchingEnvironment { + open fun nullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String? = throw NotImplementedError("MyIncludedResolverTypeWithNullDataFetchingEnvironment.nullableField must be implemented.") + open fun nonNullableField(dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment? = null): String = throw NotImplementedError("MyIncludedResolverTypeWithNullDataFetchingEnvironment.nonNullableField must be implemented.") +} diff --git a/test/unit/should_honor_resolverInterfaces_config/schema.graphql b/test/unit/should_honor_resolverInterfaces_config/schema.graphql index fcce4fd..6caddac 100644 --- a/test/unit/should_honor_resolverInterfaces_config/schema.graphql +++ b/test/unit/should_honor_resolverInterfaces_config/schema.graphql @@ -51,3 +51,8 @@ interface MyIncludedInterfaceSuspend { interface MyExcludedInterface { field: String } + +type MyIncludedResolverTypeWithNullDataFetchingEnvironment { + nullableField: String + nonNullableField: String! +} diff --git a/test/unit/should_replace_federation_directives/expected.kt b/test/unit/should_replace_federation_directives/expected.kt index d9e622d..29b782a 100644 --- a/test/unit/should_replace_federation_directives/expected.kt +++ b/test/unit/should_replace_federation_directives/expected.kt @@ -18,5 +18,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 = field + open fun field(arg: String, dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment): String = field }