Skip to content

Why DataFetchers that use Dataloaders for lateinit variables should have prototype beans and not singletons? #983

Answered by dariuszkuc
RIP21 asked this question in Q&A
Discussion options

You must be logged in to vote

Great questions!

As Shane mentioned, when building out GraphQL schema graphql-kotlin will automatically create FunctionDataFetcher for functions/methods and default to PropertyDataFetcher for getter fields. This mapping is stored in graphql-java CodeRegistry that is then referenced when resolving fields. By marking a field as lateinit it allows you to bypass the above default behavior and inject a custom data fetcher (i.e. your LastUpdatedDataFetcher) that abstracts away of how you resolve that field. If you create separate custom data fetcher (LastUpdatedDataFetcher) it allows you to reuse it in multiple places. In the example above there is no point in making the custom data fetcher bea…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@RIP21
Comment options

@smyrick
Comment options

@RIP21
Comment options

Comment options

You must be logged in to vote
1 reply
@RIP21
Comment options

Answer selected by RIP21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants