Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ public Object get(DataFetchingEnvironment environment) {

queryField = new Field(fieldName, field.getArguments(), recordsSelection.get().getSelectionSet());

// Let's clear session persistent context to avoid getting stale objects cached in the same session
// between requests with different search criteria. This looks like a Hibernate bug...
entityManager.clear();

TypedQuery<?> query = getQuery(queryEnvironment, queryField, isDistinct);

// Let's apply page only if present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.assertj.core.util.Lists.list;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1471,6 +1472,100 @@ public void queryWithEQMatchingCase() {

//then:
assertThat(result.toString()).isEqualTo(expected);
}
}

@Test
public void shouldNotReturnStaleCacheResultsFromPreviousQueryForCollectionCriteriaExpression() {
//given:
String query = "query ($genre: Genre) {" +
" Authors(where: { " +
" books: {" +
" genre: {EQ: $genre}" +
" }" +
" }) {" +
" select {" +
" id" +
" name" +
" books {" +
" id" +
" title" +
" genre" +
" }" +
" }" +
" }" +
"}";

//when: 1st query
Object result1 = executor.execute(query, Collections.singletonMap("genre", "PLAY")).getData();

String expected1 = "{Authors={select=["
+ "{id=4, name=Anton Chekhov, books=["
+ "{id=5, title=The Cherry Orchard, genre=PLAY}, "
+ "{id=6, title=The Seagull, genre=PLAY}, "
+ "{id=7, title=Three Sisters, genre=PLAY}"
+ "]}"
+ "]}}";

//then:
assertThat(result1.toString()).isEqualTo(expected1);

//when: 2nd query
Object result2 = executor.execute(query, Collections.singletonMap("genre", "NOVEL")).getData();

String expected2 = "{Authors={select=["
+ "{id=1, name=Leo Tolstoy, books=["
+ "{id=2, title=War and Peace, genre=NOVEL}, "
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
+ "]}"
+ "]}}";

//then:
assertThat(result2.toString()).isEqualTo(expected2);
}

@Test
public void shouldNotReturnStaleCacheResultsFromPreviousQueryForEmbeddedCriteriaExpression() {
//given:
String query = "query ($genre: Genre) {" +
" Authors {" +
" select {" +
" id" +
" name" +
" books(where:{ genre: {EQ: $genre} }) {" +
" id" +
" title" +
" genre" +
" }" +
" }" +
" }" +
"}";

//when: 1st query
Object result1 = executor.execute(query, Collections.singletonMap("genre", "PLAY")).getData();

String expected1 = "{Authors={select=["
+ "{id=4, name=Anton Chekhov, books=["
+ "{id=5, title=The Cherry Orchard, genre=PLAY}, "
+ "{id=6, title=The Seagull, genre=PLAY}, "
+ "{id=7, title=Three Sisters, genre=PLAY}"
+ "]}"
+ "]}}";

//then:
assertThat(result1.toString()).isEqualTo(expected1);

//when: 2nd query
Object result2 = executor.execute(query, Collections.singletonMap("genre", "NOVEL")).getData();

String expected2 = "{Authors={select=["
+ "{id=1, name=Leo Tolstoy, books=["
+ "{id=2, title=War and Peace, genre=NOVEL}, "
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
+ "]}"
+ "]}}";

//then:
assertThat(result2.toString()).isEqualTo(expected2);
}

}