Skip to content

fix(GH-198): adedd support for fetching optional element collections elements #200

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

Merged
merged 3 commits into from
Oct 5, 2019

Conversation

igdianov
Copy link
Collaborator

@igdianov igdianov commented Oct 5, 2019

This PR fixes fetching plural attributes annotated with @ElementCollection to use left outer join that makes collection elements optional should associated collection elements data set be empty, i.e. given

public class Author {
	@Id
	Long id;

	String name;

	@OneToMany(mappedBy="author", fetch=FetchType.LAZY)
	@OrderBy("id ASC")
	Set<Book> books;
	
	@ElementCollection(fetch=FetchType.LAZY) 
	@CollectionTable(name = "author_phone_numbers", joinColumns = @JoinColumn(name = "author_id")) 
	@Column(name = "phone_number")
	private Set<String> phoneNumbers = new HashSet<>();	
	
	@Enumerated(EnumType.STRING)
	Genre genre;	
}

When executing the following query with author containing empty phoneNumbers selection:

query {
  Author(id: 8) {
    id
    name
    phoneNumbers
    books {
      id
      title
      tags
    }
  }
}

The expected result should return the following Json:

{
  "data": {
    "Author": {
      "id": 8,
      "name": "Igor Dianov",
      "phoneNumbers": [],
      "books": []
    },
  }
}

It is also possible to use where criteria expressions to fetch the selection that satisfies search criteria with values in the element collection, i.e. given query,

query {
  Books(where: {tags: {EQ: "war"}}) {
    select {
      id
      title
      tags
    }
  }
}

The expected result should be

{
  "data": {
    "Books": {
      "select": [
        {
          "id": 2,
          "title": "War and Peace",
          "tags": [
            "piece",
            "war"
          ]
        }
      ]
    }
  }
}

Also fixes #198

@igdianov igdianov self-assigned this Oct 5, 2019
@igdianov igdianov added the bug label Oct 5, 2019
@codecov
Copy link

codecov bot commented Oct 5, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@9854252). Click here to learn what that means.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #200   +/-   ##
=========================================
  Coverage          ?   73.67%           
  Complexity        ?      877           
=========================================
  Files             ?       50           
  Lines             ?     3708           
  Branches          ?      626           
=========================================
  Hits              ?     2732           
  Misses            ?      698           
  Partials          ?      278
Impacted Files Coverage Δ Complexity Δ
...ures/graphql/jpa/query/schema/model/book/Book.java 0% <0%> (ø) 0 <0> (?)
...a/query/schema/impl/QraphQLJpaBaseDataFetcher.java 75.82% <100%> (ø) 170 <0> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9854252...0315332. Read the comment docs.

@igdianov igdianov merged commit 5d99c3b into master Oct 5, 2019
@igdianov igdianov deleted the igdianov-fix-fetch-element-collection branch October 5, 2019 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Join Fetch applied twice for ElementCollection
1 participant