Skip to content

merge master #5

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 11 commits into from
Apr 21, 2019
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log

## 0.3.18-SNAPSHOT
## 0.3.20-SNAPSHOT
* feat: support enum variable bindings in queries (#109) [5dd999a](https://github.com/introproventures/graphql-jpa-query/commit/5dd999a1107899ce6bfe08aceb37ed2fb057aac6)
* Update README to add PWD shortcut in the title [8e9d409](https://github.com/introproventures/graphql-jpa-query/commit/8e9d409b4a193dde823991a9945d29f0163234a8)
* #102 fix NullPointerException when searching for Transient annotation (#106) [fb45d23](https://github.com/introproventures/graphql-jpa-query/commit/fb45d2329d8d02abc687e3db3cb2faafa4d91659)
* chore: enable Docker build by default [ec3f1a6](https://github.com/introproventures/graphql-jpa-query/commit/ec3f1a6c5daa3390fd738e2d2cef4f7a58b24e2d)
* fix: use bean naming convention for property names [6df3c30](https://github.com/introproventures/graphql-jpa-query/commit/6df3c30d1a16681da07d81d7ca64fed9d885ac57)
* distinct sql and ignore field in filters and sorting (#95) [bde04d5](https://github.com/introproventures/graphql-jpa-query/commit/bde04d5702943cd7d5e70d071e8a49df4ef8ad9f)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
GraphQL Query Api for JPA Entity Models
GraphQL Query Api for JPA Entity Models [![Try in PWD](https://cdn.rawgit.com/play-with-docker/stacks/cff22438/assets/images/button.png)](http://play-with-docker.com/?stack=https://raw.githubusercontent.com/introproventures/graphql-jpa-query/master/graphql-jpa-query-example/docker-compose.yml&stack_name=graphhql)
===============

[![Build Status](https://travis-ci.org/introproventures/graphql-jpa-query.svg?branch=master)](https://travis-ci.org/introproventures/graphql-jpa-query)
[![codecov](https://codecov.io/gh/introproventures/graphql-jpa-query/branch/master/graph/badge.svg)](https://codecov.io/gh/introproventures/graphql-jpa-query)
[![Maven Central](https://img.shields.io/maven-central/v/com.introproventures/graphql-jpa-query.svg)](https://mvnrepository.com/artifact/com.introproventures/graphql-jpa-query)
[![Jitpack.io](https://jitpack.io/v/introproventures/graphql-jpa-query.svg)](https://jitpack.io/#introproventures/graphql-jpa-query)
[![Jitpack.io](https://jitpack.io/v/introproventures/graphql-jpa-query.svg)](https://jitpack.io/#introproventures/graphql-jpa-query)

GraphQL is a query language for Web APIs implemented by GraphQL Java [graphql-java 11.0](https://github.com/andimarek/graphql-java) runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-dependencies</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-dependencies</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>
<artifactId>graphql-jpa-query-autoconfigure</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-dependencies</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-dependencies</relativePath>
</parent>
<artifactId>graphql-jpa-query-build</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>graphql-jpa-query-dependencies</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-example-merge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion graphql-jpa-query-schema/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
.isAnnotationPresent(annotation);

} catch (NoSuchFieldException e) {
if(delegate.getReadMethod() == null) return false;
answer = delegate.getReadMethod()
.isAnnotationPresent(annotation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,27 @@ protected Object convertValue(DataFetchingEnvironment environment, Argument argu
return ((StringValue) value).getValue();
}
}
else if (value instanceof VariableReference)
// Get resolved variable in environment arguments
return environment.getArguments().get(argument.getName());
else if (value instanceof ArrayValue) {
else if (value instanceof VariableReference) {
Class javaType = getJavaType(environment, argument);
Object argumentValue = environment.getArguments().get(argument.getName());
if(javaType.isEnum()) {
if(argumentValue instanceof Collection) {
List<Enum> values = new ArrayList<>();

Collection.class.cast(argumentValue)
.forEach(it -> values.add(Enum.valueOf(javaType, it.toString())));
return values;
} else {
return Enum.valueOf(javaType, argumentValue.toString());
}
}
else {
// Get resolved variable in environment arguments
return argumentValue;
}
} else if (value instanceof ArrayValue) {
Object convertedValue = environment.getArgument(argument.getName());
if (convertedValue != null) {
if (convertedValue != null && !getJavaType(environment, argument).isEnum()) {
// unwrap [[EnumValue{name='value'}]]
if(convertedValue instanceof Collection
&& ((Collection) convertedValue).stream().allMatch(it->it instanceof Collection)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.introproventures.graphql.jpa.query.schema;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;

import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;


@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
@TestPropertySource({"classpath:hibernate.properties"})
public class GraphQLEnumVariableBindingsTests {

@SpringBootApplication
static class Application {
@Bean
public GraphQLExecutor graphQLExecutor(final GraphQLSchemaBuilder graphQLSchemaBuilder) {
return new GraphQLJpaExecutor(graphQLSchemaBuilder.build());
}

@Bean
public GraphQLSchemaBuilder graphQLSchemaBuilder(final EntityManager entityManager) {

return new GraphQLJpaSchemaBuilder(entityManager)
.name("GraphQLBooks")
.description("Books JPA test schema");
}

}

@Autowired
private GraphQLExecutor executor;


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

Map<String, Object> variables = new HashMap<String, Object>() {{
put("genre", "NOVEL");
}};


String expected = "{Books={select=["
+ "{id=2, title=War and Peace, genre=NOVEL}, "
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
+ "]}}";

//when
Object result = executor.execute(query, variables).getData();

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

@Test
public void queryEnumSimpleArrayVariableBinding() {
//given
String query = "query($genre: Genre) {" +
" Books(where: {" +
" genre: {IN: [$genre]}" +
" }) {" +
" select {" +
" id" +
" title" +
" genre" +
" }" +
" }" +
"}";

Map<String, Object> variables = new HashMap<String, Object>() {{
put("genre", "NOVEL");
}};


String expected = "{Books={select=["
+ "{id=2, title=War and Peace, genre=NOVEL}, "
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
+ "]}}";

//when
Object result = executor.execute(query, variables).getData();

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

@Test
public void queryEnumArrayVariableBindingInNestedRelation() {
//given
String query = "query($genres: [Genre!]) {" +
" Authors(where: {" +
" books: {" +
" genre: {IN: $genres}" +
" }" +
" }) {" +
" select {" +
" id" +
" name" +
" books {" +
" id" +
" title" +
" genre" +
" }" +
" }" +
" }" +
"}";

Map<String, Object> variables = new HashMap<String, Object>() {{
put("genres", Arrays.asList("NOVEL"));
}};


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

//when
Object result = executor.execute(query, variables).getData();

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

@Test
public void queryEnumArrayVariableBindingInEmbeddedRelation() {
//given
String query = "query($genres: [Genre!]) {" +
" Authors {" +
" select {" +
" id" +
" name" +
" books(where: {" +
" genre: {IN: $genres}" +
" }) {" +
" id" +
" title" +
" genre" +
" }" +
" }" +
" } " +
"}";

Map<String, Object> variables = new HashMap<String, Object>() {{
put("genres", Arrays.asList("NOVEL"));
}};


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

//when
Object result = executor.execute(query, variables).getData();

// then
assertThat(result.toString()).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,14 @@ public void correctlyDerivesSchemaDescriptionsFromGivenEntities() {
.describedAs( "Ensure that CodeList.parent has the expected description")
.isEqualTo("The CodeList's parent CodeList");
}

@Test
public void testBuildSchema(){
//given
GraphQLSchema schema = builder.build();

//then
assertThat(schema).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public void testNotTransientFields() throws Exception {
assertThat(IntrospectionUtils.isTransient(entity, "info")).isFalse();
assertThat(IntrospectionUtils.isTransient(entity, "title")).isFalse();
}



@Test
public void testByPassSetMethod() throws Exception {
// given
Class<CalculatedEntity> entity = CalculatedEntity.class;

// then
assertThat(IntrospectionUtils.isTransient(entity,"something")).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ public boolean isCustomLogic() {
public String getHideFieldFunction() {
return "getHideFieldFunction";
}

public void setSomething(int a){}
}
2 changes: 1 addition & 1 deletion graphql-jpa-query-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-build</artifactId>
<version>0.3.18-SNAPSHOT</version>
<version>0.3.20-SNAPSHOT</version>
<relativePath>../graphql-jpa-query-build</relativePath>
</parent>
<artifactId>graphql-jpa-query-web</artifactId>
Expand Down
Loading