Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Conversation

BlasiusSecundus
Copy link

Using the transactional query invoker prevents LazyInitializationException occurring when working with JPA entities across multiple resolvers (thus making individual resolvers Transactional is not sufficient).

By default, this feature is disabled. It can be enabled in application.properties/yaml with:

graphql.query-invoker.transactional=true

@@ -23,6 +23,8 @@ dependencies {

compile "org.springframework.boot:spring-boot-autoconfigure:$LIB_SPRING_BOOT_VER"
compile "org.springframework.boot:spring-boot-starter-websocket:$LIB_SPRING_BOOT_VER"
compile "javax.transaction:javax.transaction-api:$LIB_TRANSACTIONS_API_VERSION"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be included as compileOnly instead so we're not pulling in more dependencies? People that want to use this will probably have these dependencies themselves anyway already, won't they?

Copy link
Author

@BlasiusSecundus BlasiusSecundus Nov 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, made them compileOnly. transaction-api is also included as testCompile, as it is currently used in one of the tests.

This may prevent LazyInitializationException when working with JPA
entities across multiple resolvers (thus making individual resolvers
Transactional is not sufficient).

By default, this feature is disabled. It can be enabled in
application.properties/yaml with:

graphql.query-invoker.transactional=true
@BlasiusSecundus BlasiusSecundus force-pushed the feature/transactional-query-invoker branch from 01ba914 to fc611f8 Compare November 16, 2019 15:31
@oliemansm oliemansm merged commit 32db152 into graphql-java-kickstart:master Nov 19, 2019
@oliemansm oliemansm added this to the 6.0.0 milestone Nov 19, 2019
@oliemansm
Copy link
Member

@BlasiusSecundus
I've decided to revert this merge because this library already provides a mechanism to add this kind of extension by simply providing your own GraphQLQueryInvoker bean. I want to try to make sure there's enough options in this library that you can override to fit your own needs, but not to include all those separate needs in this library directly.

@oliemansm oliemansm removed this from the 6.0.0 milestone Nov 29, 2019
@vinterdo
Copy link

@oliemansm could you provide an example? Also, graphql.query-invoker.transactional=true is described in readme, while not merged/released, causing my confusion why it is not working :)

@oliemansm
Copy link
Member

Updated the readme, thanks for pointing it out.

If the default settings are good for you, and you only want to use a customGraphQLQueryInvoker bean, then just add something like this in your app configuration:

@Bean
public GraphQLQueryInvoker queryInvoker(ExecutionStrategyProvider executionStrategyProvider) {
  GraphQLQueryInvoker.Builder builder = GraphQLQueryInvoker.newBuilder()
        .withExecutionStrategyProvider(executionStrategyProvider);
  return new MyCustomQueryInvoker(builder.build());
}

@BlasiusSecundus
Copy link
Author

@oliemansm, thanks for the update and the explanation.

I want to try to make sure there's enough options in this library that you can override to fit your own needs, but not to include all those separate needs in this library directly.

That makes a good point. (The PR originated from one such a separate need/solution for that need)

@BlasiusSecundus BlasiusSecundus deleted the feature/transactional-query-invoker branch September 26, 2020 04:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants