Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* [
* {
Expand All @@ -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
Expand All @@ -136,6 +141,7 @@ export const configSchema = object({
classMethods: optional(
union([literal("SUSPEND"), literal("COMPLETABLE_FUTURE")]),
),
nullableDataFetchingEnvironment: optional(boolean()),
}),
),
),
Expand Down
3 changes: 1 addition & 2 deletions src/definitions/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
const dataFetchingEnvironmentArgument = `dataFetchingEnvironment: graphql.schema.DataFetchingEnvironment${typeInResolverInterfacesConfig?.nullableDataFetchingEnvironment ? "? = null" : ""}`;
const extraFieldArguments = [dataFetchingEnvironmentArgument];
const allFieldArguments = existingFieldArguments?.concat(extraFieldArguments);
return allFieldArguments?.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ export default {
typeName: "MyIncludedInterfaceSuspend",
classMethods: "SUSPEND",
},
{
typeName: "MyIncludedResolverTypeWithNullDataFetchingEnvironment",
nullableDataFetchingEnvironment: true,
},
],
} satisfies GraphQLKotlinCodegenConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ interface MyIncludedInterfaceSuspend {
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.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ interface MyIncludedInterfaceSuspend {
interface MyExcludedInterface {
field: String
}

type MyIncludedResolverTypeWithNullDataFetchingEnvironment {
nullableField: String
nonNullableField: String!
}