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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#.project
.settings/
build/
.factorypath

# Intellij
.idea/
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ For GraphQL JPA Annotations use:
For GraphQL JPA Schema Builder use:

<dependency>
<groupId>com.github.introproventures.graphql-jpa-query</groupId>
<groupId>com.introproventures</groupId>
<artifactId>graphql-jpa-query-schema</artifactId>
<version>0.3.0</version>
</dependency>
Expand Down Expand Up @@ -215,7 +215,7 @@ Will Return:

Reverse Query
-------------
You can execute an inverse query to fitler results with a join in many-to-one association with some limitations. If you do this, be aware that only static parameter binding are supported in `where` criteria expressions.
You can execute an inverse query to fitler results with a join in many-to-one association in one query with parameter bindings support added in 0.3.1

For Example:

Expand Down
11 changes: 11 additions & 0 deletions graphql-jpa-query-annotations/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
Expand Down
83 changes: 44 additions & 39 deletions graphql-jpa-query-boot-starter/.classpath
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".apt_generated">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
11 changes: 11 additions & 0 deletions graphql-jpa-query-boot-starter/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
Expand Down
11 changes: 11 additions & 0 deletions graphql-jpa-query-example/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
Expand Down
11 changes: 11 additions & 0 deletions graphql-jpa-query-schema/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

import java.util.Collections;
import java.util.Map;

import javax.transaction.Transactional;
Expand Down Expand Up @@ -62,10 +63,21 @@ public ExecutionResult execute(String query) {
@Override
@Transactional(TxType.SUPPORTS)
public ExecutionResult execute(String query, Map<String, Object> arguments) {

// Need to inject variables in context to support parameter bindings in reverse queries
Map<String, Object> context = Collections.singletonMap("variables", arguments);

// ExecutionInput executionInput = ExecutionInput.newExecutionInput()
// .query(query)
// .variables(arguments)
// .root(context)
// .context(context)
// .build();

if (arguments == null)
return graphQL.execute(query);
else
return graphQL.execute(query, (Object) null, arguments);
return graphQL.execute(query, context, arguments);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ protected Predicate getPredicate(CriteriaBuilder cb, Root<?> from, From<?,?> pat

From<?,?> join = getCompoundJoin(path, argument.getName(), false);
Argument where = new Argument("where", argument.getValue());
Map<String, Object> variables = Optional.ofNullable(environment.getContext())
.filter(it -> it instanceof Map)
.map(it -> (Map<String, Object>) it)
.map(it -> (Map<String, Object>) it.get("variables"))
.orElse(Collections.emptyMap());

GraphQLFieldDefinition fieldDef = getFieldDef(
environment.getGraphQLSchema(),
Expand All @@ -290,7 +295,7 @@ protected Predicate getPredicate(CriteriaBuilder cb, Root<?> from, From<?,?> pat
);

Map<String, Object> arguments = (Map<String, Object>) new ValuesResolver()
.getArgumentValues(fieldDef.getArguments(), Collections.singletonList(where), Collections.emptyMap())
.getArgumentValues(fieldDef.getArguments(), Collections.singletonList(where), variables)
.get("where");

return getWherePredicate(cb, from, join, new WherePredicateEnvironment(environment, arguments), where);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class JavaScalarsTest {
@Test
public void long2LocalDateTime() {
//given
Coercing coercing = JavaScalars.of(LocalDateTime.class).getCoercing();
Coercing<?,?> coercing = JavaScalars.of(LocalDateTime.class).getCoercing();

LocalDateTime localDateTime = LocalDateTime.of(2017, 02, 02, 12, 30, 15);
long input = localDateTime.toEpochSecond(ZoneId.systemDefault().getRules().getOffset(localDateTime));
Expand All @@ -58,7 +58,7 @@ public void long2LocalDateTime() {
@Test
public void string2LocalDateTime() {
//given
Coercing coercing = JavaScalars.of(LocalDateTime.class).getCoercing();
Coercing<?,?> coercing = JavaScalars.of(LocalDateTime.class).getCoercing();
final String input = "2017-02-02T12:30:15";

//when
Expand All @@ -79,7 +79,7 @@ public void string2LocalDateTime() {

public void long2LocalDate() {
// given
Coercing coercing = JavaScalars.of(LocalDate.class).getCoercing();
Coercing<?,?> coercing = JavaScalars.of(LocalDate.class).getCoercing();
LocalDateTime localDateTime = LocalDateTime.of(2017, 02, 02, 0, 0, 0);
long input = localDateTime.toEpochSecond(ZoneId.systemDefault().getRules().getOffset(localDateTime));

Expand All @@ -98,7 +98,7 @@ public void long2LocalDate() {

public void string2LocalDate() {
//given
Coercing coercing = JavaScalars.of(LocalDate.class).getCoercing();
Coercing<?,?> coercing = JavaScalars.of(LocalDate.class).getCoercing();
final String input = "2017-02-02";

//when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ public void queryManyToOneJoinById() {
assertThat(result.toString()).isEqualTo(expected);
}

@SuppressWarnings("serial")
@Test
public void queryManyToOneJoinByIdWithVariables() {
//given:
String query = "query($id: String!) { Humans { select { name, homePlanet, favoriteDroid(where: {id: {EQ: $id}}) { name} } } }";
Map<String, Object> variables = new HashMap<String, Object>() {{
put("id", "2001");
}};

String expected = "{Humans={select=[{name=Darth Vader, homePlanet=Tatooine, favoriteDroid={name=R2-D2}}]}}";

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

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

@Test
public void queryOneToManyJoinByID() {
//given:
Expand Down