Skip to content

Join Fetch applied twice for ElementCollection #198

Closed
@vokinpirks

Description

@vokinpirks

Hi!
I'm playing around with this library and encountered an issue.
I have pretty simple JPA model. There is element collection defined as follows:

@ElementCollection(fetch = FetchType.LAZY)
@GraphQLDescription("A set of user-defined tags")
@BatchSize(size = 16)
private Set<String> tags = new HashSet<>();

When I do NOT include this field in query everything works fine:

query {
  Tracks() {
    select {
      addedAt
      playCount
    }
  }
}

But when I do so, I get an empty result:

query {
  Tracks() {
    select {
      addedAt
      playCount
      tags
    }
  }
}

'tags' field is empty for all entities.
I checked generated JPQL/SQL queries and found out that there are two joins for tags, left and inner one. I guess I'm getting the empty result because of that inner join.
I started debugging and figured out that the second join is added at
com.introproventures.graphql.jpa.query.schema.impl.QraphQLJpaBaseDataFetcher.java:234
(root.fetches becomes [2] there).

And..join is a very inefficient way of fetching *ToMany/ElemectCollection relations. Batch fetching is a way better for that. Theoretically, is it possible to implement batch fetching in this library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions