Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql with exposed transaction issue #1135

Closed
klabast opened this issue Jan 13, 2021 · 1 comment
Closed

graphql with exposed transaction issue #1135

klabast opened this issue Jan 13, 2021 · 1 comment

Comments

@klabast
Copy link

klabast commented Jan 13, 2021

I am trying to build a Spring Boot, GraphQL, Exposed app.

Those are my two test(!) Entities:

object AuctionHouseTable : UUIDTable("auction_house") {
    val name = text("name").uniqueIndex()
    val description = text("description").nullable()
    val url = text("url").nullable().uniqueIndex()
}

class AuctionHouse(id: EntityID<UUID>): UUIDEntity(id) {
    companion object: UUIDEntityClass<AuctionHouse>(AuctionHouseTable)

    var name by AuctionHouseTable.name
    var description by AuctionHouseTable.description
    var url by AuctionHouseTable.url
}

object AuctionHouseLocationTable: UUIDTable("auction_house_location") {
    val auctionHouse = reference("fk_auction_house", AuctionHouseTable)
    val locationDetail = text("location_detail").nullable()
}

class AuctionHouseLocation(id: EntityID<UUID>): UUIDEntity(id) {
    companion object: UUIDEntityClass<AuctionHouseLocation>(AuctionHouseLocationTable)

    var auctionHouse by AuctionHouse referencedOn AuctionHouseLocationTable.auctionHouse
    var locationDetail by AuctionHouseLocationTable.locationDetail
}

Also I am using spring-transactions and HikariCP. Querying a single entity works, no need for transaction { }.

When trying to query

query {
  getAuctionHouseLocations {
    id
    locationDetail
    auctionHouse {
      name
    }
  }
}

I am getting java.lang.IllegalStateException: No transaction in context.. I guess, this has something to do with GraphQL not being able to initiate lazy loading.

When I change

fun findAll(): List<AuctionHouseLocation> {
        return AuctionHouseLocation.all().toList()
    }

to

fun findAll(): List<AuctionHouseLocation> {
        val list = AuctionHouseLocation.all().toList()
        for (auctionHouseLocation in list) {
            println("Auction House name ${auctionHouseLocation.auctionHouse.name}")
        }
        return list
    }

in my repository, Exposed correctly prints the name and executes the additional sql statement, but this is not the same context GraphQL tries to use, I guess.

Has anyone been able to use GraphQL with Exposed+Spring Boot (and DAO, not DSL)?

@Tapac
Copy link
Contributor

Tapac commented Jan 22, 2021

Look similar to #1130 , fixed in master, and will be released soon.

@Tapac Tapac closed this as completed Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants