Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQ
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));

Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
DataFetchingEnvironment environment = new DataFetchingEnvironment(
DataFetchingEnvironment environment = new DefaultDataFetchingEnvironment(
source,
argumentValues,
executionContext.getRoot(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private List<GraphQLExecutionNodeValue> fetchData(ExecutionContext executionCont
for (GraphQLExecutionNodeDatum n : nodeData) {
sources.add(n.getSource());
}
DataFetchingEnvironment environment = new DataFetchingEnvironment(
DataFetchingEnvironment environment = new DefaultDataFetchingEnvironment(
sources,
argumentValues,
executionContext.getRoot(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package graphql.execution.batched;


import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;

import graphql.schema.DefaultDataFetchingEnvironment;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -28,7 +27,7 @@ public Object get(DataFetchingEnvironment environment) {
List<Object> sources = (List<Object>) environment.getSource();
List<Object> results = new ArrayList<Object>();
for (Object source : sources) {
DataFetchingEnvironment singleEnv = new DataFetchingEnvironment(
DataFetchingEnvironment singleEnv = new DefaultDataFetchingEnvironment(
source,
environment.getArguments(),
environment.getContext(),
Expand Down
77 changes: 22 additions & 55 deletions src/main/java/graphql/schema/DataFetchingEnvironment.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,30 @@
package graphql.schema;


import graphql.language.Field;

import java.util.List;
import java.util.Map;

public class DataFetchingEnvironment {
private final Object source;
private final Map<String, Object> arguments;
private final Object context;
private final List<Field> fields;
private final GraphQLOutputType fieldType;
private final GraphQLType parentType;
private final GraphQLSchema graphQLSchema;

public DataFetchingEnvironment(Object source, Map<String, Object> arguments, Object context, List<Field> fields, GraphQLOutputType fieldType, GraphQLType parentType, GraphQLSchema graphQLSchema) {
this.source = source;
this.arguments = arguments;
this.context = context;
this.fields = fields;
this.fieldType = fieldType;
this.parentType = parentType;
this.graphQLSchema = graphQLSchema;
}

public Object getSource() {
return source;
}

public Map<String, Object> getArguments() {
return arguments;
}

public boolean containsArgument(String name) {
return arguments.containsKey(name);
}

public <T> T getArgument(String name) {
return (T) arguments.get(name);
}

public Object getContext() {
return context;
}

public List<Field> getFields() {
return fields;
}

public GraphQLOutputType getFieldType() {
return fieldType;
}

public GraphQLType getParentType() {
return parentType;
}

public GraphQLSchema getGraphQLSchema() {
return graphQLSchema;
}
/**
* environment for {@link DataFetcher data fetcher}.
*/
public interface DataFetchingEnvironment {

Object getSource();

Map<String, Object> getArguments();

boolean containsArgument(String name);

<T> T getArgument(String name);

Object getContext();

List<Field> getFields();

GraphQLOutputType getFieldType();

GraphQLType getParentType();

GraphQLSchema getGraphQLSchema();
}
73 changes: 73 additions & 0 deletions src/main/java/graphql/schema/DefaultDataFetchingEnvironment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package graphql.schema;


import graphql.language.Field;

import java.util.List;
import java.util.Map;

public class DefaultDataFetchingEnvironment implements DataFetchingEnvironment {

private final Object source;
private final Map<String, Object> arguments;
private final Object context;
private final List<Field> fields;
private final GraphQLOutputType fieldType;
private final GraphQLType parentType;
private final GraphQLSchema graphQLSchema;

public DefaultDataFetchingEnvironment(Object source, Map<String, Object> arguments, Object context, List<Field> fields, GraphQLOutputType fieldType, GraphQLType parentType, GraphQLSchema graphQLSchema) {
this.source = source;
this.arguments = arguments;
this.context = context;
this.fields = fields;
this.fieldType = fieldType;
this.parentType = parentType;
this.graphQLSchema = graphQLSchema;
}

@Override
public Object getSource() {
return source;
}

@Override
public Map<String, Object> getArguments() {
return arguments;
}

@Override
public boolean containsArgument(String name) {
return arguments.containsKey(name);
}

@Override
public <T> T getArgument(String name) {
return (T) arguments.get(name);
}

@Override
public Object getContext() {
return context;
}

@Override
public List<Field> getFields() {
return fields;
}

@Override
public GraphQLOutputType getFieldType() {
return fieldType;
}

@Override
public GraphQLType getParentType() {
return parentType;
}

@Override
public GraphQLSchema getGraphQLSchema() {
return graphQLSchema;
}
}
11 changes: 6 additions & 5 deletions src/test/groovy/graphql/DataFetcherTest.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql

import graphql.schema.DataFetchingEnvironment
import graphql.schema.DefaultDataFetchingEnvironment
import graphql.schema.FieldDataFetcher
import graphql.schema.PropertyDataFetcher
import spock.lang.Specification
Expand Down Expand Up @@ -53,7 +54,7 @@ class DataFetcherTest extends Specification {

def "get field value"() {
given:
def environment = new DataFetchingEnvironment(dataHolder, null, null, null, GraphQLString, null, null)
def environment = new DefaultDataFetchingEnvironment(dataHolder, null, null, null, GraphQLString, null, null)
when:
def result = new FieldDataFetcher("publicField").get(environment)
then:
Expand All @@ -62,7 +63,7 @@ class DataFetcherTest extends Specification {

def "get property value"() {
given:
def environment = new DataFetchingEnvironment(dataHolder, null, null, null, GraphQLString, null, null)
def environment = new DefaultDataFetchingEnvironment(dataHolder, null, null, null, GraphQLString, null, null)
when:
def result = new PropertyDataFetcher("property").get(environment)
then:
Expand All @@ -71,7 +72,7 @@ class DataFetcherTest extends Specification {

def "get Boolean property value"() {
given:
def environment = new DataFetchingEnvironment(dataHolder, null, null, null, GraphQLBoolean, null, null)
def environment = new DefaultDataFetchingEnvironment(dataHolder, null, null, null, GraphQLBoolean, null, null)
when:
def result = new PropertyDataFetcher("booleanField").get(environment)
then:
Expand All @@ -80,7 +81,7 @@ class DataFetcherTest extends Specification {

def "get Boolean property value with get"() {
given:
def environment = new DataFetchingEnvironment(dataHolder, null, null, null, GraphQLBoolean, null, null)
def environment = new DefaultDataFetchingEnvironment(dataHolder, null, null, null, GraphQLBoolean, null, null)
when:
def result = new PropertyDataFetcher("booleanFieldWithGet").get(environment)
then:
Expand All @@ -89,7 +90,7 @@ class DataFetcherTest extends Specification {

def "get field value as property"() {
given:
def environment = new DataFetchingEnvironment(dataHolder, null, null, null, GraphQLString, null, null)
def environment = new DefaultDataFetchingEnvironment(dataHolder, null, null, null, GraphQLString, null, null)
when:
def result = new PropertyDataFetcher("publicField").get(environment)
then:
Expand Down