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 @@ -23,7 +23,6 @@
import javax.transaction.Transactional.TxType;

import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor;

import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
Expand Down Expand Up @@ -55,7 +54,7 @@ public GraphQLJpaExecutor(GraphQLSchema graphQLSchema) {
@Override
@Transactional(TxType.SUPPORTS)
public ExecutionResult execute(String query) {
return graphQL.execute(query);
return execute(query, Collections.emptyMap());
}

/* (non-Javadoc)
Expand All @@ -65,20 +64,12 @@ public ExecutionResult execute(String query) {
@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(executionInput);
return graphQL.execute(executionInput);
}

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

From<?,?> join = getCompoundJoin(path, argument.getName(), true);
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());
Map<String, Object> variables = environment.getExecutionContext().getVariables();

GraphQLFieldDefinition fieldDef = getFieldDef(
environment.getGraphQLSchema(),
this.getObjectType(environment, argument),
this.getObjectType(environment),
new Field(fieldName)
);

Expand Down Expand Up @@ -420,7 +416,7 @@ private Predicate getFieldPredicate(String fieldName, CriteriaBuilder cb, From<?
.anyMatch(it -> !Logical.names().contains(it.getName()) && !Criteria.names().contains(it.getName())))
{
GraphQLFieldDefinition fieldDefinition = getFieldDef(environment.getGraphQLSchema(),
this.getObjectType(environment, argument),
this.getObjectType(environment),
new Field(fieldName));
Map<String, Object> arguments = new LinkedHashMap<>();
boolean isOptional = false;
Expand Down Expand Up @@ -580,7 +576,9 @@ protected Object convertValue(DataFetchingEnvironment environment, Argument argu
}
else if (value instanceof VariableReference) {
Class javaType = getJavaType(environment, argument);
Object argumentValue = environment.getArguments().get(argument.getName());
Object argumentValue = environment.getExecutionContext()
.getVariables()
.get(VariableReference.class.cast(value).getName());
if(javaType.isEnum()) {
if(argumentValue instanceof Collection) {
List<Enum> values = new ArrayList<>();
Expand Down Expand Up @@ -660,7 +658,7 @@ protected Class<?> getJavaType(DataFetchingEnvironment environment, Argument arg
* @return JPA model attribute
*/
private Attribute<?,?> getAttribute(DataFetchingEnvironment environment, Argument argument) {
GraphQLObjectType objectType = getObjectType(environment, argument);
GraphQLObjectType objectType = getObjectType(environment);
EntityType<?> entityType = getEntityType(objectType);

return entityType.getAttribute(argument.getName());
Expand Down Expand Up @@ -697,7 +695,7 @@ private EntityType<?> getEntityType(GraphQLObjectType objectType) {
* @param argument
* @return resolved GraphQL object type or null if no output type is provided
*/
private GraphQLObjectType getObjectType(DataFetchingEnvironment environment, Argument argument) {
private GraphQLObjectType getObjectType(DataFetchingEnvironment environment) {
GraphQLType outputType = environment.getFieldType();

if (outputType instanceof GraphQLList)
Expand Down