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({
112
112
* interface functions to enforce a type contract.
113
113
*
114
114
* 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.
116
117
* @example
117
118
* [
118
119
* {
@@ -125,6 +126,10 @@ export const configSchema = object({
125
126
* {
126
127
* typeName: "MyCompletableFutureResolverType",
127
128
* classMethods: "COMPLETABLE_FUTURE",
129
+ * },
130
+ * {
131
+ * typeName: "MyTypeWithNullableDataFetchingEnvironment",
132
+ * nullableDataFetchingEnvironment: true,
128
133
* }
129
134
* ]
130
135
* @link https://opensource.expediagroup.com/graphql-kotlin-codegen/docs/recommended-usage
@@ -136,6 +141,7 @@ export const configSchema = object({
136
141
classMethods : optional (
137
142
union ( [ literal ( "SUSPEND" ) , literal ( "COMPLETABLE_FUTURE" ) ] ) ,
138
143
) ,
144
+ nullableDataFetchingEnvironment : optional ( boolean ( ) ) ,
139
145
} ) ,
140
146
) ,
141
147
) ,
Original file line number Diff line number Diff line change @@ -287,8 +287,7 @@ function buildFieldArguments(
287
287
const argMetadata = buildTypeMetadata ( arg . type , schema , config ) ;
288
288
return `${ sanitizeName ( arg . name . value ) } : ${ argMetadata . typeName } ${ arg . type . kind === Kind . NON_NULL_TYPE ? "" : nullableSuffix } ` ;
289
289
} ) ;
290
- const dataFetchingEnvironmentArgument =
291
- "dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment" ;
290
+ const dataFetchingEnvironmentArgument = `dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment${ typeInResolverInterfacesConfig ?. nullableDataFetchingEnvironment ? "? = null" : "" } ` ;
292
291
const extraFieldArguments = [ dataFetchingEnvironmentArgument ] ;
293
292
const allFieldArguments = existingFieldArguments ?. concat ( extraFieldArguments ) ;
294
293
return allFieldArguments ?. length
Original file line number Diff line number Diff line change @@ -23,5 +23,9 @@ export default {
23
23
typeName : "MyIncludedInterfaceSuspend" ,
24
24
classMethods : "SUSPEND" ,
25
25
} ,
26
+ {
27
+ typeName : "MyIncludedResolverTypeWithNullDataFetchingEnvironment" ,
28
+ nullableDataFetchingEnvironment : true ,
29
+ } ,
26
30
] ,
27
31
} satisfies GraphQLKotlinCodegenConfig ;
Original file line number Diff line number Diff line change @@ -63,3 +63,9 @@ interface MyIncludedInterfaceSuspend {
63
63
interface MyExcludedInterface {
64
64
val field: String?
65
65
}
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 {
51
51
interface MyExcludedInterface {
52
52
field : String
53
53
}
54
+
55
+ type MyIncludedResolverTypeWithNullDataFetchingEnvironment {
56
+ nullableField : String
57
+ nonNullableField : String !
58
+ }
You can’t perform that action at this time.
0 commit comments