diff --git a/website/versioned_docs/version-6.x.x/schema-generator/execution/fetching-data.md b/website/versioned_docs/version-6.x.x/schema-generator/execution/fetching-data.md index a3ac043328..c9f019fd08 100644 --- a/website/versioned_docs/version-6.x.x/schema-generator/execution/fetching-data.md +++ b/website/versioned_docs/version-6.x.x/schema-generator/execution/fetching-data.md @@ -55,3 +55,19 @@ You can provide your own custom data fetchers to resolve functions and propertie to your [SchemaGeneratorConfig](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/SchemaGeneratorConfig.kt). See our [spring example app](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples/server/spring-server) for an example of `CustomDataFetcherFactoryProvider`. + +:::info + +Currently, graphql-kotlin, through the [KotlinDataFetcherFactoryProvider](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/execution/KotlinDataFetcherFactoryProvider.kt#L62) +creates a [PropertyDataFetcher](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/execution/PropertyDataFetcher.kt) +per source's property. This instance is created [every single time](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/schema/GraphQLCodeRegistry.java#L100) +the graphql-java [DataFetcherFactory](https://github.com/graphql-java/graphql-java/blob/master/src/main/java/graphql/schema/DataFetcherFactory.java) is invoked, +which happens to be on runtime per property per GraphQL operation. + +If you want to avoid that, use or extend the [SimpleSingletonKotlinDataFetcherFactoryProvider](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/execution/KotlinDataFetcherFactoryProvider.kt#L72) which will provide a +[SingletonPropertyDataFetcher](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/execution/SingletonPropertyDataFetcher.kt) that will host its own singleton factory, and it will store +all `KProperty.Getter<*>`s in a `ConcurrentHashMap`. + +This is inspired by this [graphql-java's PR](https://github.com/graphql-java/graphql-java/pull/3754) + +:::