File tree Expand file tree Collapse file tree 5 files changed +23
-3
lines changed
test/unit/should_honor_resolverInterfaces_config Expand file tree Collapse file tree 5 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,8 @@ export const configSchema = object({
112112 * interface functions to enforce a type contract.
113113 *
114114 * Type names can be optionally passed with the classMethods config to generate the interface with `suspend` functions or
115- * `java.util.concurrent.CompletableFuture` functions.
115+ * `java.util.concurrent.CompletableFuture` functions. Pass `nullableDataFetchingEnvironment: true` to make the
116+ * `DataFetchingEnvironment` argument nullable in each resolver function for that class.
116117 * @example
117118 * [
118119 * {
@@ -125,6 +126,10 @@ export const configSchema = object({
125126 * {
126127 * typeName: "MyCompletableFutureResolverType",
127128 * classMethods: "COMPLETABLE_FUTURE",
129+ * },
130+ * {
131+ * typeName: "MyTypeWithNullableDataFetchingEnvironment",
132+ * nullableDataFetchingEnvironment: true,
128133 * }
129134 * ]
130135 * @link https://opensource.expediagroup.com/graphql-kotlin-codegen/docs/recommended-usage
@@ -136,6 +141,7 @@ export const configSchema = object({
136141 classMethods : optional (
137142 union ( [ literal ( "SUSPEND" ) , literal ( "COMPLETABLE_FUTURE" ) ] ) ,
138143 ) ,
144+ nullableDataFetchingEnvironment : optional ( boolean ( ) ) ,
139145 } ) ,
140146 ) ,
141147 ) ,
Original file line number Diff line number Diff line change @@ -287,8 +287,7 @@ function buildFieldArguments(
287287 const argMetadata = buildTypeMetadata ( arg . type , schema , config ) ;
288288 return `${ sanitizeName ( arg . name . value ) } : ${ argMetadata . typeName } ${ arg . type . kind === Kind . NON_NULL_TYPE ? "" : nullableSuffix } ` ;
289289 } ) ;
290- const dataFetchingEnvironmentArgument =
291- "dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment" ;
290+ const dataFetchingEnvironmentArgument = `dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment${ typeInResolverInterfacesConfig ?. nullableDataFetchingEnvironment ? "? = null" : "" } ` ;
292291 const extraFieldArguments = [ dataFetchingEnvironmentArgument ] ;
293292 const allFieldArguments = existingFieldArguments ?. concat ( extraFieldArguments ) ;
294293 return allFieldArguments ?. length
Original file line number Diff line number Diff line change @@ -23,5 +23,9 @@ export default {
2323 typeName : "MyIncludedInterfaceSuspend" ,
2424 classMethods : "SUSPEND" ,
2525 } ,
26+ {
27+ typeName : "MyIncludedResolverTypeWithNullDataFetchingEnvironment" ,
28+ nullableDataFetchingEnvironment : true ,
29+ } ,
2630 ] ,
2731} satisfies GraphQLKotlinCodegenConfig ;
Original file line number Diff line number Diff line change @@ -63,3 +63,9 @@ interface MyIncludedInterfaceSuspend {
6363interface MyExcludedInterface {
6464 val field: String?
6565}
66+
67+ @GraphQLValidObjectLocations(locations = [GraphQLValidObjectLocations .Locations .OBJECT ])
68+ open class MyIncludedResolverTypeWithNullDataFetchingEnvironment {
69+ open fun nullableField (dataFetchingEnvironment : graphql.schema.DataFetchingEnvironment ? = null): String? = throw NotImplementedError (" MyIncludedResolverTypeWithNullDataFetchingEnvironment.nullableField must be implemented." )
70+ open fun nonNullableField (dataFetchingEnvironment : graphql.schema.DataFetchingEnvironment ? = null): String = throw NotImplementedError (" MyIncludedResolverTypeWithNullDataFetchingEnvironment.nonNullableField must be implemented." )
71+ }
Original file line number Diff line number Diff line change @@ -51,3 +51,8 @@ interface MyIncludedInterfaceSuspend {
5151interface MyExcludedInterface {
5252 field : String
5353}
54+
55+ type MyIncludedResolverTypeWithNullDataFetchingEnvironment {
56+ nullableField : String
57+ nonNullableField : String !
58+ }
You can’t perform that action at this time.
0 commit comments